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

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $value = "";
    $content = $content;
    $val = "\$content->" . $field->name;
    $fieldname = $field->name;
    
    eval("if (isset($val)) \$value = \"$val\";");
    $value = JText::_($value);
    $value = stripslashes($value);

    Joomla. Adsmanager

    Jetti, 10 Мая 2011

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function get_phrase()
    {
    	global $words;
    	global $phrase;
    	$phrase = implode(" ", $words);
    	if(strlen($phrase) < 4) return;
    }

    I was amazed to find this!?! The last line of the function rationalized my day...

    wyand, 05 Мая 2011

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

    +159

    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 CreateLayer(text, id, t, l,m) {
    if(document.layers && m==1)
     {
      var str="<LAYER ID=menu" + id + " TOP=" + t + " LEFT=" + l + " onmouseover=\"occupied_menu[" + id + "]=1;\" onmouseout=\"Turn('" + id + "',0);occupied_menu[" + id + "]=0;\" VISIBILITY=hide Z-INDEX=2 bgcolor=\"#0066CC\">" + text + "</LAYER>";
      document.write(str);
     }
     else if(document.layers && m==2)
     {
     id = id.substring(0,1);
      var str="<LAYER ID=menu" + id + "a TOP=" + t + " LEFT=" + l + " onmouseover=\"occupied_menu[" + id + "]=1;occupied_header[" + id + "]=1;\" onmouseout=\"Turn('" + id + "',0);occupied_menu[" + id + "]=0;occupied_header[" + id + "]=0\" VISIBILITY=hide Z-INDEX=2 bgcolor=\"#EF1010\">" + text + "</LAYER>";
      document.write(str);
     }
     else if(document.all)
     {
      var strng="<div id=menu" + id + " style=\"position:absolute;top:" + t + ";left:" + l + ";visibility:hidden;width:100;z-index:1;\" onmouseover=\"occupied_menu[" + id + "]=1;\" onmouseout=\"Turn('" + id + "',0);occupied_menu[" + id + "]=0;\">" + text + "</div>";
      document.write(strng);
     }
     }

    moonie, 05 Мая 2011

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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    if ((u[i]!=100500)&&(v[j]==100500))
        v[j]=matr[i+1][j+1].cost-u[i];
    if ((u[i]==100500)&&(v[j]!=100500))
        u[i]=matr[i+1][j+1].cost-v[j];

    пересчет платежей в ТЗЛП

    resettik, 04 Мая 2011

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

    +161

    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
    if($age != '') {
    			$d_m_y = explode('-', $age); // Разделяем на day(0) month(1) year(2)
    		// ГЕНЕРАЦИЯ ФОРМЫ С ДНЕМ РОЖДЕНИЯ
    		$vars['bday'] = "<select name=\"b_day\">\n<option>-</option>\n";
    		$i = 1;
    		while ($i <= 31) {
    			if($d_m_y[0] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['bday'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['bday'] .= "</select>\n";
    		// ГЕНЕРАЦИЯ СПИСКА С МЕСЯЦАМИ
    		$i = 1;
    		$vars['bmonth'] = "<select name=\"b_month\">\n<option>-</option>\n";
    		while ($i <= 12) {
    			if($d_m_y[1] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['bmonth'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['bmonth'] .= "</select>\n"; // Месяц ДР при ред
    		// ГЕНЕРАЦИЯ СПИСКА С ГОДАМИ
    		$i = 1940;
    		$vars['byear'] = "<select name=\"b_year\"\n<option>-</option>\n"; // Год ДР при ред
    		while ($i <= 2003) {
    			if($d_m_y[2] == $i) {
    				$sel = ' selected';
    			} else {
    				$sel = '';
    			}
    			$vars['byear'] .= '<option'.$sel.'>'.$i."</option>\n";
    			$i++;
    		}
    		$vars['byear'] .= "</select>\n";
    		$vars['use_age'] = false; // ОТКЛЮЧАЕМ ПОКАЗ ПУСТОГО СПИСКА
    		} else {
    		$vars['use_age'] = true;
    		$vars['bday'] = false;
    		$vars['bmonth'] = false;
    		$vars['byear'] = false;
    		}

    Генерация SELECT'ов для выбора даты рождения

    Мартин, 02 Мая 2011

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

    −864

    1. 1
    2. 2
    comment on column XXX.status
      is '0 -- вопрос включен, 1-- выкл';

    Duke_Raven, 28 Апреля 2011

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

    +124

    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
    private void TextBox_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Space)
                {
                    TextBox box = sender as TextBox;
    
                    int start = box.SelectionStart;
                    int length = box.SelectionLength;
    
                    if (length == 0)
                    {
                        box.Text = box.Text.Insert(start + length, " ");
                        box.SelectionStart = start + 1;
                    }
                    else
                    {
                        string str1 = box.Text.Substring(0, start);
                        string str2 = box.Text.Substring(start + length);
    
                        box.Text = str1 + " " + str2;
                        box.SelectionStart = start + 1;
                    }
    
                    e.Handled = true;
                }
            }

    Отборный говнокод выращенный на территории Индии.
    Видимо им зарплату действительно за строчки кода платят.

    strato, 26 Апреля 2011

    Комментарии (5)
  9. SQL / Говнокод #6448

    −860

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    -- Из простого...
    select kdet, cexnum, cex, last_value(cex) over(partition by kdet) as final_cex
    from xxtpa_rout_aztpa_v;
    
    -- Сделаем сложное...
    select t.*, max(max_cex) over(partition by kdet, rout_num) max_cex
    from (select t.*, case cex_num when max(cex_num) over(partition by t.kdet, t.rout_num) then t.cex else null end max_cex
    from xxtpa_rout_aztpa_v t) t;

    Пример того, как НЕ применять KISS-принцип.

    dwinner, 22 Апреля 2011

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

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    foreach ($firstQueryRes as $row)
    			{
    				$K = $this->ccnm;
    				$U = $this->getFncByCategory($row->category);  // compile material href //
    				$R = $row->category;
    				$W = $row->date;
    				$A = $row->huu_1;
    				$materialHref[$row->id_all] = site_url("$K/$U/$R/$W/$A");
    				$materialTitle[$row->id_all] = $row->name;
    			}

    Задание: расшифруйте какое польское плохое слово здесь инкапсулировано.

    increazon, 21 Апреля 2011

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

    +72

    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
    public class Tm_SP_RP extends Tm_Service implements IObject{
    	private static final String m_MsgProfileStore =
    		"UPDATE TM_SP_RP SET strMsgProfile=? WHERE nServiceID=?";
    	private static final String m_WorkaroundHack =
    		"SELECT data_type FROM user_tab_columns WHERE table_name='TM_SP_RP' AND column_name='STRMSGPROFILE'";
    
    	private String strMsgProfile = null;
    
    /* Здесь ещё разные всякие методы */
    
            private static String getWorkaroundType(Connection conn) throws SQLException
        {
        	PreparedStatement stmt = conn.prepareStatement(m_WorkaroundHack);
        	try
        	{
        		ResultSet rset = stmt.executeQuery();
        		try
        		{
        			if (!rset.next())
        				return "VARCHAR2";
        			return rset.getString(1);
        		}
        		finally
        		{
        			if (rset != null)
        				rset.close();
        		}
        	}
        	finally
        	{
        		if (stmt!=null)
        			stmt.close();
        	}
        }
    
    	public void storeMsgProfile(Connection conn) throws SQLException
    	{
    		String w_around = getWorkaroundType(conn); 
    		
        	PreparedStatement stmt = conn.prepareStatement(m_MsgProfileStore);
        	try
        	{
        		if (w_around.equalsIgnoreCase("VARCHAR2") ||
        			w_around.equalsIgnoreCase("VARCHAR"))
        		{
        			if (strMsgProfile == null)
        				stmt.setNull(1, Types.NULL);
        			else
        				stmt.setString(1, strMsgProfile);
        		}
        		else
        		{
        			byte []data = (strMsgProfile == null) ?
    	    				new byte[0] : strMsgProfile.getBytes();
    	    		stmt.setBytes(1, data);
        		}
        		
        		stmt.setLong(2, this.getId());
        		
        		stmt.executeUpdate();
        	}
        	finally
        	{
        		if (stmt!=null)
        			stmt.close();
        	}
    	}
    }

    Комбинация из багованных JDBC-дров Oracle и работающего с ним Hibernate (чтоб он сдох) иногда заставляет рождать вот такие хитрые workaround-хаки. Несколько баз, в одной тип поля - LONG, в другой - VARCHAR2.

    SadKo, 21 Апреля 2011

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