1. C++ / Говнокод #26912

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    void tick(void)
    {
    	for (auto&& x : registry.objects)
    		(x? std::function<void(void)>([&](void) {((IObject*)(x))->tick(); }) : [&]() {})();
    }

    Мозг сказал что "((IObject*)(x))->tick();" написать слишком сложно и повелел написать вот это.

    digitalEugene, 03 Сентября 2020

    Комментарии (30)
  2. C++ / Говнокод #26911

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int main()
    {
        + ! - ! -- -- ! + ! - - - ++ ~ - ! -- -- -- ~ ~ ~ ++ ++ ++ - ~ ++ - * - - -
        * ++ * * ++ * -- -- -- -- - * -- + * ++ ++ ++ ++ ++ * ++ * -- -- * -- - *
        
        BRAINFUCK;
        
        return 0;
    }

    https://ideone.com/EtK1J4

    Ответ на https://govnokod.ru/26910. Теперь с реальной конпеляцией в нативный код.

    bormand, 03 Сентября 2020

    Комментарии (13)
  3. C++ / Говнокод #26910

    +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
    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
    // https://govnokod.ru/26890#comment571155
    // bormand 2 часа назад #
    // Можно брейнфак запилить на операторах. Как раз вроде унарных хватает.
    // & * - ~ ! -- + ++ --
    
    #include <array>
    #include <vector>
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <limits>
    
    struct Brainfuck {
    public:
        using IPType = uint16_t;
        constexpr static size_t MAX_MEMORY = std::numeric_limits<IPType>::max();
    
        std::array<uint8_t, MAX_MEMORY> memory{};
        std::vector<char> app{};
        IPType ip = 0;
        IPType cell = 0;
    
        IPType find_matching_tag(IPType cur_ip, char open, char close, int ip_direction)
        {
            size_t stack_size = 0;
            do  {
                if (app[cur_ip] == close) {
                    --stack_size;
                }
                if (app[cur_ip] == open) {
                    ++stack_size;
                }
                cur_ip += ip_direction;
            } while (stack_size > 0);
            return cur_ip - ip_direction;
        }
    
        IPType find_matching_close_tag(IPType cur_ip)
        {
            return find_matching_tag(cur_ip, '[', ']', 1);
        }
    
        IPType find_matching_open_tag(IPType cur_ip)
        {
            return find_matching_tag(cur_ip, ']', '[', -1);
        }
    
        void loop_open()
        {
            if (memory[cell] == 0) {
                ip = find_matching_close_tag(ip);
            } else {
                ++ip;
            }
        }
    
        void loop_close()
        {
            if (memory[cell] != 0) {
                ip = find_matching_open_tag(ip);
            } else {
                ++ip;
            }
        }
    
        void exec(char op)
        {
            switch (op) {
                case '>': ++cell; break;
                case '<': --cell; break;
                case '+': ++memory[cell]; break;
                case '-': --memory[cell]; break;
                case '.': std::putchar(memory[cell]); break;
                case ',': memory[cell] = static_cast<uint8_t>(std::getchar()); break;
                case '[': loop_open(); return;   // no ip advancing
                case ']': loop_close(); return;  // no ip advancing
            }
            ip++;
        }
    
        void run()
        {
            while (ip < app.size()) {
                exec(app[ip]);
            }
        }
    
    public:
        Brainfuck & operator++() { app.push_back('>'); return *this; }
        Brainfuck & operator--() { app.push_back('<'); return *this; }
        Brainfuck & operator+() { app.push_back('+'); return *this; }
        Brainfuck & operator-() { app.push_back('-'); return *this; }
        Brainfuck & operator*() { app.push_back('.'); return *this; }
        Brainfuck & operator&() { app.push_back(','); return *this; }
        Brainfuck & operator!() { app.push_back('['); return *this; }
        Brainfuck & operator~() { app.push_back(']'); return *this; }
        Brainfuck & operator>>(const Brainfuck &) { run(); return *this; }
    };

    https://wandbox.org/permlink/XJUKGyb4YbnBVwOI

    Бонус («99 bottles of beer»): https://pastebin.com/s4sBK9nX (взято с https://github.com/fabianishere/brainfuck/blob/master/examples/bottles-1.bf).

    gost, 03 Сентября 2020

    Комментарии (244)
  4. Куча / Говнокод #26909

    0

    1. 1
    2. 2
    3. 3
    4. 4
    q)\l sp.q
    +`p`city!(`p$`p1`p2`p3`p4`p5`p6`p1`p2;`london`london`london`london`london`lon..
    (`s#+(,`color)!,`s#`blue`green`red)!+(,`qty)!,900 1000 1200
    +`s`p`qty!(`s$`s1`s1`s1`s2`s3`s4;`p$`p1`p4`p6`p2`p2`p4;300 200 100 400 200 300)

    https://code.kx.com/q/learn/tour/

    MAKAKA, 03 Сентября 2020

    Комментарии (4)
  5. C++ / Говнокод #26908

    +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
    void Argument::parseAsInt()
    {
        auto res = std::from_chars(data.data(), data.data() + data.size(), dataInt);
        if (res.ec == std::errc()) {
            setTypeFlag(ArgType::Int);
        }
    }
    
    void Argument::parseAsFloat()
    {
        // Rww: gcc still does not support float from_chars(), lol
        const char *begin = data.data();
        const char *end = begin + data.size();
        char *endPtr = nullptr;
    
        dataFloat = std::strtof(begin, &endPtr);
        if (endPtr == end || dataFloat != 0.0f) {
            setTypeFlag(ArgType::Float);
        } else {
            for (const char *it = endPtr; it < end; it++) {
                if (!std::isspace(*it)) {
                    return;
                }
            }
            setTypeFlag(ArgType::Float);
        }
    }

    Говнокодил тут недавно, долго думал, что считать числом (пет, ТЗ нет). В конце-концов решил считать всё, что можно распарсить.

    gost, 02 Сентября 2020

    Комментарии (14)
  6. JavaScript / Говнокод #26907

    −1

    1. 1
    // https://habr.com/ru/company/ruvds/blog/515676/

    Разбор худшего в мире куска кода.

    GDMaster, 02 Сентября 2020

    Комментарии (75)
  7. Си / Говнокод #26906

    +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
    /// Checks if the token is number or not
    bool is_number(char* test_val)
    {
        const char* ROW = "0123456789\0";
        
        for (int i = 0; i < strlen(test_val); i++) {
            for (int j = 0; j < strlen(ROW); j++) {
                if (test_val[i] == ROW[j]) {
                    goto next;
                }
            }
            return false;
            next:
        }
        return true;
    }

    Попытка проверить строку на число в Си.

    GDMaster, 02 Сентября 2020

    Комментарии (70)
  8. C++ / Говнокод #26905

    +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
    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
    //--------------------------------------------------------------------------------------------------------------------\\
    
        float max_rotation = record->m_pEntity->GetMaxBodyRotation();
       
    
        auto animstate = ent->m_PlayerAnimState();
        float resolve_value = 50.f; //не трогайте это, так и должно быть
    
        if (!record->m_pState)
            return;
    
        const auto info = g_anims.GetAnimationInfo(record->m_pEntity);
        if (!info)
            return;
    
        float eye_yaw = record->m_pState->m_flEyeYaw;
    
        if (max_rotation < resolve_value)
            resolve_value = max_rotation;
    
        data->m_extending = record->m_pLayers[3].m_cycle == 0.f && record->m_pLayers[3].m_weight == 0.f;
        float Delta = AngleDiff(ent->m_angEyeAngles().y, animstate->m_flGoalFeetYaw);
    
        //--------------------------------------------------------------------------------------------------------------------\\
                                                           RESOLVERPART
        //--------------------------------------------------------------------------------------------------------------------\\
    
        if (data->m_extending)
            resolve_value = max_rotation;
    
        if (ent->m_AnimOverlay()[13].m_weight + 14.250f > 0.54)
        {
            if (ent->m_AnimOverlay()[3].m_cycle > 0.12)
            {
                if (ent->m_AnimOverlay()[13].m_cycle > 0.43)
                {
                    animstate->m_flGoalFeetYaw = ent->m_angEyeAngles().y;
                }
            }
        }
    
        if (data->m_extending)
        {
            if (Delta <= 0)
            {
                animstate->m_flGoalFeetYaw = Delta * resolve_value;
            }
            else if (Delta > 0)
            {
                animstate->m_flGoalFeetYaw = Delta * -resolve_value;
            }
        }
    
        else if (ent->m_AnimOverlay()[7].m_order == record->m_pLayers[7].m_order)
        {
            if (ent->m_AnimOverlay()[7].m_cycle > 0.5f)
            {
                animstate->m_flGoalFeetYaw = math::NormalizeYaw(record->m_pEntity->m_flLowerBodyYawTarget()) + get_max_desync_delta;
                return;
            }
            else
                animstate->m_flGoalFeetYaw = record->m_pEntity->m_angEyeAngles().y;
        }
    
        if (record->m_bDidShot)
            info->m_flBrute = Resolver::ResolveShot(data, record);
    
        //--------------------------------------------------------------------------------------------------------------------\\
                                                        BRUTEFORCE PART
        //--------------------------------------------------------------------------------------------------------------------\\
    
        else {
            float lbyt = record->m_pEntity->m_flLowerBodyYawTarget();
            data->m_delta = std::abs(math::NormalizedAngle(eye_yaw - lbyt));
    
            float resolve_yaw = ((data->m_delta < 0.f) ? resolve_value : resolve_value);
    
            switch (data->m_missed_shots % 3) {
            case 0:
                info->m_flBrute = data->m_last_resolve = resolve_yaw;
                break;
            case 1:
                info->m_flBrute = -data->m_last_resolve;
                break;
            case 2:
                info->m_flBrute = 0;
                break;
            }
        }
    
        record->m_pState->m_flGoalFeetYaw = eye_yaw + info->m_flBrute;
    
        //--------------------------------------------------------------------------------------------------------------------\\

    best resolver

    danielka33, 02 Сентября 2020

    Комментарии (0)
  9. Assembler / Говнокод #26904

    +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
    lea esi, cpu_name
        mov eax, 0
        mov mreg, eax
    
        ;[04/12] G
        mov eax, 0ffh
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[03/12] e
        mov eax, 0ff00h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[02/12] n
        mov eax, 0ff0000h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[01/12] u
        mov eax, 0ff000000h
        and eax, ebx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi
    
        ;[08/12] i
        mov eax, 0ffh
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[07/12] n
        mov eax, 0ff00h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[06/12] e
        mov eax, 0ff0000h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[05/12] I
        mov eax, 0ff000000h
        and eax, edx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi
    
        ;[12/12] n
        mov eax, 0ffh
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg]
        mov [esi], al
        inc esi
    
        ;[11/12] t
        mov eax, 0ff00h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 1]
        mov [esi], al
        inc esi
    
        ;[10/12] e
        mov eax, 0ff0000h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 2]
        mov [esi], al
        inc esi
    
        ;[09/12] l
        mov eax, 0ff000000h
        and eax, ecx
        mov mreg, eax
        mov al, byte ptr [mreg + 3]
        mov [esi], al
        inc esi

    oaoaoammm, 01 Сентября 2020

    Комментарии (243)
  10. PHP / Говнокод #26903

    −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
    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
    public function index()
        {
            $items = CartManager::getAllItems();
    
            $couponCode = Coupon::getFromSession()->implode('code', ', ');
    
            $address = auth()->user()->address;
    
            $user = auth()->user();
            $userDetails = auth()->user() ? auth()->user()->fields : null;
    
            $fields = [
                'promo_code' => $couponCode,
                'email' => $user->email,
                'first_name' => $userDetails->firstname,
                'last_name' => $userDetails->lastname,
                'phone' => $userDetails->phone,
            ];
    
            if ($address) {
                $field = [
                    'value' => $address->city->title
                ];
                if ($address->city->type === \App\Address::TYPE_CITY) {
                    $field ['data']['city_fias_id'] = $address->city->id;
                    $field ['data']['city'] = $address->city->title;
                } elseif ($address->city->type === \App\Address::TYPE_SETTLEMENT) {
                    $field ['data']['settlement_fias_id'] = $address->city->id;
                    $field ['data']['settlement'] = $address->city->title;
                }
                $fields ['delivery_city'] = $field;
            }
    
            if ($address->street) {
                $fields ['delivery_street'] = [
                    'value' => $address->street->title,
                    'data' => [
                        'street_fias_id' => $address->street->id,
                    ]
                ];
            }
    
            if ($address->street_number) {
                $fields ['delivery_house_number'] = [
                    'value' => $address->street_number,
                ];
            }
    
            if ($address->flat) {
                $fields ['delivery_flat_number'] = $address->flat;
            }
    
            $fields = (object)$fields;
    
            $actions = [
                'remove' => route('shop.cart.remove'),
                'remove_gift_card' => route('shop.cart.gift-cards.remove'),
                'change' => route('shop.cart.update'),
                'promo' => route('shop.coupon.apply'),
                'checkout' => route('orders.store'),
                'get_pickups' => route('delivery_points.index'),
                'check_email' => route('check_email'),
            ];
    
            return view('shop.cart.index', compact(
                'items',
                'address',
                'couponCode',
                'fields',
                'actions'
            ));
        }

    this is MVC, baby !

    hrustbb2, 31 Августа 2020

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