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

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

    +144

    1. 1
    http://nemolaboratory.ru/blog/about_a_miscellaneous/Nemo-Laboratory-About

    Напишите здесь все свои замечания, буду благодарен

    nemo, 17 Сентября 2010

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (obj == null)
    	return 0;
    if (obj == DBNull.Value)
    	return 0;
    return int.Parse (obj.ToString ());

    в столбце хранится Integer...

    akai_mirror, 17 Сентября 2010

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

    +169

    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
    <?php
    
    $res = "-1";
    if($num>0) {
    	for($d=1;$d<=$num;$d++) {
    		$res.=",".$data[$d-1];
    		
    	}
    	$res=substr($res,3,100000);
    	$res=str_replace(",",", ", $res);
    }
    
    ?>

    ferry-very-good, 13 Сентября 2010

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

    +165

    1. 1
    2. 2
    $res = explode(" ", $price);		
    $price = trim(str_replace(".", "", str_replace(",", "", substr(trim($res[0]), 0, strlen(trim($res[0])) - 2))));

    Изначально в переменной $price строка такого вида: 144.07 РУБ.
    Судя по всему автор хотел таким образом получить из нее целое значение

    partizan22, 12 Сентября 2010

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

    −155

    1. 1
    2. 2
    3. 3
    4. 4
    @image = (image unless image.nil?) or 
             (Rubygame::Surface.autoload(image_file) unless image_file.nil?) or 
             (Rubygame::Surface.autoload("#{@name}.png") unless @name.nil?) or 
             Rubygame::Surface.new([16, 16])

    (c) http://stackoverflow.com/questions/3690508

    Nakilon, 11 Сентября 2010

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

    +154

    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
    // $curr_page - старница, на который сейчас находимся
    // $n_page - число страниц
    // $count - обще число записей
    // $param - site - страницы на сайте
    //        - adm - в админке
    function genNumPage($curr_page, $n_page, $count, $param=null) {
        $string = parse_url($_SERVER['REQUEST_URI']);
        $query = '?'.$string['query'];
        $num_page = ceil($count / $n_page);
        if (isset($param))  $table = new my_Page("site/site_interface.html", "num_page");
        else                $table = new my_Page("interface/interface.html", "num_page");
        
        if ($num_page < 2) return null;
        
        for ($i = 1; $i <= $num_page; $i++) {
            if ($i != $curr_page) {
                if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $href = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.$i, $query);
                elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $href = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.$i, $query);
                elseif ($string['query'] != '')                     $href = '?'.$string['query'].'&p='.$i;
                else                                                $href = '?p='.$i;
                
                if ((!$param) || ($param == 'adm')) $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> ";
                else                                $str .= " <a href=".$string['host'].$string['path'].$href.">".$i."</a> | ";
            }
            elseif ((!$param) || ($param == 'adm')) $str .= "<span>".$i."</span>";
            else                                    $str .= "<span>".$i."</span> | ";
        }
        
            if ($curr_page > 1) {
            if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $prev = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page - 1), $query);
            elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $prev = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page - 1), $query);
            elseif ($string['query'] != '')                     $prev = '?'.$string['query'].'&p='.($curr_page - 1);
            else                                                $prev = '?p='.($curr_page - 1);;
            
            if ((!$param) || ($param == 'adm')) $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">&larr;</a> ";
            else                                $prev = " <a href=".$string['host'].$string['path'].$prev." id=\"PrevLink\">Предыдущая</a> ";
        }
        
        if ($curr_page < $num_page) {
            if (preg_match('/\?p\=[0-9]{1,3}/', $query))        $next = preg_replace('/\?p\=[0-9]{1,3}/', '?p='.($curr_page + 1), $query);
            elseif (preg_match('/\&p\=[0-9]{1,3}/', $query))    $next = preg_replace('/\&p\=[0-9]{1,3}/', '&p='.($curr_page + 1), $query);
            elseif ($string['query'] != '')                     $next = '?'.$string['query'].'&p='.($curr_page + 1);
            else                                                $next = '?p='.($curr_page + 1);;
            
            if ((!$param) || ($param == 'adm')) $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">&rarr;</a> ";
            else                                $next = " <a href=".$string['host'].$string['path'].$next." id=\"NextLink\">Следующая</a> ";
        }
        
        $table->addValueArray(array(
                                    "NUM"   => $str,
                                    "PREV"  => $prev,
                                    "NEXT"  => $next
        ));
        return $table->myReplace();
    }

    Генерирует номера страниц. Из одной CMS'ки.

    netrain, 09 Сентября 2010

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

    +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
    class microTimer {
    	function start() {
    		global $starttime;
    		$mtime = microtime();
    		$mtime = explode( ' ', $mtime );
    		$mtime = $mtime[1] + $mtime[0];
    		$starttime = $mtime;
    	}
    	function stop() {
    		global $starttime;
    		$mtime = microtime();
    		$mtime = explode( ' ', $mtime );
    		$mtime = $mtime[1] + $mtime[0];
    		$endtime = $mtime;
    		$totaltime = round( ($endtime - $starttime), 5 );
    		return $totaltime;
    	}
    }

    DLE 9.0

    Morgan, 06 Сентября 2010

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

    +163

    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
    if (document.all('text1')!=null)
      {
       obj=document.all('text1');
       obj.style.position='absolute';
       obj.style.left=785+k;
       obj.style.top=66;
      }
      if (document.all('text1')!=null)
      {
      obj=document.all('text2');
      obj.style.position='absolute';
      obj.style.left=785+k;
      obj.style.top=88;
      }
      if (document.all('text1')!=null)
      {
      obj=document.all('img1');
      obj.style.position='absolute';
      obj.style.left=730+k;
      obj.style.top=72;
      }
      if (document.all('text1')!=null)
      {
      obj=document.all('img2');
      obj.style.position='absolute';
      obj.style.left=904+k;
      obj.style.top=84;
      }
      if (document.all('text1')!=null)
      {
      obj=document.all('img3');
      obj.style.position='absolute';
      obj.style.left=785+k;
      obj.style.top=39;
      }
      if (document.all('text1')!=null)
      {
      obj=document.all('img4');
      obj.style.position='absolute';
      obj.style.left=795+k;
      obj.style.top=109;
      }

    Надеюсь, что это генерировали в цикле, а не писали руками.

    telnet, 31 Августа 2010

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

    +167

    1. 1
    $select->where('target_table.param IN (' . implode(',', array_map(create_function('$e', '{return "\'$e\'";}'), $entities)) . ')');

    Недавно наткнулся на такое :)

    ko1Rn, 27 Августа 2010

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

    −101

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #TROLOLO GENERATOR!
    def trololo(x):
        print 'tro'+('lo'*x)
        
    trololo(100)

    Если нужно потроллить!

    boltayka, 27 Августа 2010

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