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

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

    +20

    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
    source code: C++
    
    
    enum e_acomany {
    	Audi,
    	BMW, 
    	Cadillac, 
    	Ford,
    	Jaguar, 
    	Lexus 
    	Maybach, 
    	RollsRoyce, 
    	Saab
    };
    ?>

    Маны бывают разные. Этот, например, по C++

    guest, 20 Декабря 2008

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

    +42.8

    1. 1
    Многое из представленного здесь на самом деле является просто непонятным говнобыдлокодерами кода.

    Многое из представленного здесь на самом деле является просто непонятным говнобыдлокодерами кода.

    Нужна санитарная служба.

    guest, 15 Декабря 2008

    Комментарии (20)
  4. Си / Говнокод #29221

    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
    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
    /* IOCTL calls for E-Ink paper update */
    #define EPAPER_UPDATE_LOCAL 0x101         /** Update localarea */
    #define EPAPER_UPDATE_PART  0x102         /** ???              */
    #define EPAPER_UPDATE_FULL  0x103         /** Fully update     */
    #define EPAPER_UPDATE_DISPLAY_QT  0x120d  /** Update all display
    
    /* Helper FB update function */
    int epaper_update_helper(int fb, unsigned long int ioctl_call, void *mode)
    {
      if (framebuffer_descriptor >= 0)
      {
        errno=0;
        ioctl(fb, ioctl_call, mode);
    //    sleep_timer=sleep_timeout; // Reset sleep timer on every display refresh = we are not have any constantly refreshing display parts now!
        return errno;
      }
      return TRUE;
    }
    
    void epaperUpdate(__attribute__((unused)) unsigned long int ioctl_call, __attribute__((unused)) void *mode)
    {
      #ifndef __amd64
      int ioctl_result;
      #endif //__amd64
      TRACE("Called void epaperUpdate()\n");
      if (enable_refresh == FALSE)
      {
        TRACE("Display refresh was locked, IGNORED!\n");
        (void) ioctl_call;
        (void) mode;
        return;
      }
      #ifndef __amd64
      /* Иначе запись в видеопамять не успевает завершиться и получаем верхний левый угол новой картинки и нижний правый - прежней. */
    //  if (hw_platform != HW_PLATFORM_SIBRARY_GTK) {
    //    const struct timespec delay = {0, QT_REFRESH_DELAY};
    //    nanosleep(&delay, NULL);
    //  }
      ioctl_result=epaper_update_helper(framebuffer_descriptor, ioctl_call, mode);
      #ifdef debug
      if (ioctl_result != 0)
      {
        TRACE("Display refresh ioctl call FAILED %d (%s)\n", ioctl_result, strerror(ioctl_result));
        // GTK прошивка, обновление от Qt: 1 (Операция не позволяется)
        // Qt прошивка, обновление от GTK: 22 (Недопустимый аргумент)
      }
      #else
      (void) ioctl_result;
      #endif
      #endif
      return;
    }
    
    
    int detect_refresh_type (void)
    {
      int mode=3;
    #if 0
      struct mxcfb_update_data data = {
        .update_region =
        { .top = 0,
          .left = 0,
          .width = 1,
          .height = 1
        },
        .update_mode = UPDATE_MODE_FULL,
        .update_marker = 0,
        .waveform_mode = WAVEFORM_MODE_AUTO,
        .temp = TEMP_USE_AMBIENT,
        .flags = 0
      };
    #endif
      if (epaper_update_helper(framebuffer_descriptor, EPAPER_UPDATE_DISPLAY_QT, &mode) == 0)
      {
        refresh_type=REFRESH_NEW;
        TRACE("Display refresh was successed, new\n");
      }
      else if (epaper_update_helper(framebuffer_descriptor, EPAPER_UPDATE_FULL, &mode) == 0)
      {
        refresh_type=REFRESH_LEGACY;
        TRACE("Display refresh was successed, legacy\n");
      }
    //  else if (epaper_update_helper(framebuffer_descriptor, MXCFB_SEND_UPDATE_ORG, &data) == 0)
    //  {
    //    refresh_type=REFRESH_KOBO;
    //    TRACE("Display refresh was successed, kobo\n");
    //  }
      else
      {
        TRACE("Display refresh was not detected!\n");
      }
      return (refresh_type);
    }

    Источник:
    https://github.com/gheorghe-crihan/digma-e605-qt-apps-framework/blob/master/firstapp/digma_hw.c

    Не то, чтобы говно, просто код испещрён #if 0 и комментариями.

    HoBorogHuu_nemyx, 25 Января 2026

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

    0

    1. 1
    2. 2
    3. 3
    <?php
    // ...
    parse_str($ShopParams, $shopParams);

    Регистр одной буквы всё меняет!

    jonnywalker, 16 Апреля 2024

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

    0

    1. 1
    "good" =~ /g(?:o(*{print "o"}))*d/;

    Для выполнения блоков кода внутри regex-шаблона добавлена конструкция "*{ ... }", которая эквивалентна конструкциям "?{ ... }" и "??{ ... }", за исключением того, что её использование не приводит к отключению оптимизации в движке регулярных выражений, из-за чего повышается производительность, но поведение становится менее стабильным.

    JloJle4Ka, 04 Июля 2023

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

    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
    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    int main ()
    {
       char address[128], fname[128], command[128];
       FILE *tempfile;
    
       strcpy(fname , tmpnam(NULL));
       tempfile = fopen (fname, "w");     /* create temporary file */
       if (tempfile == NULL)              /* error - didn't create file */
       {
          printf("Internal failure #1 please report %d\n", errno);
          exit (1);
       }
       fprintf(tempfile, "Thank you very much for caring about our cause\n");
       fprintf(tempfile, "this letter is just to tell you how much we\n");
       fprintf(tempfile, "really think you are wonderful for caring.\n\n");
       fprintf(tempfile, "Sincerely,\n\n");
       fprintf(tempfile, "Jane Doe, Executive Thanker\n");
    fclose (tempfile);
       gets(address);                            /* read in email address */
    
       sprintf(command, "mail -s \"thanks for caring\" %s < %s\n",
               address, fname);                /* create the command */
       system (command);                       /* execute command */
       remove (fname);                         /* clean up */
       exit (0);
    }

    Игра: найди вулна.

    JloJle4Ka, 03 Февраля 2023

    Комментарии (19)
  8. 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)
  9. 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)
  10. 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)
  11. 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)