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

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

    +169

    1. 1
    2. 2
    $base = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
            $base .= '/public' . Zend_Registry::get('Theme')->getThemeBase().'/static/images/menu/';

    Поиск пути... :)

    kovel, 02 Февраля 2011

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

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?
    function dbQuery($query)
    {
    	$arg = func_get_args();
    	unset($arg[0]);
    	for ($i=1; $i<sizeof($arg); $i++) {
    		$arg[$i] = mysql_real_escape_string($arg[$i]);
    	}
    	$sql = vsprintf($query, $arg);
    	return mysql_query($sql) or die (mysql_error());
    }

    qbasic, 02 Февраля 2011

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

    +83

    1. 1
    2. 2
    3. 3
    private double calculateValue( int number, int rate ) {
        return Math.pow( number, rate );
    }

    galak, 31 Января 2011

    Комментарии (12)
  5. Си / Говнокод #5441

    +144

    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
    static struct hostent *hostd;
    
    int getLocalIP(unsigned long *ip) {
        if ((hostd = gethostbyname("")) == NULL) {
            *ip = -1;
            return -1;
        } else {
            *ip = *(u_long *) hostd->h_addr_list[0];
            return 0;
        }
    }
    
    unsigned long getLocalIPRedneckStyle() {
        unsigned long *ip;
    
        if (getLocalIP(ip)) {
            return -1;
        } else {
            return *ip;
        }
    }

    danilissimus, 29 Января 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $userList = "";
    foreach ($this->currentUsers as $k => $v)
    { 
        $userList .= ($v->first_name . (empty($v->middle_name) ? "" : " " . $v->middle_name)  . " " . $v->last_name . ", ");
    }
    $userList = substr($userList, 0, -2);
    ?>
    <?= $userList ?>

    Индусы отдыхают.

    anycolor, 28 Января 2011

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

    +120

    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
    98. 98
    static void processCmd(string command) {
    	string[] c_args = command.Split(" ".ToCharArray());
    	switch (c_args[0]) {
    		case "beep":
    			nbr.PlayTone(4096, 500);
    			break;
    		case "exit":
    			exit_op();
    			break;
    		case "info":
    			log_ca("Info:");
    			log_ca(Application.ProductName + " " + Application.ProductVersion);
    			log_ca("listener is " + ((services_running[0]) ? "running" : "down"));
    			log_ca("updater is " + ((services_running[1]) ? "running" : "down"));
    			break;
    		case "start":
    			try {
    				switch (c_args[1]) {
    					case "updater":
    						break;
    					case "listener":
    						if (services_running[0])
    							log_ca("listener is already running");
    						else
    							start_listener();
    						break;
    					default:
    						throw new ArgumentException();
    						break;
    				}
    			}
    			catch {
    				log_ca("Usage: start <service>. Available services: listener, updater.");
    			}
    			break;
    		case "help":
    			foreach (string hs in System.IO.File.ReadAllLines("help.txt")) {
    				log_ca(hs);
    			}
    			break;
    		default:
    			log_ca("\"help\" will display all available commands");
    			break;
    		case "stop":
    			try {
    				nbr.MotorA.Brake();
    				nbr.MotorB.Brake();
    				nbr.MotorC.Brake();
    			}
    			catch { }
    			break;
    		case "run":
    			try {
    				switch(c_args[1]) {
    					case "a":
    						if(arr_motor[0]=="none")
    							log_e("Motor not found or config error");
    						else {
    							if (c_args[4] == "false")
    								nbr.MotorA = new NxtMotor(false);
    							else
    								nbr.MotorA = new NxtMotor(true);
    							nbr.MotorA.Run(Convert.ToSByte(c_args[2]), Convert.ToUInt32(c_args[3]));
    						}
    						break;
    					case "b":
    						if(arr_motor[1]=="none")
    							log_e("Motor not found or config error");
    						else {
    							if (c_args[4] == "false")
    								nbr.MotorB = new NxtMotor(false);
    							else
    								nbr.MotorB = new NxtMotor(true);
    							nbr.MotorB.Run(Convert.ToSByte(c_args[2]), Convert.ToUInt32(c_args[3]));
    						}
    						break;
    					case "c":
    						if(arr_motor[2]=="none")
    							log_e("Motor not found or config error");
    						else {
    							if (c_args[4] == "false")
    								nbr.MotorC = new NxtMotor(false);
    							else
    								nbr.MotorC = new NxtMotor(true);
    							nbr.MotorC.Run(Convert.ToSByte(c_args[2]), Convert.ToUInt32(c_args[3]));
    						}
    						break;
    					default:
    						throw new Exception();
    						break;
    				}
    			}
    			catch (Exception ex) {
    				log_ca("Usage: run <motor> <speed> <tacho> <reverse>. Example: run a 100 0 false.");
    			}
    		break;
    	}
    }

    Мой код, написано 3 года назад.

    A1mighty, 27 Января 2011

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

    +157

    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
    function convert($str,$ky=''){
      if($ky=='')return $str;
      $ky=str_replace(chr(32),'',$ky);
      if(strlen($ky)<8)exit('key error');
      $kl=strlen($ky)<32?strlen($ky):32;
      $k=array();
      for($i=0;$i<$kl;$i++){
        $k[$i]=ord($ky{$i})&0x1F;
      }
      $j=0;
      for($i=0;$i<strlen($str);$i++){
        $e=ord($str{$i});
        $str{$i}=$e&0xE0?chr($e^$k[$j]):chr($e);
        $j++;
        $j=$j==$kl?0:$j;
      }
      return $str;
    }

    PHPASTA

    bugmenot, 27 Января 2011

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

    +166

    1. 1
    echo 'Состояние ебических кавычек: '.(get_magic_quotes_gpc() ? '<span class="red">Да как же их вырубить!!?</span>' : '<span class="green">Вырублены!</span>');

    Uchkuma, 25 Января 2011

    Комментарии (12)
  10. Java / Говнокод #5377

    +78

    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
    public void setDomainSearchFilter(String domainSearchFilter) {
    	if (this.domainSearchFilter == null)
    	{
    		if (domainSearchFilter != null)
    		{
    			this.domainSearchFilter = domainSearchFilter;
    		}
    
    		return;
    	}
    
    	if (domainSearchFilter == null)
    	{
    		this.domainSearchFilter = null;
    		return;
    	}
    
    	if (!this.domainSearchFilter.equals(domainSearchFilter))
    	{
    		this.domainSearchFilter = domainSearchFilter;
    	}
    }

    voice, 24 Января 2011

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

    +162

    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
    <?php
    $month_cols = array("january" => 31,
    	            "february" => 28,
                        "march" => 31,
                        "april" => 30,
                        "may" => 31,
                        "june" => 30,
                        "july" => 31,
                        "august" => 31,
                        "september" => 30,
                        "october" => 31,
                        "november" => 30,
                        "december" => 31);
    
    if($_POST["month_to_change"])
    {
    $month_to = $_POST["month_to_change"];
     for($i = 1; $i <= $month_cols[$_POST["month_to_change"]]; $i++)
     {
      $description = mysql_real_escape_string($_POST["textar_".$i]);
      mysql_query("UPDATE `calender` SET `description` = '$description' WHERE `day` = '$i' AND `month` = '$month_to' LIMIT 1");
     }
    }
    
      echo "<h3>Лунный календарь</h3>";
    
      if($_POST["month_change"])
      {
       if($_POST["month"] == "january") $jan_sel = "selected";
       if($_POST["month"] == "february") $feb_sel = "selected";
       if($_POST["month"] == "march") $mar_sel = "selected";
       if($_POST["month"] == "april") $apr_sel = "selected";
       if($_POST["month"] == "may") $may_sel = "selected";
       if($_POST["month"] == "june") $jun_sel = "selected";
       if($_POST["month"] == "july") $jul_sel = "selected";
       if($_POST["month"] == "august") $aug_sel = "selected";
       if($_POST["month"] == "september") $sep_sel = "selected";
       if($_POST["month"] == "october") $oct_sel = "selected";
       if($_POST["month"] == "november") $nov_sel = "selected";
       if($_POST["month"] == "december") $dec_sel = "selected";
      }
      else
      {
       $jan_sel = "selected";
      }
    
      $changing_month = $_POST["month"];
      if($changing_month == "") $changing_month = "january";
    
      echo "<table>\n";
      echo "<tr><td>\n";
      echo "<form name=\"form_name\" id=\"form_id\" action=\"\" method=\"post\">\n";
      echo "<select name=\"month\" onChange=\"this.form.submit()\">\n
      	<option value=\"january\" $jan_sel>Январь</option>\n
    	<option value=\"february\" $feb_sel>Февраль</option>\n
            <option value=\"march\" $mar_sel>Март</option>\n
            <option value=\"april\" $apr_sel>Апрель</option>\n
            <option value=\"may\" $may_sel>Май</option>\n
            <option value=\"june\" $jun_sel>Июнь</option>\n
            <option value=\"july\" $jul_sel>Июль</option>\n
            <option value=\"august\" $aug_sel>Август</option>\n
            <option value=\"september\" $sep_sel>Сентябрь</option>\n
            <option value=\"october\" $oct_sel>Октябрь</option>\n
            <option value=\"november\" $nov_sel>Ноябрь</option>\n
            <option value=\"december\" $dec_sel>Декабрь</option>\n
            </select>\n";
      echo "<input type=\"hidden\" name=\"month_change\" value=\"change\">\n";
      echo "</td></tr>\n";
    
      for($i = 1; $i <= $month_cols[$changing_month]; $i++)
      {
    
      $q_q2 = mysql_query("SELECT `description` FROM `calender` WHERE `day` = '$i' AND `month` = '$changing_month' LIMIT 1");
    
      $descr = mysql_fetch_row($q_q2);
    
       echo "<tr valign=\"top\" cols=\"5\">
              <td><b>$i</b></td>
              <td>
              <textarea name=\"textar_$i\">".$descr[0]."</textarea>
              </td>
    </tr>\n";
      }
    
      echo "<tr>
             <td colspan=\"2\" align=\"right\">
             <input type=\"submit\" value=\"Сохранить\">
             </td>
    </tr>\n";
    
      echo "<input type=\"hidden\" name=\"month_to_change\" value=\"$changing_month\">\n";
    
      echo "</form>";
      echo "</table>";
    ?>

    А это уже часть, которая апдейтит базу :-)

    varg242, 22 Января 2011

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