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

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

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @hands_by_value.each do |hand|
    	if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
    			@hands_by_value.delete_at(@hands_by_value.index(hand))			
    		end
    	end

    Рукотворный array.uniq! похоже :)

    lnk, 01 Июля 2011

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $search_string = str_replace('"', '', $search_string);
    $search_string = str_replace('+', '%20', $search_string);
    
    //$search_string = preg_replace( '#([[:punct:]])#e', '( isset($punct[\'\1\']) ? $punct[\'\1\'] : \'\')', $search_string );
    $search_string = trim($search_string);
    $search_string = addslashes(stripslashes(htmlspecialchars(strip_tags(rawurldecode($search_string)))));

    Борямся с XSS

    yamaha252, 30 Июня 2011

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php
    //...
    	$fileinattachments = $root_directory.$filepath.$fileid.'_'.$filename;
    	if(!file($fileinattachments)) $fileinattachments = $root_directory.$filepath.$fileid."_".$filename
    //...
    ?>

    Много думал. Код из незабвенной vTiger CRM.

    mr.The, 29 Июня 2011

    Комментарии (4)
  5. JavaScript / Говнокод #7071

    +147

    1. 1
    if(typeof n!="number"&&(k==Number||!(n instanceof Number))||p.round(n)!=n||n==NaN||n==Infinity)return!1;

    yasosiska, 27 Июня 2011

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

    +146

    1. 1
    2. 2
    Я ХОЧУ ПОКАКАТЬ!
    ПОМОГИТЕ МНЕ ПАЖАЛУЙСТА!

    yasosiska, 26 Июня 2011

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

    +137

    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
    rem ID generator
    :idgen
    set nsmb=36
    set idstr=
    for /l %%i in (1,1,8) do call :rsadd
    echo ID=%idstr%
    exit /b
    
    rem Random symbol adding [0-9a-z]
    :rsadd
    set r=%random%
    set /a c=r-r/nsmb*nsmb
    if %c% lss 10 set idstr=%idstr%%c%
    if %c% == 10 set idstr=%idstr%a
    if %c% == 11 set idstr=%idstr%b
    if %c% == 12 set idstr=%idstr%c
    if %c% == 13 set idstr=%idstr%d
    if %c% == 14 set idstr=%idstr%e
    if %c% == 15 set idstr=%idstr%f
    if %c% == 16 set idstr=%idstr%g
    if %c% == 17 set idstr=%idstr%h
    if %c% == 18 set idstr=%idstr%i
    if %c% == 19 set idstr=%idstr%j
    if %c% == 20 set idstr=%idstr%k
    if %c% == 21 set idstr=%idstr%l
    if %c% == 22 set idstr=%idstr%m
    if %c% == 23 set idstr=%idstr%n
    if %c% == 24 set idstr=%idstr%o
    if %c% == 25 set idstr=%idstr%p
    if %c% == 26 set idstr=%idstr%q
    if %c% == 27 set idstr=%idstr%r
    if %c% == 28 set idstr=%idstr%s
    if %c% == 29 set idstr=%idstr%t
    if %c% == 30 set idstr=%idstr%u
    if %c% == 31 set idstr=%idstr%v
    if %c% == 32 set idstr=%idstr%w
    if %c% == 33 set idstr=%idstr%x
    if %c% == 34 set idstr=%idstr%y
    if %c% == 35 set idstr=%idstr%z
    exit /b

    Windows shell

    Собственноручно написанное. Нашел, разбирая старые скрипты.

    vp2729, 25 Июня 2011

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

    +170

    1. 1
    2. 2
    3. 3
    (function(a){ var m
        return (m=a.length)<2 ? a[0] : (m=a[--m],a.length--,(a[a.length-1]>m)&&(a[a.length-1]=m),arguments.callee(a))
    })(this.prop)

    Вроде бы ищет минимум в this.prop.
    P.S. this.prop как массив удаляется. Равен результату.

    Jean-Esther, 24 Июня 2011

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    elseif (array_key_exists(pathinfo($_SERVER['HTTP_HOST'], PATHINFO_EXTENSION), $lang_array)) {
    	   $language = pathinfo($_SERVER['HTTP_HOST'], PATHINFO_EXTENSION);
    	}
    	else
    	   $language = 'en';

    Из того же проекта, где зародился шаблонизатор.
    Минималистичный файл-хостинг, который все решает за хозяина.
    Конфиг - только папка хранения файлов и макс. объем.
    А язык он определяет сам. По доменному имени. Каждый раз при обращении к странице.

    7ion, 23 Июня 2011

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

    +74

    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
    private static java.util.Hashtable<String, Session> sessions =
        new java.util.Hashtable<String, Session>();
    ...
    public static SessionOperations[] getSessions() {
        int cnt = sessions.size();
        SessionOperations[] res = new SessionOperations[cnt];
        java.util.Enumeration<String> e = sessions.keys();
        for( int i = 0; i < res.length; i++ ) {
          String sid = e.nextElement();
          res[i] = sessions.get( sid ).getOperations( sid );
        }
        return res;
    }

    Удаление из sessions между получением размера и набора ключей приводит к весьма печальным последствиям...

    P.S. В результате в течение трех суток в production не удалялись оставленные сессии (без Logout), sessions отожрал 600М и всё свалилось с OOM.

    Skipy, 23 Июня 2011

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

    −111

    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
    NetworkStatus internet = [internetReachable currentReachabilityStatus];
    
    switch (internet)
    {
        case NotReachable:		{ internetStatus = NO;  break; }
        case ReachableViaWiFi:	{ internetStatus = YES; break; }
        case ReachableViaWWAN:	{ internetStatus = YES; break; }
        default: break;
    }
    
    NetworkStatus host = [hostReachable currentReachabilityStatus];
    switch (host)
    {
        case NotReachable:		{ hostStatus = NO;  break; }
        case ReachableViaWiFi:	{ hostStatus = YES; break; }
        case ReachableViaWWAN:	{ hostStatus = YES; break; }
        default: break;
    }
    
    //-------------------------------------------------------------
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 
    	return false; 
    }
    
    //-------------------------------------------------------------
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
    	if (logicRotate == 1)
    	{
    		if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) // если ЛандскейпРайт
    		{
    			FlowCover.transform = CGAffineTransformIdentity;
    			indexLandscape = 1;
    		}
    		if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) // если ЛандскейпЛефт
    		{
    			FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
    			indexLandscape = 0;
    		}
    	}
    	else
    	{
    		if (indexLandscape == 1)
    		{
    			FlowCover.transform = CGAffineTransformIdentity;
    		}
    		else
    		{
    			FlowCover.transform = CGAffineTransformMakeRotation(M_PI);
    		}
    		logicRotate = 1;
    	}
    	return false;
    }
    
    //-------------------------------------------------------------
    
    pagetextLabel.hidden = (pageFullScreen.realPageNo) ? NO : YES;
    
    //-------------------------------------------------------------
    
    [(FastImageView*)page showImage:[listOfImages objectAtIndex:pageIndex]]; //картинка
    
    //-------------------------------------------------------------
    
    if (firstPages>2) {
        ...
        if (theAudio) {
            [theAudio play];	//звук
        }
        firstPages++;
    }
    else
    {
        firstPages++;
    }
    
    //-------------------------------------------------------------
    
    LabPercent.text = [NSString stringWithFormat:@"%d%@", percent * 100, @"%"];
    
    //-------------------------------------------------------------
    
    if ([DELEGATE isIPad]) {
        mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:17.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
    }
    else {
        mTempSize = [tempstr sizeWithFont:[UIFont fontWithName:@"Helvetica" size:12.0f] constrainedToSize:maxSize lineBreakMode:UILineBreakModeTailTruncation];
    }
    h = mTempSize.height;
    if ([DELEGATE isIPad]) {
        lab.font = [UIFont fontWithName:@"Helvetica" size:17.0f];
    }
    else {
        lab.font = [UIFont fontWithName:@"Helvetica" size:12.0f];
    }

    От того же автора http://govnokod.ru/6964. Тут избранные куски, хотя можно постить весь проект

    GLvRzZZ, 17 Июня 2011

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