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

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

    +148

    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
    <?php
    
    class CodeCounter {
        const MULTILINE_COMMENT = 0x01;
    
        private $dir = null;
        private $ext = null;
    
        public function __construct($dir = '.', $ext = '*') {
            $this->dir = $dir;
            if($ext == '*') {
                $this->ext = "/.*/si";
            } else {
                $e = explode('|', $ext);
                foreach($e as &$ext) {
                    $ext = trim($ext);
                    if($ext == '')
                        unset($ext);
                }
                $r = implode('|', $e);
                $this->ext = "/.*\.({$r})$/si";
            }
    
        }
    
        public function calculate() {
            $lines = 0;
            $args = func_get_args();
            if(count($args) == 0)
                $dir = $this->dir;
            else
                $dir = $args[0];
            if(file_exists($dir) && is_dir($dir)) {
                $list = scandir($dir);
                foreach($list as $item) {
                    if($item == '.' || $item == '..')
                        continue;
                    $fullItem = realpath($dir . DIRECTORY_SEPARATOR . $item);
                    if(is_dir($fullItem)) {
                        $lines += $this->calculate($fullItem);
                    } else {
                        if(preg_match($this->ext, $item)) {
                            echo "Calculating lines in {$fullItem}:  ";
                            $_lines = self::count($fullItem);
                            echo "{$_lines}\n";
                            $lines += $_lines;
                        }
                    }
                }
            }
            return $lines;
        }
    
        private static function count($file) {
            $lines = 0;
            $d = null;
            if(file_exists($file) && ($file = file($file))) {
                foreach($file as $line) {
                    $line = trim($line);
                    if($line == '')
                        continue;
                    if( substr($line, 0, 2) == '//' || //single line comment
                        substr($line, 0, 1) == '#'  || //single line comment
                        substr($line, 0, 2) == '<?' || //php open tag
                        substr($line, 0, 2) == '?>'    //php close tags
                    )
                        continue;
                    if(($pos = strpos('/*', $line)) !== false) {
                        if($pos == 0) {
                            if(strpos('*/', $line, $pos) === false) {
                                $d = self::MULTILINE_COMMENT;
                            }
                        } else {
                            $lines++;
                        }
                        continue;
                    }
                    if($d == self::MULTILINE_COMMENT) {
                        if(strpos('*/', $line) !== false) {
                            $d = null;
                        }
                        continue;
                    }
                    $lines++;
                }
            }
            return $lines;
        }
    }
    
    $counter = new CodeCounter('./amapys', 'php|js');
    $lines = $counter->calculate();
    echo "\nTotal: {$lines} lines\n";

    Автор: POPSuL
    Пхп-шники такие пхп-шники.
    ООП во все поля. Им неведом sed и awk.

    cutwater, 13 Июня 2011

    Комментарии (16)
  3. Lua / Говнокод #6809

    −93

    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
    --загрузка шрифта
    MyFont = pge.font.load("verdana.ttf",12)
    
    --цвета шрифта
    white = pge.gfx.createcolor(255,255,255)
    green = pge.gfx.createcolor(0,255,0)
    
    --загрузка графики
    A01 = pge.texture.load("pics/A-01.png")
    A02 = pge.texture.load("pics/A-02.png")
    A03 = pge.texture.load("pics/A-03.png")
    A04 = pge.texture.load("pics/A-04.png")
    A05 = pge.texture.load("pics/A-05.png")
    A06 = pge.texture.load("pics/A-06.png")
    A07 = pge.texture.load("pics/A-07.png")
    A08 = pge.texture.load("pics/A-08.png")
    A09 = pge.texture.load("pics/A-09.png")
    A10 = pge.texture.load("pics/A-10.png")
    A11 = pge.texture.load("pics/A-11.png")
    A12 = pge.texture.load("pics/A-12.png")
    A13 = pge.texture.load("pics/A-13.png")
    A14 = pge.texture.load("pics/A-14.png")
    A15 = pge.texture.load("pics/A-15.png")
    A16 = pge.texture.load("pics/A-16.png")
    A17 = pge.texture.load("pics/A-17.png")
    A18 = pge.texture.load("pics/A-18.png")
    A19 = pge.texture.load("pics/A-19.png")
    A20 = pge.texture.load("pics/A-20.png")
    A21 = pge.texture.load("pics/A-21.png")
    A22 = pge.texture.load("pics/A-22.png")
    A23 = pge.texture.load("pics/A-23.png")
    A24 = pge.texture.load("pics/A-24.png")
    
    --переменная для счётчика
    index = 1
    
    
    while pge.running() do
    pge.controls.update()
    pge.gfx.startdrawing() -- начало рисования
    pge.gfx.clearscreen() -- очистка экрана
    if pge.controls.pressed(PGE_CTRL_DOWN) then
    index = index+1 -- увеличиваем index на 1
    end
    
    A01:activate()
    A01:draw(30,25) -- отрисовка первой картинки
    -- далее отрисовка последующих картинок в зависимости от значения переменной index
    	if index==2 then
    		pge.gfx.clearscreen()
    		A02:activate()
    		A02:draw(30,25)
    	end
    	if index==3 then
    		pge.gfx.clearscreen()
    		A03:activate()
    		A03:draw(30,25)
    	end
    	if index==4 then
    		pge.gfx.clearscreen()
    		A04:activate()
    		A04:draw(30,25)
    	end
    	if index==5 then
    		pge.gfx.clearscreen()
    		A05:activate()
    		A05:draw(30,25)
    	end
    	if index==6 then
    		pge.gfx.clearscreen()
    		A06:activate()
    		A06:draw(30,25)
    	end
    
    pge.gfx.enddrawing() -- конец отрисовки
    pge.gfx.swapbuffers()
    	if pge.controls.pressed(PGE_CTRL_START) then
    		break
    	end
    end

    Увидел и не смог не запостить
    Lua

    Werdn, 01 Июня 2011

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    $cd = strtotime($givendate);
    $newdate = date('Y-m-d H:i:s', mktime(date('H',$cd),
                       date('i',$cd), date('s',$cd), date('m',$cd)+$mth,
                       date('d',$cd)+$day, date('Y',$cd)+$yr));

    kovel, 23 Мая 2011

    Комментарии (16)
  5. Java / Говнокод #6670

    +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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    public boolean setBit(byte _position, boolean _state) {
    		if ( !valid ) {
    			LOG.error("value is INVALID");
    			
    			return false;
    		} else if ( _position<0 ) {
    			LOG.error("NEGATIVE _position");
    			
    			return false;
    		} else if ( _position > capacity ) {
    			LOG.warn("_position("+_position+") > cacity("+capacity+") "+
    					"for value "+this);
    			
    			return false;
    		}
    		
    		value|=( (_state ? 1 : 0) << (_position+1) );
    		
    		return true;
    }

    ога, разбежался

    ilardm, 14 Мая 2011

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

    +168

    1. 1
    <? echo convert($current_order['post_price']-1+1, 'CNY', $order_currency); ?>

    цена плюсминусадин

    Axell, 14 Мая 2011

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

    +146

    1. 1
    for (n = 0; n != dirs.length; n++)

    Lure Of Chaos, 14 Мая 2011

    Комментарии (16)
  8. SQL / Говнокод #6650

    −119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $query = "SELECT * FROM ns_preces".
    			 	" inner join ns_group on".
    				" ns_group.groupid=ns_preces.groupid".
     				" WHERE (assortiment=1) ".$group_case." and (proizvod like '%".$_POST["find"]."%' or model like '%".$_POST["find"]."%')";
    			$view_type=4;

    Если значение поля FIND избавляем от пробелов с помощью JavaScrip, разбивается слово в t убираются пробелы, как несколько значений скормить такому запросу ?

    lan-dao, 13 Мая 2011

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

    +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
    function shab()
    {
      global $title;                            
      global $description;
      global $keywords;
      global $content;                                         
      global $patch;
      global $page_names;
      global $pn;
      global $id;
      include_once $patch.'/head.php'; // почему-то вспомнился логотип башоргру cat /dev/ass > /dev/head
      echo $title.'</title>'."\n";
      echo '<meta name="description" content="'.$description.'">'."\n";
      echo '<meta name="keywords" content="'.$keywords.'">'."\n";
      include_once $patch.'/shapka.php'; // wtf!?
      echo $content."<br>\n";
      if(in_array($pn,$page_names))
      {                                   
          include $patch.'/form.php';
      }
      $ua=mysql_real_escape_string(trim($_SERVER['HTTP_USER_AGENT']));
      $ip=mysql_real_escape_string(trim($_SERVER['REMOTE_ADDR'])); // вебкил не пройдет
      mysql_query("update content set views=views+1 where id='$id'");
      mysql_query("insert into views_content set id='$id', ip='$ip', t=NOW() + INTERVAL 1 HOUR, d=NOW() + INTERVAL 1 HOUR, ua='$ua'");
      $q=mysql_query("select views,t,d from content where id='$id'");
      while($r=mysql_fetch_array($q))
      {
         echo '<br><span style="font-color:#808080; font-size:8pt; float:right;">Просмотров: '.$r['views'].'<br>
         '.$r['d'].'<font color="#ca3200"> / </font>'.$r['t']."<br>\n"; //d и t это дата и время кто не понял :D	
      } 
      echo '<a style="font-color:#ca3200; font-size:10pt;" href="index.php">все статьи</a></span>';
      include_once $patch.'/footer.php';
    }

    это вам не смарти, тут всё просто и понятно, а главное быстро. shab() и дело в шляпе.

    GoodTalkBot, 11 Мая 2011

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

    +152

    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
    QString generateGuid( const std::string &tDeviceSerial,
            const std::string &nDatetime, const std::string &licnum,
            const char *violation )
    {
        std::ostringstream s;
        s << tDeviceSerial;
        s << nDatetime;
        s << licnum;
        s << violation;
        
        QCryptographicHash hash( QCryptographicHash::Md5 );
        hash.addData( QByteArray( s.str().c_str() ) );
        QByteArray result = hash.result();
        return convToHex( (unsigned char*)result.data(), result.size() );
    }

    Оно, конечно, работает. Но разобраться в таком коде....

    panter_dsd, 11 Мая 2011

    Комментарии (16)
  11. Java / Говнокод #6577

    +68

    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
    public class Zayac {
    	public static void main(String args[]) {
        String ears="(\\_/)";
        String face="(-_-)";
        String hands="(> <)";
        String legs="(\")(\")";
        System.out.println(ears);
        System.out.println(face);
        System.out.println(hands);
        System.out.println(legs+'\n');
    	System.out.println('\t'+ears);
    	System.out.println('\t'+face);
    	System.out.println('\t'+hands);
        System.out.println('\t'+legs);
        System.out.println("\t"+"\t"+ears);
    	System.out.println("\t"+"\t"+face);
    	System.out.println("\t"+"\t"+hands);
        System.out.println("\t"+"\t"+legs);
    	}
    }

    Дело было вечером - делать было нечего.

    Akira, 06 Мая 2011

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