1. Куча / Говнокод #27322

    0

    1. 1
    Пиздец-оффтоп #15

    #1: https://govnokod.ru/26503 https://govnokod.xyz/_26503
    #2: https://govnokod.ru/26541 https://govnokod.xyz/_26541
    #3: https://govnokod.ru/26583 https://govnokod.xyz/_26583
    #4: https://govnokod.ru/26689 https://govnokod.xyz/_26689
    #5: https://govnokod.ru/26784 https://govnokod.xyz/_26784
    #5: https://govnokod.ru/26839 https://govnokod.xyz/_26839
    #6: https://govnokod.ru/26986 https://govnokod.xyz/_26986
    #7: https://govnokod.ru/27007 https://govnokod.xyz/_27007
    #8: https://govnokod.ru/27023 https://govnokod.xyz/_27023
    #9: https://govnokod.ru/27098 https://govnokod.xyz/_27098
    #10: https://govnokod.ru/27125 https://govnokod.xyz/_27125
    #11: https://govnokod.ru/27129 https://govnokod.xyz/_27129
    #12: https://govnokod.ru/27184 https://govnokod.xyz/_27184
    #13: https://govnokod.ru/27286 https://govnokod.xyz/_27286
    #14: https://govnokod.ru/27298 https://govnokod.xyz/_27298

    nepeKamHblu_nemyx, 27 Марта 2021

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

    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
    def luhn(self):
            all_sum = 0
            self.__card_number = str(self.__card_number)
            self.__card_number = list(self.__card_number)
            for element in range(len(self.__card_number)):
                if element % 2 == 0:
                    self.__card_number[element] = int(self.__card_number[element]) * 2
                    if self.__card_number[element] > 9:
                        number = self.__card_number[element]
                        self.__card_number[element] = number // 100 + number // 10 % 10 + number % 10  # sum digits of number
                self.__card_number[element] = int(self.__card_number[element])
                all_sum += self.__card_number[element]
            checksum = 0
            while checksum < 10:
                if all_sum % 10 == 0:
                    checksum = str(checksum)
                    break
                else:
                    all_sum += 1
                    checksum += 1
            self.i = str(self.i)
            self.i = list(self.i)
            self.i.append(checksum)
            self.__card_number = self.i
     
            self.__card_number = "".join(self.__card_number)

    Для преокта нужен был алгоритм луна, чтобы создать в конце контрольную сумму. При написании проебался, что мне card_number нужно просто добавить 1 цифру, а не менять его и по этому просто добавил костыль в виде i.

    warzon131, 27 Марта 2021

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

    +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
    $query = "
    	SELECT
    		`version`, `mods`, `plugins`, `keywords`
    	WHERE
    		`version` = {$version}";
    foreach (explode(",", $mods) as $mod)
    {
    	$query += "AND `mods` LIKE '{$mod}' OR `mods` LIKE '{$mod},%' OR `mods` LIKE '%,{$mod},%' OR `mods` LIKE '%,{$mod}'";
    }
    foreach (explode(",", $plugins) as $plugin)
    {
    	$query += "AND `plugins` LIKE '{$plugin}' OR `plugins` LIKE '{$plugin},%' OR `plugins` LIKE '%,{$plugin},%' OR `plugins` LIKE '%,{$plugin}'";
    }

    Говнокод чтобы прогнать массив с id записей внутри varchar по массиву с id записей из переменной (id,id,id)

    Dev1lroot, 27 Марта 2021

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

    +1

    1. 1
    Просто оффтоп #17

    #1: https://govnokod.ru/20162 https://govnokod.xyz/_20162
    #2: https://govnokod.ru/25329 https://govnokod.xyz/_25329
    #3: https://govnokod.ru/25415 https://govnokod.xyz/_25415
    #4: (vanished) https://govnokod.xyz/_25472
    #5: https://govnokod.ru/25693 https://govnokod.xyz/_25693
    #6: (vanished) https://govnokod.xyz/_26649
    #7: https://govnokod.ru/26672 https://govnokod.xyz/_26672
    #8: https://govnokod.ru/26924 https://govnokod.xyz/_26924
    #9: https://govnokod.ru/27072 https://govnokod.xyz/_27072
    #10: https://govnokod.ru/27086 https://govnokod.xyz/_27086
    #11: https://govnokod.ru/27122 https://govnokod.xyz/_27122
    #12: https://govnokod.ru/27153 https://govnokod.xyz/_27153
    #13: https://govnokod.ru/27159 https://govnokod.xyz/_27159
    #14: https://govnokod.ru/27200 https://govnokod.xyz/_27200
    #15: https://govnokod.ru/27237 https://govnokod.xyz/_27237
    #16: https://govnokod.ru/27282 https://govnokod.xyz/_27282

    nepeKamHblu_nemyx, 26 Марта 2021

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

    +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
    using System.Device.Gpio;
    using System;
    using System.Threading;
    
    namespace Blinky
    {
    	public class Program
        {
            private static GpioController s_GpioController;
            public static void Main()
            {
                s_GpioController = new GpioController();
    
                // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
                GpioPin led = s_GpioController.OpenPin(4,PinMode.Output);
                led.Write(PinValue.Low);
    
                while (true)
                {
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(125);
                    led.Toggle();
                    Thread.Sleep(525);
                }
            }        
        }
    }

    https://habr.com/ru/post/549012/: «.NET nanoFramework — платформа для разработки приложений на C# для микроконтроллеров».

    Ну все, последний оплот сишки пал, можно ее закапывать.

    PolinaAksenova, 25 Марта 2021

    Комментарии (26)
  6. C++ / Говнокод #27317

    +1

    1. 1
    pubimbue, ate и ios

    давайте ржать над крестостримами

    booratihno, 25 Марта 2021

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

    +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
    #include <array>
    #include <iostream>
    #include <string_view>
    #include <type_traits>
    
    std::string_view getMaxMargin();
    
    template<int bit_num>
    struct flag {
        friend constexpr int adl_flag(flag<bit_num>);
    };
    
    template<int bit_num>
    struct writer {
        friend constexpr int adl_flag(flag<bit_num>)
        {
            return bit_num;
        }
    
        static constexpr int value = bit_num;
    };
    
    template<int bit_num, int = adl_flag(flag<bit_num>{})>
    constexpr bool is_flag_set(int, flag<bit_num>)
    {
        return bit_num >= 0;
    }
    
    template<int bit_num>
    constexpr bool is_flag_set(float, flag<bit_num>)
    {
        return false;
    }
    
    template<size_t number, size_t bit_num>
    constexpr bool get_bit()
    {
        return (number & (1 << bit_num)) != 0;
    }
    
    #define flags_to_size()                     \
         ((is_flag_set<0>(0, flag<0>{}) << 0)   \
        | (is_flag_set<1>(0, flag<1>{}) << 1)   \
        | (is_flag_set<2>(0, flag<2>{}) << 2)   \
        | (is_flag_set<3>(0, flag<3>{}) << 3))
    
    template<bool test, typename T_true, typename T_false>
    struct meta_if {
        using type = T_true;
    };
    
    template<typename T_true, typename T_false>
    struct meta_if<false, T_true, T_false> {
        using type = T_false;
    };
    
    template<bool test, typename T_true, typename T_false>
    using meta_if_t = typename meta_if<test, T_true, T_false>::type;
    
    template<
        size_t desired_size,
        int = (0 +
               sizeof(meta_if_t<get_bit<desired_size, 0>(), writer<0>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 1>(), writer<1>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 2>(), writer<2>, int>) +
               sizeof(meta_if_t<get_bit<desired_size, 3>(), writer<3>, int>)
        )
    >
    constexpr size_t f()
    {
        return desired_size;
    }
    
    int main()
    {
        constexpr size_t a = f<1>();
        constexpr size_t b = f<6>();
        std::cout << "Max margin size: " << getMaxMargin().size() << std::endl;
    }
    
    constexpr size_t MARGIN_SIZE = flags_to_size();
    constexpr char MARGIN_CHAR = 'x';
    
    template<typename T, T... Args>
    constexpr auto getMarginStorageImpl(std::integer_sequence<T, Args...>)
    {
        return std::array<char, sizeof...(Args)>{(static_cast<void>(Args), MARGIN_CHAR)...};
    }
    constexpr auto getMarginStorage()
    {
        return getMarginStorageImpl(std::make_integer_sequence<int, MARGIN_SIZE>());
    }
    constexpr static auto marginStorage = getMarginStorage();;
    
    std::string_view getMaxMargin()
    {
        return std::string_view(marginStorage.data(), MARGIN_SIZE);
    }

    "Интересно, можно ли насфиначить такой шаблон, чтобы в пределах TU сгенерированные литералы были слайсами одного статического массива, длина которого выводилась бы автоматически."

    PolinaAksenova, 25 Марта 2021

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

    +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
    ?check_trace(
           begin
               %% Inject some orderings to make sure the replicant
               %% receives transactions in all states.
               %%
               %% 1. Commit some transactions before the replicant start:
               ?force_ordering(#{?snk_kind := trans_gen_counter_update, value := 5}, #{?snk_kind := state_change, to := disconnected}),
               %% 2. Make sure the rest of transactions are produced after the agent starts:
               ?force_ordering(#{?snk_kind := subscribe_realtime_stream}, #{?snk_kind := trans_gen_counter_update, value := 10}),
               %% 3. Make sure transactions are sent during TLOG replay:
               ?force_ordering(#{?snk_kind := state_change, to := bootstrap}, #{?snk_kind := trans_gen_counter_update, value := 15}),
               %% 4. Make sure some transactions are produced while in normal mode
               ?force_ordering(#{?snk_kind := state_change, to := normal}, #{?snk_kind := trans_gen_counter_update, value := 25}),
    ...

    Какой тест )))

    CHayT, 24 Марта 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    # PowerShell
    
    switch ($true)
    {
        ($firstNumber -gt $secondNumber) {Write-Output ("{0} > {1}" -F $firstNumber, $secondNumber)}
        ($firstNumber -eq $secondNumber) {Write-Output ("{0} == {1}" -F $firstNumber, $secondNumber)}
        ($firstNumber -lt $secondNumber) {Write-Output ("{0} < {1}" -F $firstNumber, $secondNumber)}
    }

    Интересный такой свитч-кейс (https://stackoverflow.com/questions/57063932/powershell-overriding-assignment-and-comparison-operators)

    groser, 24 Марта 2021

    Комментарии (5)
  10. Java / Говнокод #27313

    +5

    1. 1
    2. 2
    3. 3
    private static String getMargin(final int size) {
            return "                                                                                                                             ".substring(0, 6 * size);
        }

    Как создать пустую строку с заданной длиной...

    nekkiy, 24 Марта 2021

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