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

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

    +42

    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
    foreach ($balancedSlots as $cluster) {
                    if ($cluster['type']=='cluster'){
                            foreach ($cluster['servers'] as $ip=>$server) {
                                    if ($GLOBALS['mode']!='test'){
                                            $GLOBALS['dataVar'][$i] = array();
                                            if (isset($server['snmp_server'])){
                                                    $p = preg_split('/,/', $server['snmp_server']);
                                                    $GLOBALS['dataVar'][$i]['proc_handle'] = popen(dirname(__FILE__).'/snmp_server.sh '.$p[0].' '.$p[1], 'r');
                                                    $GLOBALS['dataVar'][$i]['snmp_params'] = $p;
                                                    $GLOBALS['dataVar'][$i]['snmp_result'] = array('ifName'=>array(), 'counter'=>array());
                                            }
                                            else {
                                                    //print "proc_handle: ".$server['snmp_cmd']."\n";
                                                    $GLOBALS['dataVar'][$i]['proc_handle'] = popen($server['snmp_cmd'], 'r');
                                            }
                                            $GLOBALS['dataVar'][$i]['server']=$server;
                                            $GLOBALS['dataVar'][$i]['server']['ip']=$ip;
                                            $GLOBALS['dataVar'][$i]['eb'] = event_buffer_new($GLOBALS['dataVar'][$i]['proc_handle'], "read_result", NULL, "error_func", $i);
                                            event_buffer_timeout_set($GLOBALS['dataVar'][$i]['eb'], 4, 60);
                                            event_buffer_base_set($GLOBALS['dataVar'][$i]['eb'], $GLOBALS['base']);
                                            event_buffer_enable($GLOBALS['dataVar'][$i]['eb'], EV_READ);
                                    }
                                    elseif ($GLOBALS['mode']=='test')
                                    {
                                            if (!array_key_exists($ip, $testLastServers)) {
                                                    $testLastServers[$ip]=0;
                                            }
                                            if ($testServersData[$ip][$testServersIteration]!==false){
                                                    $GLOBALS['result'][$ip] = new ArrayObject(array('counter64'=>$testLastServers[$ip]+$testServersData[$ip][$testServersIteration], 'ts'=>$GLOBALS['mesure_time']));
                                                    $testLastServers[$ip] = $GLOBALS['result'][$ip]['counter64'];
                                            }
                                    }
                                    $i++;
                            }
                    }
            }

    Попытка одного товарища использовать библиотеку libevent. Видно щедрое использование глобальных переменных.

    Bdfy, 31 Июля 2012

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

    +41

    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
    catch(...)
    {	
    	static int j = 0;
    
    	//if we enter this catch clause more than 1 time
    	//it is very likely that the RestartSystem() command
    	//did not succeed. If this is the case we just exit.
    	if(j>0)
    		exit(0);
    	else
    		SWFMonitorT::GetInstance()->RestartSystem();
    	j++;
    	throw;
    }

    Приключения в мире байтоёбиков...

    blackhearted, 16 Июля 2014

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

    +41

    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
    for (std::vector<SomeClass::SmartPtr>::iterator i = candidates.begin ();
               i != candidates.end (); )
          {
             if ((*i)->getArea ().intersect (thisArea))
             {
                // label is inside the area.
                ++i;
             }
             else
             {
                // label must be removed
                std::iter_swap (i, candidates.end () - 1);
                candidates.pop_back ();
             }
          }

    Не совсем ясны были мотивы человека, написавшего это. Этот код вообще не работает и не сразу и поймешь что тут к чему.

    bes, 21 Февраля 2014

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

    +41

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public static function getById( $id )
    {
      $model = new self;
      $data  = $model->load();
      foreach( $data AS $item ){
        if( $item->id == $id ){
          return $item;
        }
      }
      return null;
    }

    Нашел в текущем проекте.

    grdExh, 28 Января 2013

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

    +41

    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
    # POST /register
    Public Function Register(){
        foreach((array)$_POST as $k=>$v)
            $_POST[$k] = addslashes(strip_tags($v));
        $login = $_POST['Login'];
        $password = $_POST['Password'];
        $email = $_POST['Email'];
        $firstname = $_POST['FirstName'];
        $lastname = $_POST['LastName'];
        $errors = array();
    
        IF(!Session::Restore()){
            Driver::Init();
            IF(String::is_valid_email_address($email)){
                IF(strlen($login) > 3 && strlen($login) <= 12 && String::Check('([a-zA-Z0-9_]+)', $login) ){
                    IF(strlen($password) > 5 && $password == $_POST['RePassword']){
                        $users = Collection::Get('users')->Select(Query::Equal('login', $login));
                        IF(!sizeof($users)){
                            $user = new User;
                            $user->login = strtolower($login);
                            $user->password = md5($password);
                            $user->regtime = time();
                            $photo = UploadedFiles::Get('Photo');
                            IF($photo)
                                IF($photo->exists){
                                    $photoHash = md5('photo_'.$user->login);
                                    $photosPath = APPLICATION_DIR.'/assets/uploads/photos';
                                    $photo->Path = $photosPath.'/tmp/'.$photoHash;
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/300/'.$photoHash.'.jpg', 100, 300, 500);
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/100/'.$photoHash.'.jpg', 100, 100);
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/50/'.$photoHash.'.jpg', 100, 50);
                                    @unlink($photo->Path);
                                    $user->photo = $photoHash;
                                }
                            $user->save();
                            Session::Link($login, $password);
                            return Router::Redirect('/profile');
                        }
                        else $errors[] = l('This username is already taken');
                    }
                    else $errors[] = l('Password length must be more than 3');
                }
                else $errors[] = l('Login length must be more than 3, and less than 13 characters and contain only Latin characters');
            }
            else $errors[] = l('Your email address must be in the format of [email protected]');
        }
        else $errors[] = l("You are already registered");
        $view = new View('main.php');
        return $view->Set('Content', 'registration.php')->Set('login', $login)->Set('email', $email)->Set('firstname', $firstname)->Set('lastname', $lastname)->Set('errors', $errors);
    }

    Ну так.

    d3n4, 14 Декабря 2012

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

    +41

    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
    ....
    <table border="0" cellspacing="0" cellpadding="1">
    	<tr>
    		<td width="45%" valign="top">
    			<?if($arResult["AUTH"]["new_user_registration"]=="Y"):?>
    				<b><?echo GetMessage("STOF_2REG")?></b>
    			<?endif;?>
    		</td>
    		<td width="10%"> </td>
    		<td width="45%" valign="top">
    			<?if($arResult["AUTH"]["new_user_registration"]=="Y"):?>
    				<b><?echo GetMessage("STOF_2NEW")?></b>
    			<?endif;?>
    		</td>
    	</tr>
    	<tr>
    ....

    наткнулся в Битриксе, в шаблоне стандартного компонента sale.order.full
    Видимо не судьба одной проверкой <?if($arResult["AUTH"]["new_user_registration"]=="Y"):?> исключить всю строку <tr>...</tr>

    Freewww, 07 Ноября 2012

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

    +41

    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
    int sheeps(int pole[10][10])
    {
        int i,j,f,k,r;
        int rand_chislo, rand_chislo1, ts,s; 
      
          srand(time(NULL));      
         for (i=0;i<10;i++)   
          for (j=0;j<10;j++)
          pole [i][j]=0;  
         do{ f=0;                                
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;        
            ts = 1+rand()%4;        
              if (ts==1) {for(i=0;i<3;i++) if(rand_chislo==i)f=1;}
             if (ts==2)  {for(i=7;i<10;i++) if(rand_chislo==i)f=1;}                          
              if (ts==3) {for(i=0;i<3;i++) if(rand_chislo1==i)f=1;}
             if (ts==4)  {for(i=7;i<10;i++) if(rand_chislo1==i)f=1;}       
            }
           while (f==1);
            switch (ts){
              case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1;
                      pole[rand_chislo-2][rand_chislo1]=1;pole[rand_chislo-3][rand_chislo1]=1; break;
               case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1; 
                       pole[rand_chislo+2][rand_chislo1]=1;pole[rand_chislo+3][rand_chislo1]=1; break;
             case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;
                     pole[rand_chislo][rand_chislo1-2]=1;pole[rand_chislo][rand_chislo1-3]=1;break;
              case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1;
                      pole[rand_chislo][rand_chislo1+2]=1;pole[rand_chislo][rand_chislo1+3]=1; break; }
         
        for (k=0;k<3;k++)                                      
         {
           do{ f=0;
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;       
            ts = 1+rand()%4;       
              if (ts==1)  {if(rand_chislo!=0){ for (i=rand_chislo-2;i<rand_chislo+2;i++)
                                          for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
                                            {if (pole[i][j]!=0){f=1;}}}else f=1; }
             if (ts==2)  {if (rand_chislo!=9)  {  for (i=rand_chislo-1;i<=rand_chislo+2;i++)
                                              for (j=rand_chislo1-1;j<=rand_chislo1+1;j++)
                                              { if (pole[i][j]!=0){ f=1;}}}else f=1;  }                            
              if (ts==3) { if (rand_chislo1!=0) {   for (i=rand_chislo-1;i<=rand_chislo+1;i++)
                                                for (j=rand_chislo1-2;j<=rand_chislo1+1;j++)
                                                { if (pole[i][j]!=0){ f=1;}}}else f=1;  } 
             if (ts==4) { if (rand_chislo1!=9) {   for (i=rand_chislo-1;i<=rand_chislo+1;i++)
                                                for (j=rand_chislo1-1;j<=rand_chislo1+2;j++)
                                                { if (pole[i][j]!=0){ f=1;}}} 
                                                else f=1;   }                                  
            }
           while (f==1);
            switch (ts){
              case 1: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo-1][rand_chislo1]=1; break;
              case 2: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo+1][rand_chislo1]=1; break;
              case 3: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1-1]=1;break;
              case 4: pole[rand_chislo][rand_chislo1]=1; pole[rand_chislo][rand_chislo1+1]=1; break; }  
         }    
         for (k=0;k<2;k++)                                  
         {
           do{ f=0;
            rand_chislo = 0 + rand() %10;
            rand_chislo1= 0 + rand() %10;
          
     /*зесь еще 2 таких же while (if==1) и for k<3 и k<4 */
    
    return pole[10][10];
    }

    курсовик первокурсника "морской бой". функция расстановки кораблей

    equilibrium, 17 Сентября 2012

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

    +41

    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
    function sqldate2time($date) {
        list($y, $m, $d) = explode('-', $date);
        $res = mktime(3,0,0,$m,$d,$y);
        return($res);
    }//function
     
    //Добавляем к дате указанное кол-во дней
    function add_days($date, $days = 1) {
        $t = sqldate2time($date);
        $t += (86400*$days);
     
        return(date('Y-m-d', $t));
    }//function

    Попытка на каком-то форуме, прибавить интервал времени (к примеру 7 дней)

    nepster, 14 Сентября 2012

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

    +41

    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
    <?php
    ini_set('display_errors','On');
    error_reporting('E_ALL');
    mysql_connect("localhost","MySQL","satanus") or die(mysql_error());
    echo "Connected to mysql<br>";
    mysql_select_db("myurl") or die(mysql_error());
    echo "Connected to Database";
    $ms=mysql_info();
    echo $ms;
    
    function isValidURL($url)
    {
    return preg_match('|^(http)(s)?://([a-z0-9-]+\.[a-z-]+)?(localhost)?(\.[a-z0-9-_/&+?=%]+)*(:[0-9]+)?(/[^.]+)?$|i', $url);
    }
    function parse_secure($arg){
      $txt=preg_replace('/((<[^>]*>(.*)<\/[^>]*>|\'|")|(<[^>]*>)|(?:(\s+|>|<|\d+)(?:SELECT|FROM|UNION|ORDER BY|GROUP BY|UPDATE|DELETE|INSERT|OR|AND|NOT)(\s+|>|<|\d+))|<)/i','',$arg);
      return $txt;
    }
    
    if(isset($_GET['pid'])){
        $pid=$_GET['pid'];
        $pid=parse_secure($pid);
        $options=array('options'=>array('min_range'=>0,'max_range'=>1000001));
          if(filter_var($pid,FILTER_VALIDATE_INT,$options)){
            printf("pid correct %d",$pid);
        } else {
            printf("pid incorrect");exit(2);  
        }
        $query="SELECT url FROM myurl.base WHERE id='$pid'";
        $res=mysql_query($query);
        if($res){
          $row=mysql_fetch_assoc($res);
          header('Location: '.$row['url']);
        }
    };
    
    if(isset($_GET['cat']) && isset($_GET['scat'])){
      $cat=$_GET['cat'];
      $cat=parse_secure($cat);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
        $ps=parse_secure($ps);
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.subcategory=\"".$_GET['scat']."\" AND bs.category=\"".parse_secure($_GET['cat'])."\"";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a> ".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    exit(3);
    };
    
    if(isset($_GET['cat'])){
      $cat=parse_secure($_GET['cat']);
      $scat=parse_secure($_GET['scat']);
      if(isset($_GET['ps'])){
        $ps = $_GET['ps'];
      } else {
      $ps =0;
      };
      $catl=iconv_strlen($thm);
      echo "<html><head><title>Short url generator</title></head><body>";
      echo "<h1>$cat</h1><br>";
          $qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.category=\"".$cat."\" OR ( bs.subcategory=\"".$scat."\" AND bs.category=\"".$cat."\")";
          $res=mysql_query($qry);
          if($res){
            while($row=mysql_fetch_assoc($res)){
              echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a>".$row['url'];
              echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
              echo "<br>";
            }
          }
    };
    
    if(isset($_POST['url']) && (isset($_POST['category']) || isset($_POST['cat'])) && (isset($_POST['subcat']) || isset($_POST['scat']))){
      $url=$_POST['url'];
    $purl=substr($url,0,26);
      if($purl=="http://".$_SERVER['SERVER_NAME']."/")exit(0);
    $purl=substr($url,0,30);
      if($purl=="http://www.".$_SERVER['SERVER_NAME']."/")exit(0);
      $cat=parse_secure($_POST['category']);
      $catid=parse_secure($_POST['cat']);
      $scat=parse_secure($_POST['subcat']);
      $scatid=parse_secure($_POST['scat']);
      if($url) {
          if(!isValidURL($url))
    {
    $errMsg .= "* Please enter valid URL including http://<br>";

    AliceGoth, 21 Июня 2012

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

    +40.6

    1. 1
    2. 2
    Application was halted by an exception.
    Debug-mode is off.

    Ошибка на govnokod.ru при добавлении комментариев

    guest, 08 Декабря 2008

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