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

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    func Map[F, T any](s []F, f func(F) T) []T {
        r := make([]T, len(s))
        for i, v := range s {
            r[i] = f(v)
        }
        return r
    }

    Го сдался.

    PolinaAksenova, 02 Июня 2021

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

    +1

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    <?php
    error_reporting(0);
    ini_set('display_errors', '0');
    mb_internal_encoding('UTF-8');
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: text/html; charset=utf-8');
    $string=mb_strtolower(trim($_REQUEST['q']));
    $string=str_replace('#', 'sharp', $string);
    $string=str_replace('++', 'plusplus', $string);
    preg_match_all('/(\w+)/u', str_replace('_', '', $string), $matches);
    $words=$matches[1];
    $bad=array();
    $good=array();
    foreach($words as $word){
    if(mb_strpos($word, 'java')!==false || mb_strpos($word, 'джав')!==false || mb_strpos($word, 'ява')!==false){
    if(mb_strpos($word, 'script')===false && mb_strpos($word, 'скрипт')===false){
    $bad[]='Java';
    }
    }
    if(mb_strpos($word, 'python')!==false || mb_strpos($word, 'питон')!==false || mb_strpos($word, 'пайтон')!==false){
    $bad[]='Python';
    }
    if(mb_strpos($word, 'perl')!==false || mb_strpos($word, 'перл')!==false || mb_strpos($word, 'пёрл')!==false){
    $bad[]='Perl';
    }
    if(mb_strpos($word, 'cplusplus')!==false || mb_strpos($word, 'сplusplus')!==false || mb_strpos($word, 'cpp')!==false){
    $bad[]='C++';
    }
    if(mb_strpos($word, 'csharp')!==false || mb_strpos($word, 'сsharp')!==false || mb_strpos($word, 'сишарп')!==false || mb_strpos($word, 'сшарп')!==false){
    $bad[]='C#';
    }
    if($word=='c' || $word=='си' || $word=='сях'){
    $bad[]='C';
    }
    if(mb_strpos($word, 'haskel')!==false || mb_strpos($word, 'хаскел')!==false){
    $bad[]='Haskell';
    }
    if(mb_strpos($word, 'pascal')!==false || mb_strpos($word, 'паскал')!==false){
    $bad[]='Pascal';
    }
    if(mb_strpos($word, 'delphi')!==false || mb_strpos($word, 'delfi')!==false || mb_strpos($word, 'делф')!==false || mb_strpos($word, 'дельф')!==false){
    $bad[]='Delphi';
    }
    if(mb_strpos($word, 'assembler')!==false || mb_strpos($word, 'asm')!==false || mb_strpos($word, 'ассемблер')!==false || mb_strpos($word, 'асм')!==false){
    $bad[]='Assembler';
    }
    if(mb_strpos($word, 'ruby')!==false || $word=='руби' || mb_strpos($word, 'рубист')!==false || mb_strpos($word, 'рубях')!==false){
    $bad[]='Ruby';
    }
    if(mb_strpos($word, '1c')!==false || mb_strpos($word, '1с')!==false || mb_strpos($word, '1ц')!==false){
    $bad[]='1C';
    }
    if(mb_strpos($word, 'dart')!==false || mb_strpos($word, 'дарт')!==false){
    $bad[]='Dart';
    }
    if(mb_strpos($word, 'linux')!==false || mb_strpos($word, 'линукс')!==false || mb_strpos($word, 'линух')!==false || mb_strpos($word, 'ubunt')!==false || mb_strpos($word, 'убунт')!==false || mb_strpos($word, 'debian')!==false || mb_strpos($word, 'дебиан')!==false || mb_strpos($word, 'freebsd')!==false || mb_strpos($word, 'фрибсд')!==false){
    $bad[]='Linux';
    }
    if(mb_strpos($word, 'unix')!==false || mb_strpos($word, 'nix')!==false || mb_strpos($word, 'юникс')!==false || mb_strpos($word, 'юних')!==false){
    $bad[]='Unix';
    }
    if(mb_strpos($word, 'jvm')!==false || mb_strpos($word, 'жвм')!==false){
    $bad[]='JVM';
    }
    if(mb_strpos($word, 'jsharp')!==false){
    $bad[]='J#';
    }
    if(mb_strpos($word, 'jplusplus')!==false){
    $bad[]='J++';
    }
    if(mb_strpos($word, 'git')!==false || mb_strpos($word, 'гит')!==false){
    if(mb_strpos($word, 'hub')===false && mb_strpos($word, 'хаб')===false && mb_strpos($word, 'lab')===false && mb_strpos($word, 'лаб')===false){
    $bad[]='Git';
    }
    }
    if(mb_strpos($word, 'svn')!==false || mb_strpos($word, 'свн')!==false){
    $bad[]='SVN';
    }
    if(mb_strpos($word, 'postgres')!==false || mb_strpos($word, 'постгр')!==false || mb_strpos($word, 'pg_')!==false){
    $bad[]='PostgreSQL';
    }
    if(mb_strpos($word, 'composer')!==false || mb_strpos($word, 'композер')!==false){
    $bad[]='Composer';
    }
    if(mb_strpos($word, 'bower')!==false || mb_strpos($word, 'бовер')!==false || mb_strpos($word, 'бауэр')!==false || mb_strpos($word, 'боуэр')!==false){
    $bad[]='Bower';
    }
    if(mb_strpos($word, 'node')!==false || mb_strpos($word, 'ноде')!==false || mb_strpos($word, 'нода')!==false){
    $bad[]='NodeJS';
    }
    if(mb_strpos($word, 'php')!==false || mb_strpos($word, 'пхп')!==false || mb_strpos($word, 'пых')!==false || mb_strpos($word, 'пэхапэ')!==false || mb_strpos($word, 'похапэ')!==false || mb_strpos($word, 'пехапе')!==false || mb_strpos($word, 'похапе')!==false || mb_strpos($word, 'эйч')!==false || mb_strpos($word, 'пшп')!==false){
    $good[]='PHP';
    }
    if(mb_strpos($word, 'mysql')!==false || mb_strpos($word, 'мускул')!==false || mb_strpos($word, 'майскул')!==false){
    $good[]='MySQL';
    }
    if(mb_strpos($word, 'windows')!==false || mb_strpos($word, 'виндовс')!==false || mb_strpos($word, 'шинд')!==false || mb_strpos($word, 'винд')!==false){
    $good[]='Windows';
    }
    }

    HighVoltageDick, 06 Августа 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Во сколько вы оцените время на разработку минимального сонсольного текстового редактора типа "vim" (назовем его "huim")
    со следующим функционалом:
    - 2 режима с переходами по "i" и "esc". Один режим редактирования текста, другой - режим команд.
    - только 2 команды - ":q!" и ":wq"
    - в текстовом режиме нихуя нет, кроме печатания символов, "Delete", "Backspace" и переходов по стрелкам.  
    
    
    Задача со звёздочкой:
    Что дополнительно надо, чтобы это работало во всех сонсолях: "Linux", "MacOS", "Windows", "ReactOS", "ColibriOS", " CentOS", "FreeBSD", "KDE", "Kubernetes"?

    P.S. Видел сегодня в метро на кольцевой дебила. Konardyan, это не ты был?

    LinuxGovno, 27 Ноября 2018

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

    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
    """
    This module provides a function merge_sort, which is one of the simplest and the
    most robust sorting algorithms, being relatively fast, having (n*log(n))
    complexity. Also, this module counts the number of inversions in a given array.
    Usage: import this module and use the function merge_sort. The first element in
    a returned tuple shall be a sorted array, while the second one will be a number
    of inversions in the array.
    
    Copyright (C) 2021 Sergay Gayorgyevich.
    
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.
    
    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    """
    
    import argparse
    
    def merge_sort(array : list) -> (list, int):
        """
        MergeSort algorithm with additional inversion counting.
        input: array.
        output: sorted array and number of inversions in it.
        """
    
        if len(array) <= 1:
            return (array, 0)
        elif len(array) == 2:
            if array[0] > array[1]:
                array[0], array[1] = array[1], array[0]
                return (array, 1)
            return (array, 0)
    
        mid = len(array) // 2
        left, left_inversions = merge_sort(array[:mid])
        right, right_inversions = merge_sort(array[mid:])
    
        merged, split_inversions = _merge(left, right)
        return (merged, right_inversions + left_inversions + split_inversions)
    
    def _merge(left_array : list, right_array : list) -> (list, int):
        """
        This function isn't supposed to be called, it's an inner function of the
        module, and not a part of its API! 
    
        The purpose of this function is to merge two arrays. Due to the nature of
        the MergeSort algorithm, it operates two arrays, both of which are sorted.
        input: two sotrted arrays.
        output: sorted array, consisting of elements of both operated arrays.
        """
    
        resulting_array = list()
        inversion_count = 0
        c_len = len(left_array) + len(right_array)
    
        for i in range(c_len):
            if (len(left_array) != 0) and (len(right_array) != 0):
                if left_array[0] > right_array[0]:
                    inversion_count += len(left_array)
                    resulting_array.append(right_array.pop(0))
                else:
                    resulting_array.append(left_array.pop(0))
            elif len(left_array) == 0:
                resulting_array.append(right_array.pop(0))
            elif len(right_array) == 0:
                resulting_array.append(left_array.pop(0))
    
        return (resulting_array[:], inversion_count)
    
    # For testing purposes only! Do not use in production!
    if __name__ == '__main__':
        DESC = "Sort an array and print an amount of inversions it has." # Description for argparse.
        argparser = argparse.ArgumentParser(description = DESC)
        argparser.add_argument("elements", type = int, nargs = '+', help = "A list to be sorted.")
        args = argparser.parse_args()
        print(merge_sort(args.elements))

    Изучаю алгоритм "Сортировка Слиянием".

    KoWe4Ka_l7porpaMMep, 12 Апреля 2021

    Комментарии (159)
  6. Java / Говнокод #25392

    +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
    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
    /*
     * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     *
     * This code is free software; you can redistribute it and/or modify it
     * under the terms of the GNU General Public License version 2 only, as
     * published by the Free Software Foundation.
     *
     * This code is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     * version 2 for more details (a copy is included in the LICENSE file that
     * accompanied this code).
     *
     * You should have received a copy of the GNU General Public License version
     * 2 along with this work; if not, write to the Free Software Foundation,
     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     *
     * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     * or visit www.oracle.com if you need additional information or have any
     * questions.
     */
    
    /* @test
       @bug 4890726
       @summary Check the correctness of KOI8_U by comparing to KOI8_R
     */
    
    import java.util.*;
    import static java.lang.Character.UnicodeBlock;
    
    public class UkrainianIsNotRussian {
        private static String decode(byte[] bytes, String encoding) throws Throwable {
            String s = new String(bytes, encoding);
            equal(s.length(), 1);
            check(Arrays.equals(s.getBytes(encoding), bytes));
            return s;
        }
    
        private static void realMain(String[] args) throws Throwable {
            final byte[] bytes = new byte[1];
            int differences = 0;
            for (int i = 0; i < 0xff; i++) {
                bytes[0] = (byte) i;
                final String r = decode(bytes, "KOI8_R");
                final String u = decode(bytes, "KOI8_U");
                if (! r.equals(u)) {
                    differences++;
                    final char rc = r.charAt(0);
                    final char uc = u.charAt(0);
                    final UnicodeBlock rcb = UnicodeBlock.of(rc);
                    final UnicodeBlock ucb = UnicodeBlock.of(uc);
                    System.out.printf("%02x => %04x %s, %04x %s%n",
                                      i, (int) rc, rcb, (int) uc, ucb);
                    check(rcb == UnicodeBlock.BOX_DRAWING &&
                          ucb == UnicodeBlock.CYRILLIC);
                }
            }
            equal(differences, 8);
        }
    
        //--------------------- Infrastructure ---------------------------
        static volatile int passed = 0, failed = 0;
        static void pass() {passed++;}
        static void fail() {failed++; Thread.dumpStack();}
        static void fail(String msg) {System.out.println(msg); fail();}
        static void unexpected(Throwable t) {failed++; t.printStackTrace();}
        static void check(boolean cond) {if (cond) pass(); else fail();}
        static void equal(Object x, Object y) {
            if (x == null ? y == null : x.equals(y)) pass();
            else fail(x + " not equal to " + y);}
        public static void main(String[] args) throws Throwable {
            try {realMain(args);} catch (Throwable t) {unexpected(t);}
            System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
            if (failed > 0) throw new AssertionError("Some tests failed");}
    }

    https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/test/jdk/sun/nio/cs/UkrainianIsNotRussian.java

    j123123, 21 Февраля 2019

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    Есть вопрос который меня давно мучает, он по поводу инкапсуляции, полеморфизма, нацизма и мазохизма.
    Почему хохлы так любят Java?
    Самый противный ЯП я считаю, синтаксис мерзкий, мерзкие обязательные классы, но кое что в нем радует, кроссплатформенность и неплохая производительность на первый взгляд не очевидная, но запись в миллиардный миссив происходит быстрее в жабе, чем на чистом Си без оптимизаций, но Си с -O2 все равно быстрее.
    И все таки почему украинцы так любят жабу, или они ничего другого не знают и как можно привыкнуть к такому противному ЯП?

    Что ни урок\лекция\сайт по жабе - то с украинским акцентом или лекция записаная на Украине или домен сайта .ua.

    pl7ofit, 18 Июля 2015

    Комментарии (159)
  8. PHP / Говнокод #15770

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if($vOk)
    {
    	if($vOk)
    	{
    	...
    	}
    }

    Дополнительная проверка не повредит.

    any0ne2567, 17 Апреля 2014

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

    +133

    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
    // bormand: Ну что, затестим шейдер в WebGL...
    int iter = 0;
    while (iter < 1000 && length(z) < 2.0) {
        z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
        iter++;
    }
    // compileShader: 'while' : This type of loop is not allowed
    
    // bormand: WTF?! В обычном OpenGL же работало, ну ок...
    int iter = 0;
    for (; iter < 1000; iter++) {
        if (length(z) < 2.0)
            break;
        z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
    }
    // compileShader: 'for' : Missing init declaration
    
    // bormand: Да что за херня!?
    for (iter = 0; iter < 1000; iter++) {
    // compileShader: 'for' : Invalid init declaration
    
    // bormand: Подавись, сука!
    int iters = -1;
    for (int iter = 0; iter < 1000; iter++) {
        if (length(z) < 2.0) {
            iters = iter;
            break;
        }
        z = vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y) + c;
    }
    // compileShader: ok.

    bormand vs WebGL

    bormand, 07 Января 2014

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

    +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
    <?php
    
    
    $cd = dirname($_SERVER['SCRIPT_NAME'])."/resources";
    
    $type=$_GET["type"];
    
    if($type=="emptyhtml")
    {
    	header("Last-Modified: " . gmdate('D, d M Y H:i:s', time()) . 'GMT');
    	header("Expires: " . gmdate('D, d M Y H:i:s', time() + 2592000) . 'GMT');
    	header("Content-Type: text/html");
    	echo("<html><head><title>EMPTY</title></head><body></body></html>");
    	exit(200);
    }
    else if($type=="script")
    {
    	header("Content-Type: application/oct-stream");      //   -< здесь ишибка
    	
    	?>
    	
    	if(!window.CuteWebUI_AjaxUploader_OnPostback)
    	window.CuteWebUI_AjaxUploader_OnPostback=function()
    	{

    Не существует Content-Type: application/oct-stream
    Существует Content-Type: application/octet-stream
    Код работал с ошибкой 10 лет, перестал через директиву безопасности современный браузеров x-content-type-options: nosniff
    Это разработка Cute Editor for PHP https://cutesoft.net/downloads/17/default.aspx
    Гении тоже допускают ошибку...

    increazon, 17 Июля 2019

    Комментарии (158)
  11. PHP / Говнокод #25654

    0

    1. 1
    2. 2
    array_filter($input, $callback);
    array_map($callback, $input);

    OCETuHCKuu_nemyx, 31 Мая 2019

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