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

    В номинации:
    За время:
  2. 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)
  3. SQL / Говнокод #6503

    −864

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

    Duke_Raven, 28 Апреля 2011

    Комментарии (5)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. Pascal / Говнокод #6410

    +96

    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
    function OnShape(sh: TShape; X, Y: Integer) : TBrushStyle;
    var r, cx, cy, d2: Integer;
    begin
    r := sh.Width div 2;
    cx := sh.Left + r;
    cy := sh.Top + r;
    d2 := (X - cx) * (X - cx) + (Y - cy) * (Y - cy);
    OnShape := bsClear;
    if d2 < r*r then OnShape := bsSolid;
    end;
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
    Shape1.Brush.Color := clRed;
    Shape1.Brush.Style := OnShape(Shape1, X, Y);
    Shape2.Brush.Color := clLime;
    Shape2.Brush.Style := OnShape(Shape2, X, Y);
    Shape3.Brush.Color := clYellow;
    Shape3.Brush.Style := OnShape(Shape3, X, Y);
    end;

    Откуда бы вы думали это? Правильно, "Занимательное программирование Delphi". Глава 14. Светофор.

    Govnocoder#0xFF, 19 Апреля 2011

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

    +73

    1. 1
    2. 2
    if ((float)TF1.getText()>(float)(TF2.getText()){
    }

    Вот так вот приводят типы:)
    http://www.sql.ru/forum/actualthread.aspx?bid=38&tid=551373&hl=

    javaman, 18 Апреля 2011

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

    +132

    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
    int cont[15];
    bool stop_access = false;
    struct cel container[MAX_SIZE];
    struct termios savetty;
    struct termios tty;
    pthread_t thread[100];
    pthread_mutexattr_t muattr; 
    pthread_mutex_t count_mutex; 
    int icn=0;//Number elements in container
    static int x;
    static int y;
    void* stack;
      pthread_mutex_unlock(&count_mutex); 
      sleep(1);
    };
    return (void*)1;
    };
    
    void* main_thread(void *arg){
       while(true){
       sleep(1);
      char ic=getchar();
        if(ic=='\n'){
          printf("Thread\tnumber elements\n");
          for(int i=0;i<=x;i++)
          pthread_cancel(thread[i]);
          for(int i=0;i<=x;i++){
    	printf("%d ",i);
    	int cn=0;
    	for(int j=0;j<=icn;j++){
    	  if(container[j].thrnm==i){ cn++; };
    	  };
    	  printf("\t%d\n",cn);
    	};
    	printf("container number element %d\n",icn);
    	exit(0);
          };
     };
      
    };
    
    int main(int argc, char * argv[])
    {
      icn=0;
      
    if(argc<2){printf("1 arg n number of threads, 2 argument maximum number element in container");exit(0);};
    x=atoi(argv[1]);
    y=atoi(argv[2]);
    if(x>64){printf("Число потоков должно быть меньше 64\n");exit(0);}
    printf("x %d y %d\n",x,y);
    //mutex initialization
    int ret;
    ret = pthread_mutexattr_init(&muattr);
    
      //switch the keyboard to noncanonical mode
    pid_t pt=tcgetsid(0);
     // char *var=ctermid (NULL);
      printf("pid %d\n",pt);
    tcgetattr (0, &tty);
    savetty = tty;
    tty.c_lflag &= ~(ICANON);
    tty.c_cc[VMIN] = 1;
    tcsetattr (0, TCSAFLUSH, &tty);
    pthread_t mthr;
     pthread_attr_t mattr;
      pthread_attr_init(&mattr);
      pthread_attr_setdetachstate(&mattr,PTHREAD_CREATE_DETACHED);
    int mres = pthread_create(&mthr, &mattr, main_thread, NULL);
      if (mres == 0) {
        printf("Creating main thread\n");
        sleep(0.7);
      } else {
        perror("Creating the main first thread");
      return EXIT_FAILURE;
      }
      
      
    for(int i=0;i<=x;i++){
      int id1, id2, result;
      id1 = 1;
      pthread_attr_t attr;
      pthread_attr_init(&attr);
      // отсоединенный поток - не ждем его возврата
      pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
      result = pthread_create(&thread[i], &attr, thread_func, &i);
      if (result == 0) {
        printf("Creating thread %d\n",i);
        sleep(1);
      } else {
        perror("Creating the first thread");

    AliceGoth, 14 Апреля 2011

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

    −97

    1. 1
    hash.to_a.select{|elem| elem[1].map{|st| st.from}.include? state}.map{|elem| elem[1].map{|inner| inner.to}.uniq}.flatten

    e2718, 14 Апреля 2011

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