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

    В номинации:
    За время:
  2. Куча / Говнокод #4561

    +138

    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
    function StripLeadingComma(str)
      str = Ltrim(str)
      if len(str) > 0 then
        if Left(str,1) = "," then  str = Mid(str,2)
      end if
      if len(str) > 0 then
        if Left(str,1) = "," then  str = Mid(str,2)
      end if
      if len(str) > 0 then
        if Left(str,1) = "," then  str = Mid(str,2)
      end if
      if len(str) > 0 then
        if Left(str,1) = "," then  str = Mid(str,2)
      end if
      StripLeadingComma = str
    end function
    
    function StripTrailingComma(str)
      str = rtrim(str)
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      if len(str) > 0 then
        if Right(str,1) = "," then  str = Left(str,len(str)-1)
      end if
      StripTrailingComma = str
    end function

    Классика жанра на production. ASP, VBScript.

    Seth, 08 Ноября 2010

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

    +122

    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
    public static bool IsConnectedToInternet
    {
        get
        {
            // сервер для пинга
            Uri url = new Uri("www.google.com"); 
            // его перевод в строку
            string pingurl = string.Format("{0}", url.Host); 
            string host = pingurl;
            // возвращаемое значение
            bool result = false; 
            Ping p = new Ping();
            try
            {
                PingReply reply = p.Send(host, 3000);
                if (reply.Status == IPStatus.Success)
                // если все ок, то вернем true                
                   return true;
            }
            catch { }
            // в этом случае возвращается false
            return result;
        }
    }

    Взято с http://msgeeks.ru/?artid=42 - "Пинг сервера на С#".
    Особенно порадовал перевод url.Host в строку))

    inso, 26 Октября 2010

    Комментарии (7)
  4. Python / Говнокод #4451

    −100

    1. 1
    2. 2
    3. 3
    s = 'blablabla'
    if s[:7] <> 'http://':
       s = 'http://%s' % s

    blednolicui, 26 Октября 2010

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

    +168

    1. 1
    2. 2
    $Y=date('Y'); $m=date('m'); $d=date('d');$G=date('G');$i=date('i');$s=date('s'); 
    $tdate=mktime($G,$i,$s,$m,$d,$Y);

    fork, 26 Октября 2010

    Комментарии (7)
  6. PHP / Говнокод #4445

    +157

    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
    ...
    
    if ($kpp['id_complect'] == '14') {
    $smarty->assign('sost', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '54') {
    $smarty->assign('dvig', $kpp['tit']);
    
    }
    
    if ($kpp['id_complect'] == '17') {
    $smarty->assign('kpp', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '16') {
    $smarty->assign('priv', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '18') {
    $smarty->assign('weel', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '19') {
    $smarty->assign('ras', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '101') {
    $smarty->assign('color', $kpp['tit']);
    
    }
    if ($kpp['id_complect'] == '15') {
    $smarty->assign('torg', $kpp['tit']);
    
    }
    
    if ($kpp['id_complect'] == '96') {
    $smarty->assign('ls', $kpp['tit']);
    
    }
    
    if ($kpp['id_complect'] == '100') {
    $smarty->assign('vin', $kpp['tit']);
    
    }
    
    
    ...

    и так ооочень много...
    гениальный прогер наверно писал.

    yezhoff, 25 Октября 2010

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

    +117

    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
    public ActionResult Register(RegisterInformation ri, string myCaptcha, HttpPostedFileBase image)
    {
        if (ri.Name == null) ModelState.AddModelError("my", "Введите имя");
        if (ri.Name != null && ri.Name.Length > 32) ModelState.AddModelError("my", "Слишком длинное имя, максимум 32 символа");
        if (ri.Password == null) ModelState.AddModelError("my", "Введите пароль");
        if (ri.Password != null && ri.Password.Length > 32) ModelState.AddModelError("my", "Слишком длинный пароль, максимум 32 символа");
        if (ri.Email == null) ModelState.AddModelError("my", "Введите адрес почты");
        if (ri.Email != null && ri.Email.Length > 32) ModelState.AddModelError("my", "Слишком длинная почта, максимум 32 символа");
        if (ri.Phone == null) ModelState.AddModelError("my", "Введите телефон");
        if (ri.Captcha == null) ModelState.AddModelError("my", "Введите символы с картинки");
        if (ri.Email != null && !IsValid.Mail(ri.Email)) ModelState.AddModelError("my", "Невалидный email");
        long phone;
        if (!long.TryParse(ri.Phone, out phone)) ModelState.AddModelError("my", "Некорректный формат телефона");
        if (ri.Captcha != null&&!CaptchaHelper.VerifyAndExpireSolution(HttpContext, myCaptcha, ri.Captcha)) ModelState.AddModelError("my", "Неверно введены символы с картинки");
    
        if (ModelState.IsValid)
        {
            ...
    }

    Проверяем модель на ошибки

    HIMen, 23 Октября 2010

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

    +165

    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
    //FIXME: В этот код лучше не смотреть. Он крайне еретический, но работает. На досуге переписать по-человечески
    
    $_1_2[1]="одна ";
    $_1_2[2]="две ";
    $GLOBALS['_1_2'] = $_1_2;
    
    $_1_19[1]="один ";
    $_1_19[2]="два ";
    $_1_19[3]="три ";
    $_1_19[4]="четыре ";
    $_1_19[5]="пять ";
    $_1_19[6]="шесть ";
    $_1_19[7]="семь ";
    $_1_19[8]="восемь ";
    $_1_19[9]="девять ";
    $_1_19[10]="десять ";
    
    $_1_19[11]="одиннацать ";
    $_1_19[12]="двенадцать ";
    $_1_19[13]="тринадцать ";
    $_1_19[14]="четырнадцать ";
    $_1_19[15]="пятнадцать ";
    $_1_19[16]="шестнадцать ";
    $_1_19[17]="семнадцать ";
    $_1_19[18]="восемнадцать ";
    $_1_19[19]="девятнадцать ";
    $GLOBALS['_1_19'] = $_1_19;
    
    $des[2]="двадцать ";
    $des[3]="тридцать ";
    $des[4]="сорок ";
    $des[5]="пятьдесят ";
    $des[6]="шестьдесят ";
    $des[7]="семьдесят ";
    $des[8]="восемдесят ";
    $des[9]="девяносто ";
    $GLOBALS['des'] = $des;
    
    $hang[1]="сто ";
    $hang[2]="двести ";
    $hang[3]="триста ";
    $hang[4]="четыреста ";
    $hang[5]="пятьсот ";
    $hang[6]="шестьсот ";
    $hang[7]="семьсот ";
    $hang[8]="восемьсот ";
    $hang[9]="девятьсот ";
    $GLOBALS['hang'] = $hang;
    
    $namerub[1]="рубль ";
    $namerub[2]="рубля ";
    $namerub[3]="рублей ";
    $GLOBALS['namerub'] = $namerub;
    
    $nametho[1]="тысяча ";
    $nametho[2]="тысячи ";
    $nametho[3]="тысяч ";
    $GLOBALS['nametho'] = $nametho;
    
    $namemil[1]="миллион ";
    $namemil[2]="миллиона ";
    $namemil[3]="миллионов ";
    $GLOBALS['namemil'] = $namemil;
    
    $namemrd[1]="миллиард ";
    $namemrd[2]="миллиарда ";
    $namemrd[3]="миллиардов ";
    $GLOBALS['namemrd'] = $namemrd;
    
    $kopeek[1]="копейка ";
    $kopeek[2]="копейки ";
    $kopeek[3]="копеек ";
    $GLOBALS['kopeek'] = $kopeek;
    
    
    function semantic($i,&$words,&$fem,$f){
        $_1_2 = $GLOBALS['_1_2'];
    	$_1_19 = $GLOBALS['_1_19'];
    	$des = $GLOBALS['des'];
    	$hang = $GLOBALS['hang'];
    	$namerub = $GLOBALS['namerub'];
    	$nametho = $GLOBALS['nametho'];
    	$namemil = $GLOBALS['namemil'];
    	$namemrd = $GLOBALS['namemrd'];
        $words="";
        $fl=0;
        if($i >= 100){
            $jkl = intval($i / 100);
            $words.=$hang[$jkl];
            $i%=100;
        }
        if($i >= 20){
            $jkl = intval($i / 10);
            $words.=$des[$jkl];
            $i%=10;
            $fl=1;
        }
        switch($i){
            case 1: $fem=1; break;

    Нашел в коде нашего интернет проекта

    madiedinro, 22 Октября 2010

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function getAttrValue(element){
        if(element == undefined){
            return '';
        }
        return  element;
    }

    KiMindfreak, 19 Октября 2010

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

    +75

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    StringUtils.join(
                    Collections2.transform(Arrays.asList(ArrayUtils.toObject(data)),
                            new Function<Byte, String>() {
    
                                @Override
                                public String apply(final Byte from) {
                                    return "0x" + Integer.toHexString(from);
                                }
                            }), " ")

    data имеет тип byte[]

    в питоне это было бы ' '.join(map(hex, data))

    burdakovd, 18 Октября 2010

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

    +159

    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
    function randomPassword($length = 8, $seed = '') {
    	$password = "";
    	$possible = "0123456789";
    	$i = 0;
    	mt_srand(($seed == '') ? rand() : $seed);
    	while ($i < $length) {
    		$char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
    		if (!strstr($password, $char)) {
    			$password .= $char;
    			$i++;
    		}
    	}
    	return $password;
    }

    думаю пора создавать отдельный радел на сайте посвящённый высерам призванным генерировать пароли

    DrFreez, 18 Октября 2010

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