1. Лучший говнокод

    В номинации:
    За время:
  2. Python / Говнокод #28422

    −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
    words = ['Broom', 'Being', 'Boring', 'Breeding', 'Dreaming', 'Doing', 'Dancing', 'Drinking',
         'Freezing', 'Falling', 'Flooding', 'Fearing', 'Saying', 'Sleeping', 'Standing',
         'Screaming', 'Running', 'Reading', 'Rolling', 'Rushing', 'Twerking', 'Telling']
    
    def make_rows(row_size: int) -> list:
        row_size = abs(int(row_size)); index = 0; amount = len(words)
        # Найти кол-во групп / Calculate the amount of sublists
        if row_size>amount: row_size=amount
        if row_size > 0:
            subs = (amount // row_size) + 1 if amount % row_size > 0 else amount // row_size
            print(f'Слов: {len(words)} | | Ячеек: {subs}\n')
            # Создать найденное кол-во групп / Create the found amount of sublists
            rows = [[] for i in range(subs)]
            for x in range(amount):
                rows[index].append(words[x])
                if len(rows[index]) == row_size: index += 1
            return rows
        else: return words
            
    print(make_rows(2))

    rockkley94, 19 Октября 2022

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

    +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
    #include <stddef.h>
    #include <stdio.h>
    #include <utility>
    #define PLACEHOLDER char x[0];
    
    #define FORCEINLINE 
    template <typename T, typename... Ts> struct MyTuple : MyTuple<Ts...>
    {
    	FORCEINLINE constexpr MyTuple(T&& t, Ts&&... ts)
    		: value(std::move(t))
    		, MyTuple<Ts...> (std::forward<Ts>(ts)...){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T,Ts...> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T,Ts...> &&other)
    		: MyTuple<Ts...>(std::forward<MyTuple<Ts...>>(other)),
    		value(std::move(other.value)){}
    
    	FORCEINLINE constexpr int size() const { return 1 + MyTuple<Ts...>::size(); }
    	constexpr static int sz = 1 + MyTuple<Ts...>::sz;
    	FORCEINLINE MyTuple<Ts...> &next(){return *static_cast<MyTuple<Ts...>*>(this);}
    	using tnext = MyTuple<Ts...>;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    struct MyTupleEmpty
    {
    	PLACEHOLDER
    	FORCEINLINE constexpr int size() const { return 0; }
    	static constexpr int sz = 0;
    	~MyTupleEmpty() {}
    	constexpr static bool isitem = false;
    };
    
    template <typename T> struct MyTuple<T> {
    	FORCEINLINE MyTuple(T&& t) : value(std::move(t)){}
    	FORCEINLINE explicit MyTuple(const MyTuple<T> &other) = default;
    	FORCEINLINE MyTuple(MyTuple<T> &&other): value(std::move(other.value)){}
    
    	FORCEINLINE MyTupleEmpty &next() const{
    		static MyTupleEmpty empty;
    		return empty;
    	}
    	FORCEINLINE constexpr int size() const { return 1; }
    	constexpr static int sz = 1;
    	using tnext =MyTupleEmpty;
    	T value;
    	FORCEINLINE ~MyTuple() {}
    	constexpr static bool isitem = false;
    };
    template <class T>struct unwrap_refwrapper{using type = T;};
    template <class T>struct unwrap_refwrapper<std::reference_wrapper<T>>{using type = T&;};
     template <class T> using unwrap_decay_t = typename unwrap_refwrapper<typename std::decay<T>::type>::type;
    template<typename... Ts>
    static FORCEINLINE MyTuple<unwrap_decay_t<Ts>...> MakeTuple(Ts&&... args)
    {
    	return MyTuple<unwrap_decay_t<Ts>...>(std::forward<Ts>(args)...);
    }
    struct i3{
        auto setProp(auto x, i3 t = *(i3*)0)
        {
            typename decltype(x(*this))::tp c;
            return c;
        }
        using tp = i3;
    };
    
    
    #define s(x,y) setProp([](auto c){struct xxx: decltype(c)::tp{decltype(y) x = y;using tp = xxx;    decltype([] (auto xx, xxx &t = *(xxx*)0)\
        {\
            typename decltype(xx(t))::tp c;\
            return c;\
        }) setProp;auto BeginChildren(){return *this;}} d;return d;})
    
    #define c(...) BeginChildren(),MakeTuple(__VA_ARGS__)
    #define i(...) i3()
    
    
    
    
    void func2()
    {
        auto tp = MakeTuple(
        i(Window)
            .s(width,10)
            .s(height,20)
            .c(
                i(Item),
                i(Item2)
                    .s(property1,10.0f)
    
            )
        );
        printf("%d %d %f\n",tp.value.height,tp.value.width, tp.next().value.next().value.property1);
    }
    
    int main()
    {
        func2();
    }

    qml-like структура в compile time
    Стандартизаторы всё пытались запретить шаблоны в локальных классах, да не вышло - понаоставляли дыр в лямбдах и decltype.
    Если добавить -fpermissive, то gcc сожрёт даже с constexpr

    mittorn, 09 Августа 2022

    Комментарии (19)
  4. PHP / Говнокод #28113

    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
    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
    // Проверка активных ip-адресов
    $is_active = false;
    if ($dir = opendir($path_active)) {
        while (false !== ($filename = readdir($dir))) {
            // Выбирается ip + время активации этого ip
            if (preg_match('#^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})_(\d+)$#', $filename, $matches)) {
                if ($matches[2] >= time() - self::intervalSeconds) {
                    if ($matches[1] == $ip_address) {
                        $times = intval(trim(file_get_contents($path_active . $filename)));
                        if ($times >= self::intervalTimes - 1) {
                            touch($path_block . $filename);
                            unlink($path_active . $filename);
                        } else {
                            file_put_contents($path_active . $filename, $times + 1);
                        }
                        $is_active = true;
                    }
                } else {
                    unlink($path_active . $filename);
                }
            }
        }
        closedir($dir);
    }
    
    // Проверка заблокированных ip-адресов
    $is_block = false;
    if ($dir = opendir($path_block)) {
        while (false !== ($filename = readdir($dir))) {
            // Выбирается ip + время блокировки этого ip
            if (preg_match('#^(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})_(\d+)$#', $filename, $matches)) {
                if ($matches[2] >= time() - self::blockSeconds) {
                    if ($matches[1] == $ip_address) {
                        $is_block = true;
                        $time_block = $matches[2] - (time() - self::blockSeconds) + 1;
                    }
                } else {
                    unlink($path_block . $filename);
                }
            }
        }
        closedir($dir);
    }
    
    // ip-адрес заблокирован
    if ($is_block) {
        header('HTTP/1.0 502 Bad Gateway');
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
        echo '<html xmlns="http://www.w3.org/1999/xhtml">';
        echo '<head>';
        echo '<title>502 Bad Gateway</title>';
        echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
        echo '</head>';
        echo '<body>';
        echo '<h1 style="text-align:center">502 Bad Gateway</h1>';
        echo '<p style="background:#ccc;border:solid 1px #aaa;margin:30px au-to;padding:20px;text-align:center;width:700px">';
        echo 'К сожалению, Вы временно заблокированы, из-за частого запроса страниц сайта.<br />';
        echo 'Вам придется подождать. Через ' . $time_block . ' секунд(ы) Вы будете автоматически разблокированы.';
        echo '</p>';
        echo '</body>';
        echo '</html>';
        exit;
    }

    PHP-скрипт для защиты от DDOS, парсинга и ботов
    https://habr.com/ru/post/659811/

    ISO, 08 Апреля 2022

    Комментарии (19)
  5. Python / Говнокод #28104

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    def _generate_greeting(self) -> str:
        date = datetime.datetime.fromtimestamp(time.time(), pytz.timezone(config.TIMEZONE))
        if 6 <= date.hour < 11:
            return 'Доброе утро!'
        elif 11 <= date.hour < 18:
            return 'Добрый день.'
        elif 18 <= date.hour < 23:
            return 'Добрый вечер.'
        else:
            return 'Доброй ночи.'

    ISO, 03 Апреля 2022

    Комментарии (19)
  6. Python / Говнокод #28072

    +4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class ProjectIssue(
        UserAgentDetailMixin,
        SubscribableMixin,
        TodoMixin,
        TimeTrackingMixin,
        ParticipantsMixin,
        SaveMixin,
        ObjectDeleteMixin,
        RESTObject,
    ):

    ISO, 05 Марта 2022

    Комментарии (19)
  7. Assembler / Говнокод #28007

    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
    .org 80h
    data:
    	db "Hello, world!\n"
    	
    wait:
    	.loop:
    		inb %cl E9h
    		cmp %cl 0h
    		jnz @.loop
    	ret
    		
    start:
    	mov %sp 300h
    	.loop:
    		mov %al [%b + @data]
    		inc %b
    		outb E9h %al
    		call @wait
    		cmp %al Ah
    		jnz @.loop
    	int 0h

    забацал port-mapped io, работает в отдельном потоке
    sudo bormand

    digitalEugene, 11 Февраля 2022

    Комментарии (19)
  8. JavaScript / Говнокод #27913

    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
    function move1(direction: "up" | "down") {
        switch (direction) {
            case "up":
                return 1;
            case "down":
                return -1; 
        }
    
        return 0;
    }
    
    function main() {
    
        print(move1("up"));
        print(move1("down"));
    
        print("done.");
    }

    а ты умеешь так говнокодить на C/C++?

    ASD_77, 02 Января 2022

    Комментарии (19)
  9. Java / Говнокод #27574

    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
    package test.sandbox
    
    object Main {
      def foo(implicit a: Int): Int = a * 2
    
      def main(args: Array[String]): Unit = {
        {
          import Test._
          val result = foo
    
          println(s"Result1 = $result") // Result1 = 42
        }
        {
          implicit val x = 16
          println(s"Result2 = $foo")  // Result2 = 32
        }
      }
    }
    
    object Test {
      implicit val x: Int = 21
    }

    "Scala" — сахарная. (*^‿^*)

    PolinaAksenova, 16 Августа 2021

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

    +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
    ...
    
           fun([N1, _N2], Trace) ->
                   ?assert(
                      ?strict_causality( #{?snk_kind := "Adding table to a shard", shard := _Shard, live_change := true}
                                       , #{?snk_kind := "Shard schema change"}
                                       , ?of_node(N1, Trace)
                                       )),
                   ?assert(
                      ?strict_causality( #{?snk_kind := "Shard schema change", shard := _Shard}
                                       , #{?snk_kind := "Restarting shard server", shard := _Shard}
                                       , ?of_node(N1, Trace)
                                       )),
                   %% Schema change must cause restart of the replica process and bootstrap:
                   {_, Rest} = ?split_trace_at(#{?snk_kind := "Shard schema change"}, Trace),
                   ?assert(
                      ?strict_causality( #{?snk_kind := "Restarting shard server", shard := _Shard}
                                       , #{?snk_kind := state_change, to := bootstrap}
                                       , Rest
                                       ))
           end).

    Немного galaxy-brain тестов

    CHayT, 17 Июля 2021

    Комментарии (19)
  11. C# / Говнокод #27295

    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
    using System;
    
    namespace NoName
    {
        class TwoVariables
        {
            static void Main(string[] args)
            {
                Int32 FirstVariable = Convert.ToInt32(Console.ReadLine());
                Int32 SecondVariable = Convert.ToInt32(Console.ReadLine());
                FirstVariable = FirstVariable + SecondVariable;
                SecondVariable = FirstVariable - SecondVariable;
                FirstVariable = FirstVariable - SecondVariable;
                Console.WriteLine("First Variable is: " + FirstVariable);
                Console.WriteLine("Second Variable is: " + SecondVariable);
                Console.ReadKey();
            }
        }
    }
    
    
    
    
    
    
    
    
    
    
    // Продам гараж

    BelCodeMonkey, 15 Марта 2021

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