1. Java / Говнокод #24679

    −2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    public void pullToDirection(ForgeDirection dir) {
    		if (!canPullToDirection(dir))
    			return;
    		if (parentChunk.world.world.get().getBlockId(pipePosition.x + dir.offsetX, pipePosition.y + dir.offsetY,
    				pipePosition.z + dir.offsetZ) == AquaPipes.pipe.blockID) {
    			TransferPipeItem item = items.iterator().next();
    			if (item.isEmpty()) {
    				items.remove(item);
    				if (items.isEmpty()) {
    					parentChunk.pendingPipeStatesToRemove.add(this);
    					parentChunk.updateDataForAllObservers(this);
    				}
    				return;
    			}
    			items.remove(item);
    			if (items.isEmpty()) {
    				parentChunk.pendingPipeStatesToRemove.add(this);
    				parentChunk.updateDataForAllObservers(this);
    			}
    			parentChunk.world.pushToPipe(pipePosition.x + dir.offsetX, pipePosition.y + dir.offsetY,
    					pipePosition.z + dir.offsetZ, item.getStack());
    			return;
    		} else {
    			TileEntity te = parentChunk.world.world.get().getBlockTileEntity(pipePosition.x + dir.offsetX,
    					pipePosition.y + dir.offsetY, pipePosition.z + dir.offsetZ);
    			if (te != null) {
    				if (te instanceof ISidedInventory) {
    					TransferPipeItem item = items.iterator().next();
    					if (item.isEmpty()) {
    						items.remove(item);
    						if (items.isEmpty()) {
    							parentChunk.pendingPipeStatesToRemove.add(this);
    							parentChunk.updateDataForAllObservers(this);
    						}
    						return;
    					}
    					ISidedInventory inv = (ISidedInventory) te;
    					int[] slots = inv.getAccessibleSlotsFromSide(ForgeDirection.OPPOSITES[dir.ordinal()]);
    					for (int slot : slots) {
    						if (inv.canInsertItem(slot, item.getStack(), ForgeDirection.OPPOSITES[dir.ordinal()])
    								&& inv.isStackValidForSlot(slot, item.getStack())
    								&& (inv.getStackInSlot(slot) == null
    										|| (inv.getStackInSlot(slot).itemID == item.getStack().itemID
    												&& inv.getStackInSlot(slot).getItemDamage() == inv
    														.getStackInSlot(slot)
    														.getItemDamage()
    												&& inv.getStackInSlot(slot).stackSize < inv.getInventoryStackLimit()
    												&& inv.getStackInSlot(slot).stackSize < inv
    														.getStackInSlot(slot)
    														.getMaxStackSize()
    												&& ItemStack.areItemStackTagsEqual(inv.getStackInSlot(slot),
    														item.getStack())))) {
    							item.getStack().stackSize--;
    							inv.getStackInSlot(slot).stackSize++;
    							inv.onInventoryChanged();
    							if (item.isEmpty()) {
    								items.remove(item);
    								if (items.isEmpty()) {
    									parentChunk.pendingPipeStatesToRemove.add(this);
    									parentChunk.updateDataForAllObservers(this);
    								}
    							}
    						}
    					}
    				} else if (te instanceof IInventory) {
    					TransferPipeItem item = items.iterator().next();
    					if (item.isEmpty()) {
    						items.remove(item);
    						if (items.isEmpty()) {
    							parentChunk.pendingPipeStatesToRemove.add(this);
    							parentChunk.updateDataForAllObservers(this);
    						}
    						return;
    					}
    					IInventory inv = (IInventory) te;
    					for(int slot = 0; slot < inv.getSizeInventory(); slot++) {
    						if (inv.isStackValidForSlot(slot, item.getStack())
    								&& (inv.getStackInSlot(slot) == null
    										|| (inv.getStackInSlot(slot).itemID == item.getStack().itemID
    												&& inv.getStackInSlot(slot).getItemDamage() == inv
    														.getStackInSlot(slot)
    														.getItemDamage()
    												&& inv.getStackInSlot(slot).stackSize < inv.getInventoryStackLimit()
    												&& inv.getStackInSlot(slot).stackSize < inv
    														.getStackInSlot(slot)
    														.getMaxStackSize()
    												&& ItemStack.areItemStackTagsEqual(inv.getStackInSlot(slot),
    														item.getStack())))) {
    							item.getStack().stackSize--;
    							inv.getStackInSlot(slot).stackSize++;
    							inv.onInventoryChanged();
    							if (item.isEmpty()) {
    								items.remove(item);
    								if (items.isEmpty()) {
    									parentChunk.pendingPipeStatesToRemove.add(this);
    									parentChunk.updateDataForAllObservers(this);
    								}
    							}
    						}

    на закрывающие скобки не хватило места. код из моего еще не дописанного мода на майнкрафт.

    UsernameAK, 28 Августа 2018

    Комментарии (0)
  2. Python / Говнокод #24676

    −3

    1. 1
    Зачем нужен "z == int(str(z)[::-1])", если есть "int(str(z)[:len(str(z))//2]) == int(str(z)[int((len(str(z))+1)//2):][::-1])"?

    shite, 28 Августа 2018

    Комментарии (7)
  3. Lua / Говнокод #24660

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    return coroutine.create(function(x) 
        while true do
          socket.sleep(1);
          collectgarbage() 
          coroutine.yield() 
        end 
      end)

    Выделил сборщик мусора в отдельный поток, и чтоб он вечно собирал за мной всякую срань, но раз в секунду.
    Ожидание: Поток спит в течении 1 секунды.
    Реальность: Вся программа спит в течении 1 секунды.

    3oJIoTou_xyu, 26 Августа 2018

    Комментарии (41)
  4. Python / Говнокод #24658

    −4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    stack = []
    
    def stdout(x):
        if x == "puts":
            print(stack.pop())
        else:
            raise Exception("иди нахуй")
    
    def stdin(x):
        global stack
        if x == "gets":
            stack.append(input())
        else:
            raise Exception("иди нахуй")
    
    math = {
        "add": lambda: stack.append(float(stack.pop()) + float(stack.pop())),
        "sub": lambda: stack.append((-float(stack.pop())) + float(stack.pop())),
        "mul": lambda: stack.append(float(stack.pop()) * float(stack.pop())),
        "div": lambda: stack.append(1 / float(stack.pop()) * float(stack.pop())),
    }
    
    def stack_commands(x):
        global stack
        if x == "swap":
            stack[-1], stack[-2] = stack[-2:]
        elif x == "drop":
            stack.pop()
        elif x == "dup":
            stack.append(stack[-1])
        else:
            raise Exception("иди нахуй")
    
    string = {
        "concat": lambda: stack.append(str(stack.pop()) + str(stack.pop()))
    }
    
    commands = {
        "comment": lambda x: x,
        "push": lambda x: stack.append(x),
        "stdout": stdout,
        "stdin": stdin,
        "math": lambda x: print(math[x]()),
        "stack": stack_commands,
        "string": lambda x: string[x]()
    }
    
    def do(x):
        if '@' not in x:
            raise Exception(x + " is not email.")
        a, b = x.split('@')
        b = b.split('.')[0]
        commands[b](a)
    
    def eval(s):
        for i in s.lower().split():
            do(i)
    
    eval("""
    [email protected]
    
    [email protected] [email protected]
    [email protected]
    [email protected] [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected]
    [email protected] [email protected] [email protected]
    """)

    666_N33D135, 25 Августа 2018

    Комментарии (42)
  5. Си / Говнокод #24655

    −4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsaasyncselect
    int WSAAsyncSelect(
      SOCKET s,
      HWND   hWnd,
      u_int  wMsg,
      long   lEvent
    );
    
    /*
    
    hWnd
    
    A handle that identifies the window that will receive a message when a network event occurs.
    */

    Почему виндовые асинхронные (или правильно говорить "небликирующиеся") сокеты так черезжопно сделаны? Нафига им через HWND надо месседжи слать? Что, другого способа нет для оповещений?
    Требовать для работы асинхронных сокетов чтоб какое-то окно было это как требовать зубную щетку для входа в туалет чтоб посрать

    j123123, 24 Августа 2018

    Комментарии (16)
  6. Куча / Говнокод #24653

    −1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    #!/l_l5l2/8IN/l>Y7l-lON3
    
    IMl>Ol27 5Y5
    
    41l>l-l4 = {
            '4': '4',
            '8': '8',
            '(': '(',
            ')': ')',
            '3': '3',
            '#': '#',
            '9': '9',
            'l-l': '1-1',
            '1': '1',
            '_l': '_1',
            'l<': '1<',
            'l>': '1>',
            '&': '&',
            'l2': '12',
            '5': '5',
            '7': '7',
            'l_l': '1_1',
            '\/': '\/',
            '\/\/': '\/\/',
            '><': '><',
            'Y': 'Y',
            '2': '2'
    }
    
    I# 13N(5Y5.4l29\/) > 1:
        # = Ol>3N(5Y5.4l29\/[1])
    3153:
        # = 5Y5.57)IN
    
    8l_l##3l2 = []
    #Ol2 ( IN #.l234)().l_ll>l>3l2():
        8l_l##3l2.4l>l>3N)(41l>l-l4[(] I# ( IN 41l>l-l4 3153 ()
    
    l>l2IN7(''._lOIN(8l_l##3l2))

    vistefan, 24 Августа 2018

    Комментарии (73)
  7. C++ / Говнокод #24652

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    class TaxStorage {
    public:
      using TaxCode = Code<3>; // Code<int N, typename Storage = uint32_t> тип для маленьких строк
      using TaxType = Code<3>;
      using TaxId = std::tuple<TaxCode, TaxType>;
      using TaxMap = std::map<TaxId, int>
    
      using CityId = int;
      using TaxPointMap = std::unordered_map<CityId, TaxMap>;
    
      TaxMap forCityOrOther(const TaxPointMap& map, const CityId cityId) const {
        const auto found = map.find(cityId);
        return found == map.cend() ? map.at(OTHER_CITY) : *found; // должно быть found->second
      }
    }

    Dev: Ok GCC, tell me what is wrong.
    GCC: /home/whatever/project/TaxStorage.h:102: error: incompatible operand types ('const std::unordered_map<int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > > > >::mapped_type' (aka 'const std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >') and 'const std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > >')

    ДОКОЛЕ?!!

    Elvenfighter, 24 Августа 2018

    Комментарии (3)
  8. PHP / Говнокод #24648

    −1

    1. 1
    2. 2
    $query  = "SELECT * FROM archivo_mhora WHERE id_aparato=" . $aparatos_row->id;
    $query .= " && DATE_FORMAT(fecha, '%Y.%m.%d')='" . date('Y.m.d', $cur_fecha) . "' ORDER BY energy";

    Я не знаю, к какой секции следует отнести этот высер:
    1) Автор решил учить испанский. Таблицы имеют имена `aparatos`, `abonandos`, etc
    2) Само собой, SQL injection
    3) Порнография при работе с датой

    kai, 23 Августа 2018

    Комментарии (3)
  9. Куча / Говнокод #24645

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    def $qmark = 1
    def ? = 1
    
    // Error:(2, 6) method ? is defined twice

    Scala-way

    vistefan, 21 Августа 2018

    Комментарии (26)
  10. JavaScript / Говнокод #24641

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    <!-- todo: put this in a different file!!! -->
    <script>
    function authenticateUser(username, password) {
      var accounts = apiService.sql(
        "SELECT * FROM users"
      );
    
      for (var i = 0; i < accounts.length; i++) {
        var account = accounts[i];
        if (account.username === username &&
            account.password === password)
        {
          return true;
        }
      }
      if ("true" === "true") {
        return false;
      }
    }
    
    $('#login').click(function() {
      var username = $("#username").val();
      var password = $("#password").val();
    
      var authenticated = authenticateUser(username, password);
    
      if (authenticated === true) {
        $.cookie('loggedin', 'yes', { expires: 1});
      } else if (authenticated === false) {
        $("#error_message").show();
      }
    });
    </script>

    This JavaScript code powers a 1,500 user intranet application

    theraphim, 20 Августа 2018

    Комментарии (35)