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

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

    +148.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
    15. 15
    16. 16
    17. 17
    // Any fool can write code that a computer can understand. Good programmers write code that humans can understand. (C) Martin Fowler.
    function changeLogo() {
    	var pane = document.getElementById("pane");
    	if(pane != null) {
    		pane.height = 240;
    		pane.width = document.body.clientWidth;
    	} else {
    		alert("it's sad, so sad...");
    	}
    	var logo = document.getElementById("logoJpg");
    	if(logo != null) {
    		logo.height = 50;
    		logo.width = document.body.clientWidth * 0.23;
    	} else {
    		alert(" ...it's a sad, sad situation, and it's getting more and more absurd");
    	}
    }

    Код совсем ничего, но камменты рулят

    domavoy, 15 Августа 2009

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

    +149.9

    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
    97. 97
    <?
    global $db;
    $db=new db(HOST,USER,PASS,DBNAME); //подключение к бд
    class db{
    	public $SumQuerys=false; //Temp Var
    	public $Vtime; //Temp time summ
    	public $td; //Temp date
    	public $db_id= false;
    	public $query_num=0;
    	public $query_id=NULL;
    	public $mysql_error=FALSE; 
    	public $mysql_error_num=NULL;
    	public $last_query=NULL;
    	var $error=0;
    	function __construct($host='',$user='',$pas='',$bd=''){
    		$this->db_id=mysql_connect($host,$user,$pas) or die('db connect error');
    		mysql_select_db($bd,$this->db_id) or die("db: '$bd' select error");
    		mysql_query('SET NAMES utf8');
    	}
    	function __destruct(){
    		$this->close();
    		if ($this->SumQuerys){
    			#print "<table style='font-size:10px;border-collapse:collapse;border:1px dotted black' border=1>".$this->SumQuerys."<tr><td><b>$this->Vtime</b></td><td></td></table>";
    		}
    	}
    	function query($query, $show_error=true){
    		$time = microtime(true);
    		$this->last_query = $query;
    		if(!($this->query_id = mysql_query($query, $this->db_id))){
    			$this->error=1;
    			$this->mysql_error = mysql_error();
    			$this->mysql_error_num=mysql_errno();
    			if($show_error){
    				$this->display_error($this->mysql_error, $this->mysql_error_num, $query);
    			}
    		} else {$this->error=0;}
    		$this->query_num ++;
    		
    		// ----------------------------------------------------------------------------
    		$time = round(microtime(true)-$time,5);
    		if($time>0.003){
    			$alert = "color:red";
    		}
    		$this->Vtime += $time;
    		@$this->SumQuerys .= "<tr style='$alert'><td>".$time."</td><td>".$query.'</td></tr>';
    		//------------------------------------------------------------------------------
    		return $this->query_id;
    	}
    	function qrow($query){
    		$this->query($query);
    		return mysql_fetch_row($this->query_id);
    	}
    	function get_row($query_id = ''){
    		if ($query_id == '') $query_id = $this->query_id;
    		return mysql_fetch_assoc($query_id);
    	}
    	function get_array($query_id = ''){
    		if ($query_id == '') $query_id = $this->query_id;
    		return mysql_fetch_array($query_id);
    	}
    	function fetch($query_id = ''){
    		global $d;
    		if ($query_id == '') $query_id = $this->query_id;
    		return $d=@mysql_fetch_object($query_id);
    	}
    	function fetchAll($field = ''){
    		while ($d=$this->fetch($this->query_id)){
    			if ($field == ''){
    				$arr[] = $d;
    			} else {
    				$arr[] = $d->$field;
    			}
    		}
    		return @$arr;
    	}
    	function qAll($query){
    		$this->query($query);
    		return $this->fetchAll();
    	}
    	function fetch_row($query_id = ''){
    		global $d;
    		if ($query_id == '') $query_id = $this->query_id;
    		return $d=@mysql_fetch_row($query_id);
    	}
    	function qfetch($query){
    		global $d;
    		$this->query($query);
    		return $d=@mysql_fetch_object($this->query_id);
    	}
    	function num_rows($query_id = ''){
    		if ($query_id == '') $query_id = $this->query_id;
    		return mysql_num_rows($query_id);
    	}
    	
    	function insert_id() {
    		return mysql_insert_id($this->db_id);
    	}

    интерестный класс для работы с бд=)

    Heckfi, 13 Августа 2009

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

    +77.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private Date generateDate(int dateDay, int dateMonth) throws ParseException {
    		DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    		return df.parse(String.valueOf(generator.nextInt(dateDay) + 1) + "."
    			+ String.valueOf(dateMonth) + "." + DATE_YEAR);
    	}

    такое ощущение, что с незапамятных времён индусы перелелялись на русь...

    asdqwezx, 12 Августа 2009

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

    +34

    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
    void dump_indexes(map<int,stride_slices> picks, ofstream &f);
    {
      f<<"# full size: "<<picks.size()<<endl;
      for(map<int, stride_slices>::iterator
    	p=picks.begin(); p!=picks.end(); ++p)
        {
          f<<"## "
           <<p->first<<"'st stride slices count: "
           <<p->second.size()<<endl;
          
          for(stride_slices::iterator
    	    pp=p->second.begin(); pp!=p->second.end(); ++pp)
    	{
    	  f<<"### "
    	   << p->first<<"'st stride, "
    	   <<pp->first<<"'st slice size: "
    	   <<pp->second.size()<<endl;
    	  for(max_slice::iterator
    		ppp=pp->second.begin(); ppp!=pp->second.end(); ++ppp)
    	    {
    	      f<<"#### "
    	       <<p->first<<"'st stride, "
    	       <<pp->first<<"'st slice, "
    	       <<ppp->first<<"'st chunk size:"
    	       <<ppp->second.size()<<endl;
    	      
    	      for(max_chunk::iterator
    		    pppp=ppp->second.begin(); pppp!=ppp->second.end(); ++pppp)
    		f<<"       "
    		 <<p->first<<" "
    		 <<pp->first<<" "
    		 <<ppp->first<<" "
    		 <<pppp->first<<" : "
    		 <<pppp->second<<endl;	
    	    }
    	}
        }
    }

    а как нормально просмотреть кучу вложенных контейнеров?

    Biburath, 11 Августа 2009

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

    +159.3

    1. 1
    2. 2
    3. 3
    4. 4
    for ($x=5;$x<135;$x+=25){
        $cislo=mt_rand(0,9);
        $string.=$cislo;
    }

    Interfere, 11 Августа 2009

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

    +24.3

    1. 1
    2. 2
    3. 3
    bool TimeSpan::operator != (const TimeSpan & tvalue) const {
    	return *this != tvalue;
    }

    Веселый код в одной либе. То то я удивился, откуда у меня stack owerflow там где его быть не может.

    Автор виддимо хотел написать !(*this == tvalue) но протупил. =)

    guest, 09 Августа 2009

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

    +136.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
    function lock_user($id)
    {       
            global $db_obj;
     
            $SQL = "SELECT GET_LOCK('%s', 10)";
            $SQL = sprintf($SQL, (int)$id);
            $result = $db_obj->query($SQL);
            $row = $db_obj->fetch_array($result);
            $key = "GET_LOCK('" . (int)($id) . "', 10)";
            $res = $row[$key];
            return $res;
    }

    дзен

    guest, 06 Августа 2009

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

    +146.1

    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
    private function putContents($file, $string)
        {
            $result = false;
            $f = @fopen($file, 'ab+');
            if ($f) {
                fseek($f, 0);
                ftruncate($f, 0);
                $tmp = @fwrite($f, $string);
                if (!($tmp === FALSE)) {
                    $result = true;
                }
                @fclose($f);
            }
            @chmod($file, $this->options['file_umask']);
            return $result;
        }

    А почему не fopen($file, 'w'); ?

    guest, 06 Августа 2009

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    foreach ($polzavateli as $polzavatel){
    $i++;
    echo $polzavatel[$i];
    }

    профессиональный обход массива :)

    guest, 02 Августа 2009

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

    +146

    1. 1
    return ($pkey? $pkey : true); // раньше здесь всегда возвращалось true - теперь тоже

    guest, 31 Июля 2009

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