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

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

    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
    <?php
    
    $domains = [
    'edge-star-shv-%s-%s.facebook.com',      /* edge-chat.facebook.com, graph.facebook.com, mbasic.facebook.com, touch.facebook.com */ 
    'instagram-p42-shv-%s-%s.fbcdn.net',     /* www.instagram.com, b.i.instagram.com */
    'edge-sonar-mini-shv-%s-%s.fbcdn.net',   /* не знаю, для чего нужны edge-sonar-mini */
    'edge-star-mini-shv-%s-%s.facebook.com', /* www.facebook.com, m.facebook.com, fb.com */
    'instagram-p3-shv-%s-%s.fbcdn.net',      /* api.instagram.com, i.instagram.com, l.instagram.com, graph.instagram.com, edge-chat.instagram.com, */
                                             /* static.cdninstagram.com, scontent-hel3-1.cdninstagram.com, scontent.cdninstagram.com, */
                                             /* threads.net, www.threads.net */
    'xx-fbcdn-shv-%s-%s.fbcdn.net',          /* scontent-hel3-1.xx.fbcdn.net, static.xx.fbcdn.net, connect.facebook.net, scontent.xx.fbcdn.net */
    'edge-dgw-shv-%s-%s.facebook.com'        /* gateway.facebook.com, gateway.instagram.com, gateway.threads.net */
    ];
    
    $suffices = explode(',', 'akl1,ams2,ams4,arn2,atl3,bcn1,bkk1,bog1,bog2,bom1,bom2,bos5,bru2,ccu1,cdg4,cgk1,cph2,cpt1,del1,del2,den2,den4,dfw5,dub4,dus1,eze1,fco2,for1,fra3,fra5,gig4,gru1,gru2,ham3,hel3,hkg1,hkg4,hou1,hyd1,iad3,jnb1,jnb2,kul2,kul3,lax3,lga3,lhr6,lhr8,lim1,lis1,los2,maa2,mad1,mad2,man2,mct1,mia3,mnl1,mrs2,msp1,muc2,mxp1,mxp2,nrt1,ord5,otp1,pmo1,pnq1,prg1,qro1,scl2,sea1,sin6,sjc3,sof1,syd2,tpe1,vie1,waw1,xsp1,zrh1');
    
    foreach ($domains as $domain) {
      foreach (['01','02','03','04'] as $index) {
        foreach ($suffices as $suffix) {
            $url = sprintf($domain, $index, $suffix);
            $raw = gethostbynamel($url);
            if(!is_array($raw)) continue;
            $ips = implode(',', $raw);
            echo $ips,' ', $url, PHP_EOL;
        }
      }
    }

    Получение списка IP-адресов, используемых сервисами Ф*к, И*м и Threads.

    Myxa, 13 Января 2024

    Комментарии (21)
  3. Python / Говнокод #28807

    0

    1. 1
    During handling of the above exception, another exception occurred

    А бывает "Исключение возникло при обработке исключения, которое возникло при попытке обработать исключение"?

    3_dar, 27 Июня 2023

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

    +3

    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
    case 'sav8':
    if (isset($user) & $user['balls'] < $color[cena2])
    {
    echo "Недостаточно баллов.Надо :$color[cena2] баллов.А у вас <b>$user[balls]</b>\n";
    }else{
    mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-$color['cena2'])."' WHERE `id` = '$user[id]' LIMIT 1",$db);
    mysql_query("UPDATE `user` SET `ncolor`='#FFA500'  WHERE `id` = '$user[id]'");
    mysql_query("UPDATE `user` SET `ncolor2`='#FFA500'  WHERE `id` = '$user[id]'");
    echo 'Сохранено!<br/>'; } break;
    
    case 'sav9':
    if (isset($user) & $user['balls'] < $color[cena2])
    {
    echo "Недостаточно баллов.Надо :$color[cena2] баллов.А у вас <b>$user[balls]</b>\n";
    }else{
    mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-$color['cena2'])."' WHERE `id` = '$user[id]' LIMIT 1",$db);
    mysql_query("UPDATE `user` SET `ncolor`='#8B008B'  WHERE `id` = '$user[id]'");
    mysql_query("UPDATE `user` SET `ncolor2`='#8B008B'  WHERE `id` = '$user[id]'");
    echo 'Сохранено!<br/>'; } break;
    
    case 'sav10':
    if (isset($user) & $user['balls'] < $color[cena2])
    {
    echo "Недостаточно баллов.Надо :$color[cena2] баллов.А у вас <b>$user[balls]</b>\n";
    }else{
    mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-$color['cena2'])."' WHERE `id` = '$user[id]' LIMIT 1",$db);
    mysql_query("UPDATE `user` SET `ncolor`='#000000'  WHERE `id` = '$user[id]'");
    mysql_query("UPDATE `user` SET `ncolor2`='#000000'  WHERE `id` = '$user[id]'");
    echo 'Сохранено!<br/>'; } break;
    
    case 'sav11':
    if (isset($user) & $user['balls'] < $color[cena2])
    {
    echo "Недостаточно баллов.Надо :$color[cena2] баллов.А у вас <b>$user[balls]</b>\n";
    }else{
    mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-$color['cena2'])."' WHERE `id` = '$user[id]' LIMIT 1",$db);
    mysql_query("UPDATE `user` SET `ncolor`='#696969'  WHERE `id` = '$user[id]'");
    mysql_query("UPDATE `user` SET `ncolor2`='#696969'  WHERE `id` = '$user[id]'");
    echo 'Сохранено!<br/>'; } break;
    
    case 'sav12':
    if (isset($user) & $user['balls'] < $color[cena2])
    {
    echo "Недостаточно баллов.Надо :$color[cena2] баллов.А у вас <b>$user[balls]</b>\n";
    }else{
    mysql_query("UPDATE `user` SET `balls` = '".($user['balls']-$color['cena2'])."' WHERE `id` = '$user[id]' LIMIT 1",$db);
    mysql_query("UPDATE `user` SET `ncolor`='#FFFFFF'  WHERE `id` = '$user[id]'");
    mysql_query("UPDATE `user` SET `ncolor2`='#FFFFFF'  WHERE `id` = '$user[id]'");
    echo 'Сохранено!<br/>'; } break;

    Код смены цвета ника для одной популярной CMS доставшийся в "наследство" от клиента. Кто и под чем писал - без понятия.

    lionovsky, 18 Февраля 2022

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

    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
    public function onAnswerPoll()
        {
            $data = request()->all();
    
            ValidatePollForm::run($data);
    
            try {
                $options = Option::find($data['option_ids']);
    
                $log = Crypt::decrypt($data['log']);
                $log['options'] = array_merge(
                    array_get($log, 'options', []),
                    $options->lists('id')
                );
                $log['comments'] = array_get($log, 'comments', []) + array_get($data, 'comments', []);
    
                $this->log = Crypt::encrypt($log);
                $this->option = $options->first();
                $this->poll = $this->loadPoll();
                $this->locations = Location::get();
                $this->step = ++$data['step'];
    
                if ($this->option->is_last) {
                    Log::store($this->poll, $log);
                    Option::whereIn('id', $log['options'])->get()->each(function ($item) {
                        $item->increment('votes');
                        $item->logs()->create();
                    });
                }
            } catch (Exception $e) {
                trace_log($e);
                return response()
                    ->json('Something was wrong.', 500);
            }
        }
    
        /**
         * onLoadDepartments
         */
        public function onLoadDepartments()
        {
            $data = request()->all();
    
            $validator = Validator::make($data, [
                'location' => 'required|exists:kitsoft_polls_locations,slug',
                'answer_id' => 'required|exists:kitsoft_polls_answers,id'
            ]);
    
            if ($validator->fails()) {
                throw new ValidationException($validator);
            }
    
            try {
                $this->departments = Department::make()
                    ->whereHas('locations', function ($query) use ($data) {
                        return $query->where('slug', $data['location']);
                    })
                    ->whereHas('answers', function ($query) use ($data) {
                        return $query->where('id', $data['answer_id']);
                    })
                    ->get();
            } catch (Exception $e) {
                trace_log($e);
                return response()
                    ->json('Something was wrong.', 500);
            }
        }

    Из слитых сорцов «Дія.City».

    ISO, 18 Февраля 2022

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

    +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
    RUN apt install -y apache2
    RUN apt install -y php
    RUN apt install -y php-mysql
    RUN apt install -y libapache2-mod-php
    RUN apt install -y curl
    RUN apt install -y php-mbstring
    RUN apt install -y php-mysql
    RUN apt install -y php7.4-sqlite3
    RUN apt install -y php-gd
    RUN apt install -y php-intl
    RUN apt install -y php-xml
    RUN apt install -y php-curl
    
    #RUN apt install -y php7.0-ffmpeg
    
    RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.4/apache2/php.ini
    RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.4/cli/php.ini
    
    RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
    RUN echo "IncludeOptional /var/www/*.conf" >> /etc/apache2/apache2.conf
    #RUN sed -i "s/<\/VirtualHost>/Проверка\n<\/VirtualHost>" /etc/apache2/apache2.conf
    RUN sed -i "s/<\/VirtualHost>/\n\t<Directory \/var\/www\/html>\n\t<\/Directory>\n<\/VirtualHost>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tOptions Indexes FollowSymLinks MultiViews\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tAllowOverride All\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tOrder allow,deny\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tAllow from all\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN sed -i "s/<\/Directory>/\tRequire all granted\n\t<\/Directory>/g" /etc/apache2/sites-available/000-default.conf
    RUN mv /etc/apache2/sites-enabled/000-default.conf /tmp
    RUN cd /etc/apache2/sites-enabled/; ln -s ../sites-available/000-default.conf 000-default.conf
    RUN a2enmod php7.4
    RUN a2enmod rewrite
    #RUM apt install -y certbot
    #RUN a2enmod python-certbot-apache
    #RUN a2enmod ssl
    EXPOSE 80
    EXPOSE 22
    
    #        <Directory /var/www/html>
    #                Options Indexes FollowSymLinks MultiViews
    #                AllowOverride All
    #                Order allow,deny
    #                Allow from all
    #                Require all granted
    #        </Directory>
    
    RUN wget -O /var/www/html/index.phar https://github.com/mpak2/mpak.su/raw/master/phar/index.phar
    RUN wget -O /var/www/html/.htaccess https://github.com/mpak2/mpak.su/raw/master/.htaccess
    RUN wget -O /var/www/html/.htdb https://github.com/mpak2/mpak.su/raw/master/.htdb
    RUN chown www-data /var/www/html/.htdb
    RUN chown www-data /var/www/html
    RUN mkdir /var/www/html/include
    RUN mkdir /var/www/html/include/images
    RUN chmod 0777 /var/www/html/include/images
    RUN rm /var/www/html/index.html

    https://github.com/mpak2/mpak.su/blob/654b7daf0b7d4f3c83385c0ca35fcab6a1ec45f7/phar/docker/www/Dockerfile

    ISO, 07 Декабря 2021

    Комментарии (21)
  7. JavaScript / Говнокод #27688

    +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
    alex@ASD-PC:~/TypeScriptCompiler/3rdParty/llvm-wasm/debug/bin$ node mlir-translate.js --help
    OVERVIEW: MLIR Translation Testing Tool
    USAGE: mlir-translate.js [options] <input file>
    
    OPTIONS:
    
    Color Options:
    
      --color                                              - Use colors in output (default=autodetect)
    
    General options:
    
      --dot-cfg-mssa=<file name for generated dot file>    - file name for generated dot file
      --mlir-disable-threading                             - Disabling multi-threading within MLIR
      --mlir-elide-elementsattrs-if-larger=<uint>          - Elide ElementsAttrs with "..." that have more elements than the given upper limit
      --mlir-pretty-debuginfo                              - Print pretty debug info in MLIR output
      --mlir-print-debuginfo                               - Print debug info in MLIR output
      --mlir-print-elementsattrs-with-hex-if-larger=<long> - Print DenseElementsAttrs with a hex string that have more elements than the given upper limit (use -1 to disable)
      --mlir-print-op-on-diagnostic                        - When a diagnostic is emitted on an operation, also print the operation as an attached note
      --mlir-print-stacktrace-on-diagnostic                - When a diagnostic is emitted, also print the stack trace as an attached note
      -o=<filename>                                        - Output filename
      --split-input-file                                   - Split the input file into pieces and process each chunk independently
      Translation to perform
          --deserialize-spirv                                 - deserialize-spirv
          --import-llvm                                       - import-llvm
          --mlir-to-llvmir                                    - mlir-to-llvmir
          --serialize-spirv                                   - serialize-spirv
          --test-spirv-roundtrip                              - test-spirv-roundtrip
          --test-spirv-roundtrip-debug                        - test-spirv-roundtrip-debug
      --verify-diagnostics                                 - Check that emitted diagnostics match expected-* lines on the corresponding line
    
    Generic Options:
    
      --help                                               - Display available options (--help-hidden for more)
      --help-list                                          - Display list of available options (--help-list-hidden for more)
      --version                                            - Display the version of this program
    program exited (with status: 0), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)
    alex@ASD-PC:~/TypeScriptCompiler/3rdParty/llvm-wasm/debug/bin$

    сказ о том как я LLVM на WASM компилял :)

    ASD_77, 28 Сентября 2021

    Комментарии (21)
  8. Java / Говнокод #27663

    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
    private static final Map<Integer, FieldInfo> HEAD_FIELDS = new ImmutableMap.Builder<Integer, FieldInfo>()
    			.put(5, new FieldInfo("DOC.CODEOKATO", FieldInfoType.STRING))
    //			.put(7, new FieldInfo("DOC.NAMECMO", FieldInfoType.STRING))
    			.put(8, new FieldInfo("DOC.CODECMO", FieldInfoType.STRING))
    //			.put(9, new FieldInfo("DOC.NAMEMEDORG", FieldInfoType.STRING))
    			.put(10, new FieldInfo("DOC.CODEMO", FieldInfoType.STRING))
    			.put(14, new FieldInfo("DOC.INFINSPERSON_BIRTHDAY", FieldInfoType.DATE))
    			.put(12, new FieldInfo("DOC.INFINSPERSON_NUMHEALINS", FieldInfoType.STRING))
    			.put(15, new FieldInfo("DOC.INFINSPERSON_GENDER", FieldInfoType.STRING))
    			.put(16, new FieldInfo("DOC.INFINSPERSON_DATESTRMED", FieldInfoType.DATE))
    			.put(17, new FieldInfo("DOC.INFINSPERSON_DATEFINMED", FieldInfoType.DATE))
    			.put(13, new FieldInfo("DOC.INFINSPERSON_NMEDICCARD", FieldInfoType.STRING))
    			.put(18, new FieldInfo("DOC.INFINSPERSON_CODEMKB", FieldInfoType.STRING))
    			.put(23 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID19", FieldInfoType.STRING))
    			.put(24 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID191", FieldInfoType.STRING))
    			.put(25 - 1, new FieldInfo("DOC.INFINSPERSON_SEVCOVID192", FieldInfoType.STRING))
    			.build();

    Коллега изменил мой код, пока я болел.

    zloer, 14 Сентября 2021

    Комментарии (21)
  9. C++ / Говнокод #27568

    +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
    // https://github.com/seanbaxter/circle/blob/master/examples/README.md#tldr
    // ...
    // Circle's primary syntactic element is the @meta keyword, which runs the prefixed statement
    // during source translation (or during template instantiation in dependent contexts).
    
    // https://github.com/seanbaxter/circle/blob/master/examples/README.md#same-language-reflection
    // duff1.cxx
    
    void duff_copy1(char* dest, const char* source, size_t count) {
      const char* end = source + count;
      while(size_t count = end - source) {
        switch(count % 8) {
          case 0: *dest++ = *source++; // Fall-through to case 7
          case 7: *dest++ = *source++; // Fall-through to case 6...
          case 6: *dest++ = *source++;
          case 5: *dest++ = *source++;
          case 4: *dest++ = *source++;
          case 3: *dest++ = *source++;
          case 2: *dest++ = *source++;
          case 1: *dest++ = *source++;
          break;
        }
      }
    }
    
    // Reproduced above is a simplified version of Duff's device, an infamous memcpy function designed
    // to reduce the amount of branching in the operation. (The loop is optimally interleaved with the switch,
    // but I'm trying to illustrate some other points and don't want to add to the confusion.) Once we enter the
    // switch, perform an assignment and unconditionally progress to the next case statement. This algorithm
    // cries out for automation. The case statements have indices that run from 8 down to 1, modulo 8. Can we give it the Circle treatment?
    
    // duff2.cxx
    
    void duff_copy2(char* dest, const char* source, size_t count) {
      const char* end = source + count;
      while(size_t count = end - source) {
        switch(count % 8) {
          @meta for(int i = 8; i > 0; --i)
            case i % 8: *dest++ = *source++;
          break;
        }
      }

    Но гомоиконности таким подкостыливанием вы естественно не добавите!

    j123123, 14 Августа 2021

    Комментарии (21)
  10. C++ / Говнокод #27413

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if constexpr (BusMode::BLOCKING == mode) {
        derived()->send_block(arr, num);
    } else if (BusMode::IT == mode){
        derived()->send_it(arr, num);
    } else if (BusMode::DMA == mode){
        derived()->send_dma(arr, num);
    }

    https://habr.com/ru/post/556144/
    > Отладочный вывод на микроконтроллерах: как Concepts и Ranges отправили мой printf на покой
    Стреляем себе в ногу при помощи if constexpr.

    PolinaAksenova, 10 Мая 2021

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    %% Generates a Normal-distributed random variable using Box-Muller method
    %% from: https://github.com/basho/basho_stats/blob/develop/src/basho_stats_rv.erl
    -spec rnd_normal(integer(), integer()) -> non_neg_integer().
    rnd_normal(Mean, Sigma) ->
      Rv1 = random:uniform(),
      Rv2 = random:uniform(),
      Rho = math:sqrt(-2 * math:log(1-Rv2)),
      abs(trunc(Rho * math:cos(2 * math:pi() * Rv1) * Sigma + Mean)).

    Это норма.

    CHayT, 07 Мая 2021

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