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

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

    +139.8

    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
    unction int2hex($intega){
       $Ziffer = "0123456789ABCDEF";
    return $Ziffer[($intega%256)/16].$Ziffer[$intega%16];
    }
    
    function url_encode($text){
       $text = urlencode($text);
       if(!strpos($text,"%C3"))
           for($i=129;$i<255;$i++){
               $in = "%".int2hex($i);
               $out = "%C3%".int2hex($i-64);
               $text = str_replace($in,$out,$text);
           }
    return $text;
    }
    
    function tounicode ($string){
    $unistring="";
    for($i=0;$i<strlen($string);$i++){
    	$current=$string[$i];
    	$codcurrent=ord($current);
    	if($codcurrent>255):
           		$unicurrent=utf8_encode($current);
    		$unistring=$unistring.$unicurrent;
    	elseif($codcurrent<192):
    		if($codcurrent==184):
                           $unicurrent=chr(209).chr($codcurrent-39);
                           $unistring=$unistring.$unicurrent;
    		elseif($codcurrent==168):
                           $unicurrent=chr(208).chr($codcurrent-39);
                           $unistring=$unistring.$unicurrent;
    		elseif($codcurrent==147):
    				$unicurrent=utf8_encode("\"");
                            $unistring=$unistring.$unicurrent;
    		elseif($codcurrent==148):
    				$unicurrent=utf8_encode("\"");
                            $unistring=$unistring.$unicurrent;
    		elseif($codcurrent==151):
    				$unicurrent=utf8_encode("-");
                            $unistring=$unistring.$unicurrent;
    		
    		else:
                  		$unicurrent=utf8_encode($current);
                   		$unistring=$unistring.$unicurrent;
    		endif;
    	
    	else:
    		if ($codcurrent<240):
    			$unicurrent=chr(208).chr($codcurrent-48);
    			$unistring=$unistring.$unicurrent;
    		else:
    			$unicurrent=chr(209).chr($codcurrent-112);
    			$unistring=$unistring.$unicurrent;
    		endif;
    		
    	endif;
    }
    return $unistring;
    }

    guest, 25 Июня 2009

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

    +139.8

    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
    public enum TimePeriod {
    	
    	NONE,
    	DAILY,
    	WEEKLY,
    	MONTHLY,
    	YEARLY;
    	
    	public static TimePeriod getTimePeriod(String periodStr) {
    		if (null == periodStr) {
    			return null;
    		}
    		if (0 == periodStr.length()) {
    			return NONE;
    		}
    		if (0 == periodStr.compareToIgnoreCase("daily")) {
    			return DAILY;
    		}
    		if (0 == periodStr.compareToIgnoreCase("weekly")) {
    			return WEEKLY;
    		}
    		if (0 == periodStr.compareToIgnoreCase("monthly")) {
    			return MONTHLY;
    		}
    		if (0 == periodStr.compareToIgnoreCase("yearly")) {
    			return YEARLY;
    		}
    		return null;
    	}
    }

    а правильно будет так
    public static TimePeriod parse(String type) {
    return valueOf(type.toUpperCase());
    }

    guest, 20 Февраля 2009

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

    +139.7

    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 getFilename()
    {
        mysql_query('insert into `filenames` (num) values (1)');
        $id = mysql_insert_id();
        mysql_query('delete from `filenames` where id<' . $id);
        $str = date('Y') . '/' . date('m') . '/' . date('d') . '/' . $id . '_' . rand(1000,
            9999);
    
        list($dir1, $dir2, $dir3, $id) = explode('/', $str);
        checkPictureDirs($dir1, $dir2, $dir3);
    
        return $str;
    }

    Может это круто напрягать БД для получения уникального ID для имени файла.

    guest, 24 Марта 2009

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

    +139.6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    var complete = new ManualResetEvent(false);
    
    ThreadPool.QueueUserWorkItem(
    	delegate
    		{
    			service.StartDownloadUpdatesProcess(complete);
    		});
    
    complete.WaitOne();

    Запустим поток, а потом подождем пока он закончиться.

    Mike Chaliy, 04 Октября 2009

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

    +139.6

    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
    class db
    {
    	public function __call($m,$args)
    	{
    		$export = array_map(function($v) { return var_export($v,1);},$args);
    		$str = $m."(".implode(',',$export).");";
    		$str = escapeshellarg($str);
    		$str = "/home/robot/db.class.php {$str};";
    		$answer = `$str`;
    		eval('$res = '.$answer.';');
    		@array_walk_recursive($res,function(&$v) { $v = iconv('cp1251','utf-8',$v); });
    		return $res;
    	}
    }
    
    //сам db.class.php
    
    $db = new db($host,$db,$user,$pass);
    eval('$res = $db->'.$argv[1]);
    var_export($res);

    интерпрайз

    guest, 05 Августа 2009

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

    +139.6

    1. 1
    2. 2
    File pom = new File(dir.getAbsoluteFile()
      + String.valueOf(File.separatorChar) + "pom.xml");

    В классе java.io.File специально для таких умников есть две константы :
    public static final char separatorChar = '\';
    public static final String separator = "" + separatorChar;

    Одна из них - это char, а вторая - String.

    guest, 20 Марта 2009

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

    +139.5

    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
    #include <iostream>
    #include <deque>
    #include <time.h>
    using namespace std;
    int arr[10][10] = {
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    };
    #define SHIPS 1
    struct point{
         int x, y;
    };
    int num = -1, count = 0;
    deque<point> ship;
    int way[] = {0, 0, 0, 0};
    void step(){
    	for (int i = 0; i < 10; i++){
    		for (int j = 0; j < 10; j++)
    			cout << arr[i][j] << ' ' ;
    		cout << '\n';
    	}
    
    	
    	cout << '\n';
    	
         if (num == ship.size()){
    		 memset(way, 0, sizeof(way));
              while(!ship.empty()){
                   arr[ship.front().x + 1][ship.front().y] = 7;
                   arr[ship.front().x + 1][ship.front().y + 1] = 7;
                   arr[ship.front().x][ship.front().y + 1] = 7;
                   arr[ship.front().x + 1][ship.front().y - 1] = 7;
                   arr[ship.front().x - 1][ship.front().y + 1] = 7;
                   arr[ship.front().x - 1][ship.front().y - 1] = 7;
                   arr[ship.front().x][ship.front().y - 1] = 7;
                   arr[ship.front().x - 1][ship.front().y] = 7;
                   ship.pop_front();
              }
              count++;
              if (count == SHIPS) {
                   cout << "Win" << '\n';
                   exit(0);
              }
              cout << num  << " was killed" << '\n'; 
              num = -1;
         }
         int x, y;
         point tmp;
         if (ship.empty()){
              x = rand()%10;
              y = rand()%10;
              while (arr[x][y] == 7){
                   x = rand()%10;
                   y = rand()%10;
              }
              if (arr[x][y] != 0 && arr[x][y] != 7){
                   num = arr[x][y];
                   tmp.x = x;
                   tmp.y = y;
                   ship.push_front(tmp);
                   arr[x][y] = 7;
    			   if (x > 0) if (arr[x][y - 1] != 7) way[0] = 1;
    			   if (y > 0) if (arr[x - 1][y] != 7) way[1] = 1;
    			   if (x < 9) if (arr[x][y + 1] != 7) way[2] = 1;
    			   if (y < 9) if (arr[x + 1][y] != 7) way[3] = 1;
                   step();
              }else{
                   arr[x][y] = 7;
                   return;
              }
         }else{
    		  int t = rand()%4;
    		  while (way[t] == 0){
    			  t = rand()%4;
    		  }
    		  switch(t){
    			  case 0:
    				  x = ship.back().x;
                      y = ship.back().y - 1;
    				  if(arr[x][y] == num){
    					  way[1] = 0;
    					  way[3] = 0;
    					  tmp.x = x;
    					  tmp.y = y;
    					  ship.push_back(tmp);
    					  arr[x][y] = 7;
    					  step();
    				  }else{
    					  arr[x][y] = 7;
    					  way[0] = 0;
    					  return;
    				  }

    Морской бой

    guest, 08 Июля 2009

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

    +139.5

    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
    <?php
    $qw=chr(32);  
    $fp = fsockopen ("udp://77.239.192.43",28960, $errno, $errstr);  
    if (!$fp)  
    {  
    return("Error");  
    }  
    else  
    {  
    fwrite($fp,"яяяяinfo");  
    socket_set_timeout($fp,2,1);  
    $st=fread($fp,1);  
    print_r($st); 
    $r=socket_get_status($fp);  
    $r=$r["unread_bytes"]; 
    @$st.=fread($fp,$r);  
    fclose($fp);  
    $tmp2=strpos($st,"sv_maxclients");  
    $tmp1=strpos($st,"clients")+9;
    $players = 0;  
    $map=SubStr($st,0,StrPos($st,chr(0))); 
    $show_map="<img src=./maps/".$map.".jpg width=\"160\" height=\"120\">"; 
    if (($tmp2-$tmp1) >= 0)  
    {  
      $players=substr($st,$tmp1,$tmp2-$tmp1);  
      $tmp2=strpos($st,"mapname")+8;  
      $map = substr($st,$tmp2,$tmp1-$tmp2-9);  
    
    }  
    }  
    echo "";  
    
    echo (" 
    <b><font color=\"#000000\">Call of Duty2</font></b> 
    <br> 
    <b><font color=\"#000000\">$show_map</font></b> 
    <br> 
    <b><font color=\"#000000\">Игроков: $players</font></b> 
    "); 
    ?>

    говноскрипт мониторенга cod

    guest, 02 Июня 2009

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

    +139.5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <?
    
    // Загрузка всех функций из папки "sys/fnc"
    $opdirbase=opendir(H.'sys/fnc');
    while ($filebase=readdir($opdirbase))
    if (eregi('\.php$',$filebase))
    include_once(H.'sys/fnc/'.$filebase);
    
    ?>

    Вот таким макаром в wap cms "DCMS" грузятся функции. Файл с этим содержанием вставляется на все страницы. Причём в папке sys/func 47 PHP файлов =)

    guest, 24 Апреля 2009

    Комментарии (1)
  11. Си / Говнокод #782

    +139.5

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if(strncmp(I_CUR->E98,"",sizeof("")-1) != 0)
    {
        /** Fehler **/
        ret=create_error(1,1,"",NULL,NULL);
        set_error_msgseg(-1,-1,"CUR",NULL," E98",-1);
        if (ret==FEHLER)
            return ret;
    }

    Генератор сорса для одного проекта в очень крупной конторе дает такой код, который должен сообщать об ошибке.

    Долго я удивлялся, что ошибок не появляется
    if(0 != 0)

    guest, 27 Марта 2009

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