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

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

    +150

    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
    function keySave($key, $url)
    	{
    		$db = 'i_keys';
    		$this->keyDelete($key, $url);
    		$insert['key'] = $key;
    		$insert['url'] = $url;
    		$this->db->insert($db, $insert);
    	}
    
    	function keyDelete($key, $url)
    	{
    		$db = 'i_keys';
    		$this->db->where('url', $url);
    		$this->db->where('key', $key);
    		$this->db->delete($db);
    	}

    Можно ли так делать для предотвращения полных дублей в базе? Чем это не очень хорошо?

    increazon, 10 Июля 2011

    Комментарии (24)
  3. C# / Говнокод #7206

    +963

    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
    public void прорисовка_точек()
            {
                for (int i = 0; i < лист_точек.Count; i++)
                {
                    //Data0
                    if (((лист_точек[i] as ArrayList)[4] as ArrayList).Count != 0)
                    {
                        уровни определение_уровня = new уровни(s, (лист_точек[i] as ArrayList)[3].ToString(), 4);
                        if (определение_уровня.рисуем == true)
                        {
                            string type = (лист_точек[i] as ArrayList)[1].ToString();                        
                            for (int k = 0; k < ((лист_точек[i] as ArrayList)[4] as ArrayList).Count; k++)
                            {
                                PointF point = (((лист_точек[i] as ArrayList)[4] as ArrayList)[k] as List<PointF>)[0];
                                преобразование_координат координаты_старые = new преобразование_координат(point.X, point.Y, коэф_старый.max_x, коэф_старый.max_y, коэф_старый.K_x, коэф_старый.K_y);
                                point.X = (float)((новый.max_x_new - координаты_старые.xn) * новый.K_x_new * s);
                                point.Y = (float)((новый.max_y_new - координаты_старые.yn) * новый.K_y_new * s);
                                Rectangle rect = new Rectangle(Convert.ToInt32(point.X),Convert.ToInt32(point.Y),1,1);
                                if (проверка(this.Width, this.Height, point.X, point.Y) == true)
                                {
                                    Кисти_точек точки = new Кисти_точек(type);
                                    G.DrawImage(точки.bitm, point.X, point.Y, точки.bitm.Width, точки.bitm.Height);
                                }
                               прорисовка_надписей_точек(point, ((лист_точек[i] as ArrayList)[2].ToString()));
                            }
                        }
                    }
                }
            }

    Взято отсюда http://www.cyberforum.ru/csharp-net/thread330291-page3.html

    vvs, 08 Июля 2011

    Комментарии (24)
  4. Perl / Говнокод #7193

    −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
    sub hex_to_string
    {
        my ($res, $str, $i) = ("", shift, 0);
        $str =~ tr/A-Z/a-z/;
        while ($i < length($str))
        {
    	my $m = ord(substr($str, $i++, 1));
    	my $n = ord(substr($str, $i++, 1));
    	if ($m >= 48 && $m <= 57)
    	{
    	    $m -= 48;
    	}    
    	if ($m >= 97 && $m <= 102)
    	{
    	    $m = 10 + $m - 97;
    	}    
    	if ($n >= 48 && $n <= 57)
    	{
    	    $n -= 48;
    	}
    	if ($n >= 97 && $n <= 102)
    	{
    	    $n = 10 + $n - 97;
    	}
    	$res .= chr($m * 16 + $n);
        }
        
        $res = join("\n", split(/\r\n/, $res));
        return $res;
    }

    Печально, что силу регулярок недооценивают.
    sub hex_to_string($)
    {
    my $input_hex_data = shift;
    my $result = $input_hex_data;
    $result =~ s/([a-fA-F0-9][a-fA-F0-9])/chr(hex($1))/eg;
    return $result;
    }

    antoha_by, 07 Июля 2011

    Комментарии (24)
  5. Pascal / Говнокод #7125

    +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
    if Length(PP.curdir)<36 then
    pt:=' '+PP.curdir+' '
    else pt:=' \...'+Copy(PP.curdir,Length(PP.curdir)-30,31)+' ';
    Ptr:=PP.f_ptr;
    if PP.vol='' then PP.vol:='No Label';
    WriteString(1,cc+(40-length(pt)) div 2,pt,Pal[8]);
    WriteString(22,cc+1+(cc*(34-length(PP.vol))) div 40,'['+PP.vol+']',Pal[7]);
    if PP.vol='No Label' then  PP.vol:='';
    {if PP.empty then exit;}
    inc(ptr,sizeof(filrec)*row);
    for i:=row to n+row do begin
    if (i <PP.files) and (not PP.empty) then begin fname:=ptr^.filename;
    {if (ptr^.fileattr and 16) = 0 then StrLwr(fname);}
    if (Ptr^.fileattr and 2) <> 0 then fname[1]:=upcase(fname[1]);
    if ((Ptr^.fileattr and Hidden) <> 0) and (Pos('.',Fname)>0) then fname[Pos('.',Fname)+1]:=upcase(fname[Pos('.',Fname)+1]);
    SortFIle(fname);
    for a := length(fname) to 11 do fname:=fname+' ';
    fname:=fname+'│';
    if (Ptr^.fileattr and 16) = 0 then Str(Ptr^.filesize:10,pt)
    else if fname[1]='.' then pt:='UP──-DIR'
         else pt:='SUB─-DIR';
    fname:=fname+pt+'│';
    DateTimeCnv(pt,Ptr^.filedttm);
    fname:=fname+pt;     {SetFattr}
    if Ptr^.selected then WriteString(2+i-row,cc,fname,Pal[1]) else
    WriteString(2+i-row,cc,fname,Pal[2]);
    inc(ptr,sizeof(filrec));
    end
    else WriteString(2+i-row,cc,'            │          │        │     ',Pal[1]);
    end;
    end;
    procedure Put_File(PP:Panel;cc,row,x:word;active:boolean);
    var
    fname,pt:string;
    {ptr:P_filrec;}
    begin
    if PP.empty then exit;
    ptr:=PP.F_ptr;
    inc(ptr,sizeof(filrec)*(row+x));
    fname:=ptr^.filename;
    {if (ptr^.fileattr and 16) = 0 then StrLwr(fname);}
    if (Ptr^.fileattr and 2) <> 0 then fname[1]:=upcase(fname[1]);
    if ((Ptr^.fileattr and Hidden) <> 0) and (Pos('.',Fname)>0) then fname[Pos('.',Fname)+1]:=upcase(fname[Pos('.',Fname)+1]);
    SortFile(fname);
    for a := length(fname) to 11 do fname:=fname+' ';
    fname:=fname+'│';
    if (Ptr^.fileattr and 16) = 0 then Str(Ptr^.filesize:10,pt)
    else if fname[1]='.' then pt:='UP──-DIR'
         else pt:='SUB─-DIR';
    fname:=fname+pt+'│';
    DateTimeCnv(pt,Ptr^.filedttm);
    fname:=fname+pt;
    if active then If Ptr^.selected then WriteString(2+x,cc,fname,Pal[3]) else
    WriteString(2+x,cc,fname,Pal[4])
    else if Ptr^.selected then WriteString(2+x,cc,fname,Pal[1]) else
    WriteString(2+x,cc,fname,Pal[2])

    Файловый менеджер по-типу NC. Pascal, 7-ой класс школы. Участок формирования одной из панелей.
    PS: Вообще, это даже как-то работало: http://habrastorage.org/storage1/84736ecc/b4711597/5b1d2618/5b60c662.png

    Tronix, 01 Июля 2011

    Комментарии (24)
  6. C++ / Говнокод #7048

    +162

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    setGeometry((int)(QApplication::desktop()->width() -
    (QApplication::desktop()->width() -
      (QApplication::desktop()->width() / 2)) * 1.5) / 2,
      (int)(QApplication::desktop()->height() -
    (QApplication::desktop()->height() -
      (QApplication::desktop()->height() / 2)) * 1.5) / 2,
      (int)((QApplication::desktop()->width() -
    (QApplication::desktop()->width() / 2)) * 1.5),
      (int)((QApplication::desktop()->height() -
    (QApplication::desktop()->height() / 2)) * 1.5));

    Center app window!

    Aleskey, 24 Июня 2011

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

    +115

    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
    public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkStatus = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
    
        
        string cid = row.Cells[1].Text;
        bool status = chkStatus.Checked;
    
        
        string constr = @"Server=.\SQLEXPRESS;Database=TestDB;uid=waqas;pwd=sql;";
        string query = "UPDATE Categories SET Approved = @Approved WHERE CategoryID = @CategoryID";
            
        SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, con);
    
        
        com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
        com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = cid;
    
        
        con.Open();
        com.ExecuteNonQuery();
        con.Close();
    
        
        LoadData();
    }

    Полезный говнокод

    in4man, 23 Июня 2011

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

    +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
    function retPercByAct($num,$economy) { //50% discount => economy=0 => 15%
      $t='15/5 0-49,
      16/6 50-100,
      17/7 101-200,
      18/8 201-350,
      19/9 351-500,
      20/10 601-1000,
      21/11 1001-500000,';
      $t=explode(',',$t);
      foreach($t as $k=>$v) {
        $v=trim($v);
        list($perc,$nums)=explode(' ',$v);
        $nums=explode('-',$nums);
        if($nums[0]<=$num && $nums[1]>=$num) {
          $perc=explode('/',$perc);
          if(!$economy) $percR=$perc[0]; else $percR=$perc[1];
          break;
        }
      }
      return $percR;
    }

    Вот, встретилось в поддерживаемом мной проекте.

    segoddnja, 20 Июня 2011

    Комментарии (24)
  9. Куча / Говнокод #7002

    +131

    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
    (defparameter n 2)
    (setf middle (make-array 2 :initial-element 0))
    (defparameter v 7)
    (setf tr (make-array `(,(+ 1 n) ,n) :initial-element 4))
    (setf ftr (make-array 3 :initial-element 1))
    (defun pow (x n)
    (cond((= n 0) 1)((= n 1) x)(T (* x (pow x (- n 1))))))
    (defun f1 (x y)
    (+ (* (pow v 2) (pow x 2))
    (* (/ v (+ v 1)) x)
    (* 15 (+ v 1) (pow y 2))
    (* -1 2 v y) (* 4 v)))
    
    (defun sigma1 (a)
    (* a (/ (+ (sqrt (+ n 1)) (- n 1))
    (* n (sqrt 2))) ))
    
    (defun sigma2 (a)
    (* a (/ (+ (sqrt (+ n 1)) -1)
    (* n (sqrt 2))) ))
    
    (defun setp (a)
    (loop for i from 1 to n do
    (loop for j from 0 to (- n 1) do
    (cond
    ((= (- i 1) j) (setf (aref tr i j) (+ (aref tr 0 0) (sigma2 a))))
    (T (setf (aref tr i j) (+ (aref tr 0 1) (sigma1 a))))))))
    
    (defun evalfun ()
    (loop for i from 0 to n do
    (setf (aref ftr i) (f1 (aref tr i '0) (aref tr i '1)))
    (format t "The functions in dot ~$:~$~$" `(,(aref tr i '0) ,(aref tr i '1)) (aref ftr i) #\newline))
    (setf ftr (sort ftr #'<)))
    
    (defun midp()
    (loop for i from 0 to n do
    (cond
    ((= (aref ftr n) (f1 (aref tr i '0) (aref tr i '1)))
    (setq tp i))))
    
    (setf middle (make-array n :initial-element 0))
    (loop for i from 0 to n do
    (cond
    ((/= i tp)
    (setf (aref middle 0) (+ (aref middle 0) (aref tr i 0)))
    (setf (aref middle 1) (+ (aref middle 1) (aref tr i 1))))))
    (setf (aref middle 1) (/ (aref middle 1) 2))
    (setf (aref middle 0) (/ (aref middle 0) 2))
    (format t "The weight center in ~$,~$" (aref middle 0) (aref middle 0))
    (princ #\newline))
    
    (defun newp()
    (setf (aref tr tp 0) (- (aref middle 0) (aref tr tp 0)))
    (setf (aref tr tp 1) (- (aref middle 1) (aref tr tp 1))))
    (defun prpolinom()
    (format t "Polinom has this dots:~$" #\newline)
    (loop for i to n do
    (loop for j to (- n 1) do
    (format t "|~$|" (aref tr i j)))
    (princ #\newline)))
    
    (setq c 1)
    (defun mloop(a)
    (setp a)
    (defun subloop()
    (setq c (+ c 1))
    (setf tmiddle (make-array n :initial-element 0))
    (loop for i to (- n 1) do
    (setf (aref tmiddle i) (aref middle i)))
    (evalfun)
    (midp)
    (newp)
    (prpolinom)
    
    (cond
    ((and (= (aref tmiddle 0) (aref middle 0)) (= (aref tmiddle 1) (aref middle 1)))(mloop (/ a 2)))
    ((> a 0.01) (subloop) (format t "Iteration ~$~$" c #\newline))))
    (subloop))
    (mloop 2)

    симплекс метод на Common Lisp=)

    zura, 20 Июня 2011

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

    +171

    1. 1
    const_cast<TRefalAbstract*>(this)=new TRefal();

    Говногость, 18 Июня 2011

    Комментарии (24)
  11. Си / Говнокод #6884

    +130

    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
    MACROFIRE-MACRO 5.0.0
    
    [Info]
    Name = 
    Hotkey = 
    Repeat = 1
    
    [Macro]
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 83
    ButtonsPress = Circle
    Delay = 83
    ButtonsRelease = Circle
    Delay = 50
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Circle
    Delay = 83
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Down
    Delay = 50
    ButtonsPress = Right
    Delay = 83
    ButtonsRelease = Down
    ButtonsPress = Square
    Delay = 116
    ButtonsRelease = Right
    ButtonsRelease = Square
    Delay = 266
    ButtonsPress = RTrigger
    Delay = 83
    ButtonsRelease = RTrigger
    Delay = 50
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 83
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 49
    ButtonsPress = Circle
    Delay = 83
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Circle
    Delay = 50
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Circle
    Delay = 100
    ButtonsChange = Down
    Delay = 83
    ButtonsPress = Right
    Delay = 66
    ButtonsRelease = Down
    Delay = 100
    ButtonsPress = Triangle
    ButtonsRelease = Right
    Delay = 83
    ButtonsRelease = Triangle
    Delay = 917
    ButtonsPress = Down
    Delay = 200
    ButtonsPress = Circle
    Delay = 83
    ButtonsRelease = Circle
    Delay = 66
    ButtonsPress = Circle
    Delay = 66
    ButtonsRelease = Circle
    Delay = 83
    ButtonsPress = Circle
    Delay = 133
    ButtonsRelease = Circle
    Delay = 50
    ButtonsRelease = Down
    Delay = 83
    ButtonsPress = Left
    ButtonsPress = Up
    Delay = 166
    ButtonsChange = Left + Circle
    ButtonsRelease = Left
    Delay = 116
    ButtonsRelease = Circle

    Lambda-11 Challenge 6

    minlexx, 07 Июня 2011

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