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

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

    −102

    1. 1
    instanceId = Math.random().toString().split(".")[1];

    Способ получения строки произвольной длины из случайного набора чисел :)

    wvxvw, 20 Февраля 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class ForDemo {
      public static void main(String args[]) {
        long C;
    	
    	for(C = 0; C < 9999999; C++)
    	System.out.println("This is count: " + C);
    	System.out.println("Done!");
    	}
    }

    Говнокод убивающий командную строку =),
    Применять только по необходимости(!)
    Так же можно проследить между строк упоминание о C++

    Akira, 17 Февраля 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public function search() {
        $ret = array();
        foreach($this->dir() as $file)
            if($file->folder())
                $ret = array_merge($ret,$file->search()->asArray());
            else
                $ret[] = $file;
        return new mod_file_list($ret);
    }

    Красота, в результате работы функции мы получаем объект, состоящий из массива объектов класса file (этот метод в этом классе)... "чудо-поиска" (хотя это вовсе и не поиск, а банальный список файлов всех дочерних папок), особенно будет забавно, если в списке будет несколько тысяч файлов...
    В этом классе в принципе много мест, которые наровят насоздавать кучу экземпляров этого же класса, вместо замены одной приватной переменной...

    GhOsTMZ, 15 Февраля 2011

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

    +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
    <?php
    	if($showCapcha != 'showCapcha_0') {
    		echo 'Решите пример: ';
    		$secretCode_1 = rand(1 , 9);
    		$secretCode_2 = rand(1 , 9);
    		$secretCode = $secretCode_1 + $secretCode_2;
    		echo "<strong>" . $secretCode_1 . "</strong> + <strong>" . $secretCode_2 . "</strong> = ";
    		echo '
    			<input id="button_form_contact" type="text" name="secretCode" value="" />
    			<input type="hidden" name="secretCodeHide" value="'.$secretCode.'" />
    		';
    	}
    ?>
    <input id="button_form_contact" type="submit" value=" <?php echo MOD_CON_AM_GO_GO__; ?> ">

    Всё хватит придумывать капчи! Всё уже придумано xDDDD

    nethak, 11 Февраля 2011

    Комментарии (8)
  6. Pascal / Говнокод #5639

    +96

    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
    procedure tnew.execute;
    var
    cod:utf8string;
    id:byte;
    
    captcha,sim,idc:string;
    ss:TStringStream;
    s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,
    s11,s12,s13,s14,s15,s16,s17,s18,
    s19,s20,s21,s22,s23,s24,s25,s26,
    s27,s28,s29,s30,s31,s32,s33:utf8string;
    FS:TFileStream;
    Antigate: TAntigate;
    begin
    form3.IdHTTP1.Request.Referer :='http://www.aboutlive.ru/phpBB2/profile.php?mode=register';
    
    cod:=form3.IdHTTP1.get('http://www.aboutlive.ru/phpBB2/profile.php?mode=register&agreed=true');
    
    function Pars (T_, ForS, _T: string): string;
    var
    a, b: integer;
    begin
    Result := '';
    if (T_ = '') or (ForS = '') or (_T = '') then
    Exit;
    a := Pos (T_, ForS);
    if a = 0 then
    Exit
    else
    a := a + Length (T_);
    ForS := Copy (ForS, a, Length (ForS) - a + 1);
    b := Pos (_T, ForS);
    if b > 0 then
    Result := Copy (ForS, 1, b - 1);
    end;
    
    
    idc:= pars('confirm_id" value="',cod,'" />');
    sim:= pars('sid" value="',cod,'" />');
    
    FS:=TFileStream.Create('captcha.png',FMCreate);
    form3.IdHTTP1.Get('http://www.aboutlive.ru/phpBB2/profile.php?mode=confirm&id='+idc, FS);
    FS.free;
    form3.Image1.Picture.LoadFromFile('captcha.png');
    
    Antigate := TAntigate.Create; // это разгадка капчи
    antigate.Calc:=1;
    antigate.MaxRetry:=3;
    Antigate.Key := '';
    Antigate.ImageFile := 'captcha.png';
    captcha:=Antigate.Recognize;
    Antigate.free;
    
    form3.RichEdit1.Lines.Add('Капча: '+AnsiUpperCase(captcha));
    
    form3.IdHTTP1.Request.Referer :='http://www.aboutlive.ru/phpBB2/profile.php?mode=register&agreed=true';
    ss := TStringStream.Create;
    
    s1:='username=sadsaddfsa12342';
    s2:='[email protected]';
    s3:='new_pasword=1234567';
    s4:='pasword_confirm=1234567';
    s5:='confirm_code='+captcha;
    s6:='icq=';
    s7:='aim=';
    s8:='msn=';
    s9:='yim=';
    s10:='website=';
    s11:='location=';
    s12:='occupation=';
    s13:='interests=';
    s14:='signature=';
    s15:='viewemail=0';
    s16:='hideonline=0';
    s17:='notifyreply=0';
    s18:='notifypm=1';
    s19:='popup_pm=1';
    s20:='attachsig=1';
    s21:='allowbbcode=1';
    s22:='allowhtml=1';
    s23:='allowsmilies=1';
    s24:='language=russian';
    s25:='style=1';
    s26:='timezone=4';
    s27:='dateformat=D M d, Y g:i a';
    s28:='mode=register';
    s29:='agreed=true';
    s30:='coppa=0';
    s31:='sid='+sim;
    s32:='confirm_id='+idc;
    s33:='submit=Отправить';
    ss.WriteString (s1+'&'+s2+'&'+s3+'&'+s4+'&'+s5+'&'+s6+'&'+s7+'&'+s8+'&'+s9+'&'+s10+'&'+s11+'&'+s12+'&'+s13+'&'+s14+'&'+s15+'&'+s16+'&'+s17+'&'+s18+'&'+s19+'&'+s20+'&'+s21+'&'+s22+'&'+s23+'&'+s24+'&'+s25+'&'+s26+'&'+s27+'&'+s28+'&'+s29+'&'+s30+'&'+s31+'&'+s32+'&'+s33);

    Что уж тут напишешь....

    Irdis, 11 Февраля 2011

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

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # Преоброзование расширения в MIME тип
    function replace_type_in_mime($type) {
    	$type = strtolower($type);
    	$res = array("323" => "text/h323", "acx" => "application/internet-property-stream", "ai" => "application/postscript", "aif" => "audio/x-aiff", "aifc" => "audio/x-aiff", "aiff" => "audio/x-aiff", "asf" => "video/x-ms-asf", "asr" => "video/x-ms-asf", "asx" => "video/x-ms-asf", "au" => "audio/basic", "avi" => "video/x-msvideo", "axs" => "application/olescript", "bas" => "text/plain", "bcpio" => "application/x-bcpio", "bin" => "application/octet-stream", "bmp" => "image/bmp", "c" => "text/plain", "cat" => "application/vnd.ms-pkiseccat", "cdf" => "application/x-cdf", "cer" => "application/x-x509-ca-cert", "class" => "application/octet-stream", "clp" => "application/x-msclip", "cmx" => "image/x-cmx", "cod" => "image/cis-cod", "cpio" => "application/x-cpio", "crd" => "application/x-mscardfile", "crl" => "application/pkix-crl", "crt" => "application/x-x509-ca-cert", "csh" => "application/x-csh", "css" => "text/css", "dcr" => "application/x-director", "der" => "application/x-x509-ca-cert", "dir" => "application/x-director", "dll" => "application/x-msdownload", "dms" => "application/octet-stream", "doc" => "application/msword", "dot" => "application/msword", "dvi" => "application/x-dvi", "dxr" => "application/x-director", "eps" => "application/postscript", "etx" => "text/x-setext", "evy" => "application/envoy", "exe" => "application/octet-stream", "fif" => "application/fractals", "flr" => "x-world/x-vrml", "gif" => "image/gif", "gtar" => "application/x-gtar", "gz" => "application/x-gzip", "h" => "text/plain", "hdf" => "application/x-hdf", "hlp" => "application/winhlp", "hqx" => "application/mac-binhex40", "hta" => "application/hta", "htc" => "text/x-component", "htm" => "text/html", "html" => "text/html", "htt" => "text/webviewhtml", "ico" => "image/x-icon", "ief" => "image/ief", "iii" => "application/x-iphone", "ins" => "application/x-internet-signup", "isp" => "application/x-internet-signup", "jfif" => "image/pipeg", "jpe" => "image/jpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "js" => "application/x-javascript", "latex" => "application/x-latex", "lha" => "application/octet-stream", "lsf" => "video/x-la-asf", "lsx" => "video/x-la-asf", "lzh" => "application/octet-stream", "m13" => "application/x-msmediaview", "m14" => "application/x-msmediaview", "m3u" => "audio/x-mpegurl", "man" => "application/x-troff-man", "mdb" => "application/x-msaccess", "me" => "application/x-troff-me", "mht" => "message/rfc822", "mhtml" => "message/rfc822", "mid" => "audio/mid", "mny" => "application/x-msmoney", "mov" => "video/quicktime", "movie" => "video/x-sgi-movie", "mp2" => "video/mpeg", "mp3" => "audio/mpeg", "mpa" => "video/mpeg", "mpe" => "video/mpeg", "mpeg" => "video/mpeg", "mpg" => "video/mpeg", "mpp" => "application/vnd.ms-project", "mpv2" => "video/mpeg", "ms" => "application/x-troff-ms", "mvb" => "application/x-msmediaview", "nws" => "message/rfc822", "oda" => "application/oda", "p10" => "application/pkcs10", "p12" => "application/x-pkcs12", "p7b" => "application/x-pkcs7-certificates", "p7c" => "application/x-pkcs7-mime", "p7m" => "application/x-pkcs7-mime", "p7r" => "application/x-pkcs7-certreqresp", "p7s" => "application/x-pkcs7-signature", "pbm" => "image/x-portable-bitmap", "pdf" => "application/pdf", "pfx" => "application/x-pkcs12", "pgm" => "image/x-portable-graymap", "pko" => "application/ynd.ms-pkipko", "pma" => "application/x-perfmon", "pmc" => "application/x-perfmon", "pml" => "application/x-perfmon", "pmr" => "application/x-perfmon", "pmw" => "application/x-perfmon", "pnm" => "image/x-portable-anymap");
    	if($ret == null) {
    		$ret = "application/x-unknown-content-type";
    	} else {
    		$ret = $res[$type];
    	}
    	return $ret;
    }

    Не знаю смешно ли это или нет, но разобраться в одной километровой строке будет ооочень интересно))))
    Я вас огорчу, пришлось урезать на несколько тысяч символов эту дистанцию))

    nethak, 11 Февраля 2011

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

    +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
    function getAvailablePrivileges(Workset_Model_Object_Interface $resource, $where = null, $order = null, $limit = null, $offset = null, $offsetByPage = false) {
    
            if (true == $offsetByPage) {
                $offset = $this->getPageOffset($limit, $offset);
            }
    
    	$table = $this->_getTable();
    	$select = $table->prepareSelect($where, $order, $limit, $offset);
    
            $iselect = $this->_getTable()->select();
    
            $iselect->from(
                array('m' => $this->_getTable()->info(Zend_Db_Table_Abstract::NAME)),
                array('id')
            )
           ->join(
                array('i' => $this->_getTable($this->_linkedObjectTableClass)->info(Zend_Db_Table_Abstract::NAME)),
                "i.privilege_id = m.id",
                array()
            )
            ->where(
                'i.resource_id = ?', $resource->getId()
            );
    
            $select->where("id not in(?)", new Zend_Db_Expr($iselect->assemble()));
    
            $rowset = $table->fetchAll($select);
    
            return $this->getIterator($rowset, array(
                'countRows' => $this->_countAllRecords,
                'filter' => $select
            ));
    
        }

    Из проекта на Zend

    govnomes, 11 Февраля 2011

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?php if ( $row->type ){ ?>
    <?php if ( $row->type==1 ){ ?><?php echo _EZREALTY_TYPE_SALE;?><?php } ?>
    <?php if ( $row->type==2 ){ ?><?php echo _EZREALTY_TYPE_RENTAL;?><?php } ?>
    <?php if ( $row->type==3 ){ ?><?php echo _EZREALTY_TYPE_LEASE;?><?php } ?>
    <?php if ( $row->type==4 ){ ?><?php echo _EZREALTY_TYPE_AUCTION;?><?php } ?>
    <?php if ( $row->type==5 ){ ?><?php echo _EZREALTY_TYPE_SWAP;?><?php } ?>
    <?php if ( $row->type==6 ){ ?><?php echo _EZREALTY_TYPE_TENDER;?><?php } ?>
    <?php } ?>

    Компонент joomla ezrealty)

    antongorodezkiy, 10 Февраля 2011

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

    +162

    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
    //...
    	CString signature(pMsg->clipEvent.signature);
    	int indx = signature.Find('-');
    	if(!indx)
    		signature.Delete(indx);
    	indx = signature.Find('-');
    	pEvent->eventData.signature.doorNum = _ttoi(signature.Left(indx));
    	signature.Delete(0, indx+1);
    	indx = signature.Find('-');
    	pEvent->eventData.signature.eventType = _ttoi(signature.Left(indx));
    	signature.Delete(0, indx+1);
    	indx = signature.Find('-');
    	pEvent->eventData.signature.eventID = _ttoi(signature.Left(indx));	
    	signature.Delete(0, indx+1);
    	indx = signature.Find('-');
    	pEvent->eventData.signature.itemNumber = _ttoi(signature.Left(indx));	
    	signature.Delete(0, indx+1);
    	indx = signature.Find('-');
    	CString dateTimeStr;
    	dateTimeStr	= signature.Mid(5, 2);
    	dateTimeStr += '/';
    	dateTimeStr += signature.Mid(8, 2);
    	dateTimeStr += '/';
    	dateTimeStr += signature.Left(4);
    	dateTimeStr += ' ';
    	dateTimeStr += signature.Mid(11, 2);
    	dateTimeStr += ':';
    	dateTimeStr += signature.Mid(14, 2);
    	dateTimeStr += ':';
    	dateTimeStr += signature.Mid(17, 2);
    	pEvent->eventData.signature.eventDateTime = DEM_getTimeDateStampFromTimeDateString(dateTimeStr);
    	signature.Delete(0, 20);
    	pEvent->eventData.signature.cameraIndex = _ttoi(signature);
    //...

    инициализация числовых переменных из строки с заранее известным форматом...
    так как автор "кончал на MFC", с функцией sscanf западло было работать

    ShuraKotov, 09 Февраля 2011

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

    +161

    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
    // Функция для проверки входнях данных и присвоения входных данных переменым
    // $pattern задаёт регулярное выражение
    // $key ключ в массивах $_POST[] или $_GET[]
    // $firts и $second порядок их просмотра
    // $second не обязательный параметр
    // $die_if_not_match задаёт поведение при не соответствии входных данных регулярному выражению
    // $die_if_not_set задаёт поведение при отсутствии входных данных
    // по умолчания при не совпаденини или отсутствии входных данных функция не возвращаяет ничего
    function inchk($pattern, $key, $first, $second = '' ,$die_if_not_match = '0',$die_if_not_set = '0' ){
    	if(!$pattern){
    		die("Шаблон для inchk() не задан");
    	}elseif(!$key){
    		die("Ключ для inchk() не задан");
    	}
    	elseif(!$first){
    		die("Источник данных inchk() не задан");
    	}elseif($first and $second){
    		if($first == "post" or $first == "p"){
    			if($_POST[$key] != ''){
    				if(preg_match($pattern, $_POST[$key])){
    					return $_POST[$key];
    				}else{
    					if($die_if_not_match){ die('недопустимый формат $_POST[\''.$key.'\']'); }
    				}
    			}elseif($_GET[$key] != ''){
    				if(preg_match($pattern, $_GET[$key])){
    					return $_GET[$key];
    				}else{
    					if($die_if_not_match){ die('недопустимый формат $_GET[\''.$key.'\']'); }
    				}
    			}else{
    				if($die_if_not_set){ die('$_POST[\''.$key.'\'] или $_GET[\''.$key.'\'] не задан'); }
    			}
    		}
    		elseif($first == "get" or $first == "g"){
    			if($_GET[$key] != ''){
    				if(preg_match($pattern, $_GET[$key])){
    					return $_GET[$key];
    				}else{
    					if($die_if_not_match){ die('недопустимый формат $_GET[\''.$key.'\']'); }
    				}
    			}elseif($_POST[$key] != ''){
    				if(preg_match($pattern, $_POST[$key])){
    					return $_POST[$key];
    				}else{
    					if($die_if_not_match){ die('недопустимый формат $_POST[\''.$key.'\']'); }
    				}			
    			}else{
    				if($die_if_not_set){ die('$_GET[\''.$key.'\'] или $_POST[\''.$key.'\'] не задан'); }
    			}
    		}else{
    			die("Источник данных inchk() задан не верно");
    		}
    
    	}elseif($first == "get" or $first == "g"){
    		if($_GET[$key] != ''){
    			if(preg_match($pattern, $_GET[$key])){
    				return $_GET[$key];
    			}else{
    				if($die_if_not_match){ die('недопустимый формат $_GET[\''.$key.'\']'); }
    			}
    		}else{
    			if($die_if_not_set){ die('$_GET[\''.$key.'\'] не задан'); }		
    		}
    	}elseif($first == "post" or $first == "p"){
    		if($_POST[$key] != ''){
    			if(preg_match($pattern, $_POST[$key])){
    				return $_POST[$key];
    			}else{
    				if($die_if_not_match){ die('недопустимый формат $_POST[\''.$key.'\']'); }
    			}
    		}else{
    			if($die_if_not_set){ die('$_POST[\''.$key.'\'] не задан'); }		
    		}
    	}elseif($first){
    		die("Источник данных inchk() задан не верно");
    	}else{
    		die("Источник данных inchk() не задан");
    	}
    
    }

    OH, SH*T! Казалось бы, зачем?

    Gogogo, 08 Февраля 2011

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