1. Си / Говнокод #10046

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if(selected == 3){
         if(count == 1){
              displayIntResult(0);
         }else{
              if(count == 1){
                   displayIntResult(0);
              }else{
               // код
              }
        }
         // код
    }

    Надо больше спать. Обнаружено после ночи кодинга

    denis90, 26 Апреля 2012

    Комментарии (1)
  2. VisualBasic / Говнокод #10045

    −92

    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
    Sub Ìàêðîñ1()
      Sheets("Îò÷åò_Âêë.1_15-98").Select
        For i = 0 To 25 Step 1
            Sheets(Sheets.Count).Select
            If i = 0 Then
                Range("A:A, B:B").Select
            ElseIf i = 1 Then
                Range("A:A, C:C").Select
            ElseIf i = 2 Then
                Range("A:A, D:D").Select
            ElseIf i = 3 Then
                Range("A:A, E:E").Select
            ElseIf i = 4 Then
                Range("A:A, F:F").Select
            ElseIf i = 5 Then
                Range("A:A, G:G").Select
            ElseIf i = 6 Then
                Range("A:A, H:H").Select
            ElseIf i = 7 Then
                Range("A:A, I:I").Select
            ElseIf i = 8 Then
                Range("A:A, J:J").Select
            ElseIf i = 9 Then
                Range("A:A, K:K").Select
            ElseIf i = 10 Then
                Range("A:A, L:L").Select
            ElseIf i = 11 Then
                Range("A:A, M:M").Select
            ElseIf i = 12 Then
                Range("A:A, N:N").Select
            ElseIf i = 13 Then
                Range("A:A, O:O").Select
            ElseIf i = 14 Then
                Range("A:A, P:P").Select
            ElseIf i = 15 Then
                Range("A:A, Q:Q").Select
            ElseIf i = 16 Then
                Range("A:A, R:R").Select
            ElseIf i = 17 Then
                Range("A:A, S:S").Select
            ElseIf i = 18 Then
                Range("A:A, T:T").Select
            ElseIf i = 19 Then
                Range("A:A, U:U").Select
            ElseIf i = 20 Then
                Range("A:A, V:V").Select
            ElseIf i = 21 Then
                Range("A:A, W:W").Select
            ElseIf i = 22 Then
                Range("A:A, X:X").Select
            ElseIf i = 23 Then
                Range("A:A, Y:Y").Select
            ElseIf i = 24 Then
                Range("A:A, Z:Z").Select
            ElseIf i = 25 Then
                Range("A:A, AA:AA").Select
            End If
            Selection.Copy
            Sheets.Add
            Sheets(Sheets.Count - 1).Select
            Columns("A:A").Select
            ActiveSheet.Paste
        Next i
    End Sub

    Макрос для копирования подряд расположенных столбцов на отдельные листы

    usstass, 25 Апреля 2012

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

    +89

    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
    function uIsCommentAllowed($id_all)
    	{
    		$db = 'i_all';
    		$this->db->select('comment');
    		$this->db->where('id_all',$id_all);
    		$query = $this->db->get($db);
    		if ($query->num_rows() == 0) return false;
    		else 
    		{
    			$row = $query->row();
    			if ($row->comment == 1) return true;
    			if ($row->comment == 1) return false;
    		}	
    		return false;
    	}

    Кто не видит где говно, показываю: if ($row->comment == 1) return true; if ($row->comment == 1) return false;
    Теперь главный вопрос - почему на при тестировании данная ошибка не проявляется, и все вообще работает верно?

    increazon, 25 Апреля 2012

    Комментарии (31)
  4. Куча / Говнокод #10040

    +99

    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
    import Text.Parsec
    import Control.Monad
    
    romanToArabic :: String -> Either ParseError Integer
    romanToArabic = parse (genParser (Nothing : Nothing : map Just romans)) "" where
    
        romans = [('M', 1000), ('D', 500), ('C', 100),
                  ('L', 50), ('X', 10), ('V', 5), ('I', 1)]
    
        genParser [_] = eof >> return 0
        genParser (ten : five : one : rest) = state1 where
    
            state1 = choice [on one state2, on five state3, next]
            state2 = choice [on (sub2 five one) next, on (sub2 ten one) next,
                             on one state5, next]
            state3 = choice [on one state4, next]
            state4 = choice [on one state5, next]
            state5 = choice [on one next, next]
            next = genParser (one : rest)
    
            on Nothing _ = fail ""
            on (Just (ch, val)) nextNode = char ch >> nextNode >>= return . (+val)
    
            sub2 = liftM2 $ \(ch1, val1) (ch2, val2) -> (ch1, val1-2*val2)

    Кучка в ответ на http://govnokod.ru/9995#comment136058

    > с другой стороны раз хаскель, то хотелось бы, например:
    > *Main> romanToArabic "LC"
    > Left (line 1, column 2):
    > unexpected 'C'
    > expecting "X", "IX", "IV", "V", "I" or end of input

    bormand, 25 Апреля 2012

    Комментарии (19)
  5. Python / Говнокод #10039

    −94

    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
    #*тут определение факториала*
    
    fac_missing_end = factorial(100)/1000000000000000000000000
    
    #there are 134 digits when you take off the zeroes at the end
    
    sum_of_digits = 0
    
    recent_digit = fac_missing_end%10
    new_fac = fac_missing_end/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    recent_digit = new_fac%10
    new_fac = new_fac/10
    sum_of_digits = sum_of_digits + recent_digit
    
    # еще пару десятков строк такого говна
    
    print sum_of_digits

    http://projecteuler.net/problem=20
    http://projecteuler.net/thread=20;page=8


    >This is ridiculous, but it worked instantaneously
    Первый шаг к решению проблемы — признать что у тебя есть проблема.

    TheHamstertamer, 25 Апреля 2012

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

    +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
    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
    class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher {
        function get($url, $extra_headers = null)
        {
        /* неcущественное пропущено */
                if (defined('CURLOPT_NOSIGNAL')) {
                    curl_setopt($c, CURLOPT_NOSIGNAL, true);
                }
    
                if (!$this->allowedURL($url)) {
                    Auth_OpenID::log("Fetching URL not allowed: %s",
                                     $url);
                    return null;
                }
    
                curl_setopt($c, CURLOPT_WRITEFUNCTION,
                            array($this, "_writeData"));
                curl_setopt($c, CURLOPT_HEADERFUNCTION,
                            array($this, "_writeHeader"));
    
                if ($extra_headers) {
                    curl_setopt($c, CURLOPT_HTTPHEADER, $extra_headers);
                }
    
                $cv = curl_version();
                if(is_array($cv)) {
                  $curl_user_agent = 'curl/'.$cv['version'];
                } else {
                  $curl_user_agent = $cv;
                }
                curl_setopt($c, CURLOPT_USERAGENT,
                            Auth_OpenID_USER_AGENT.' '.$curl_user_agent);
                curl_setopt($c, CURLOPT_TIMEOUT, $off);
                curl_setopt($c, CURLOPT_URL, $url);
    
                if (defined('Auth_OpenID_VERIFY_HOST')) {
                    // set SSL verification options only if Auth_OpenID_VERIFY_HOST
                    // is explicitly set, otherwise use system default.
                    if (Auth_OpenID_VERIFY_HOST) {
                        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
                        curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
                        if (defined('Auth_OpenID_CAINFO')) {
                            curl_setopt($c, CURLOPT_CAINFO, Auth_OpenID_CAINFO);
                        }
                    } else {
                        curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
                    }
                }
    
                curl_exec($c);
        /* неинтересное пропущено */
        }
        
        function post($url, $body, $extra_headers = null)
        {
            if (!$this->canFetchURL($url)) {
                return null;
            }
    
            $this->reset();
    
            $c = curl_init();
    
            if (defined('CURLOPT_NOSIGNAL')) {
                curl_setopt($c, CURLOPT_NOSIGNAL, true);
            }
    
            curl_setopt($c, CURLOPT_POST, true);
            curl_setopt($c, CURLOPT_POSTFIELDS, $body);
            curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
            curl_setopt($c, CURLOPT_URL, $url);
            curl_setopt($c, CURLOPT_WRITEFUNCTION,
                        array($this, "_writeData"));
    
            if (defined('Auth_OpenID_VERIFY_HOST')) {
                // set SSL verification options only if Auth_OpenID_VERIFY_HOST
                // is explicitly set, otherwise use system default.
                if (Auth_OpenID_VERIFY_HOST) {
                    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
                    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
                    if (defined('Auth_OpenID_CAINFO')) {
                        curl_setopt($c, CURLOPT_CAINFO, Auth_OpenID_CAINFO);
                    }
                } else {
                    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
                }
            }
    
            curl_exec($c);
    /* to be continued */

    Фрагмент едва ли не самой популярной библиотеки OpenID, а именно клиентской части: http://janrain.com/openid-enabled/
    Всё бы было хорошо, но залогиниться, используя лайвджорналовский опенайдишник, не получается. По форумам поползли слухи, что ЖЖ не полностью поддерживает протокол OpenID (хотя протокол разработал Фицпатрик, один из создателей LiveJournal); что он метод POST не поддерживает, поэтому его нужно менять на GET; предлагались совершенно безумные хаки, которые на самом деле не работают...

    А ларчик просто открывался. Для поддержки ЖЖ достаточно в приведённый код добавить пару строк. Открыть спойлер или кто-нибудь угадает?

    inkanus-gray, 25 Апреля 2012

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

    +160

    1. 1
    2. 2
    3. 3
    4. 4
    function someFunction(t) {
        var y="$('#elementID').find('input[type=\"text\"]:eq(", z=")').focus()", x=")').val()==''";
        setTimeout("( "+y+"0"+x+" )? ( "+y+"0"+z+" ):( ( "+y+"1"+x+" )? ( "+y+"1"+z+" ):( "+y+"2"+z+" ) );", t);
    }

    это какое-то нечто

    bot, 25 Апреля 2012

    Комментарии (3)
  8. Pascal / Говнокод #10036

    +92

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    function lz_UploadMount:boolean;
    var del_l,i,j,k,ng,l,typ:integer;
        pt:array[1..3]of integer;
    begin
    UpDiag:=0;
    result:=true;
    if I_AM_EMUL {or not I_AM_MAIN }then exit;
    if Pult[1].Count+Pult[2].Count=0 then exit;
    lg_UploadMount;
                         //  exit;
    UpDiag:=1;
    result:=false;
    __UPLOADING:=true;
    try
    
    if not JustC(21,[])then exit;
    sleep(1000);
    //if (Pult[1].Count>0)and(Pult[2].Count>0)then ng:=3 else ng:=1;
    //if not JustC(25,[ng])then exit;;
    
    if not JustC(22,[])then exit;;
    {группы}
    if (Pult[1].Count>0)and(Pult[2].Count>0)then ng:=2 else ng:=1;
    
    for i:=1 to 2 do
     begin
     if Pult[i].Count=0 then continue;
     k:=0;
     for j:=1 to 3 do pt[j]:=MainShow.Params[j];
    
     for j:=0 to Pult[i].Count-1 do
      with TMotor(Pult[i][j])do
       begin
       k:=k+(1 shl (ConvertTP(TP)-1));
       for L:=1 to 3 do if pt[L]>GParam(L)then pt[L]:=GParam(L);
       end;
     //маска
     AddI(k);
    
     //скорость
     AddSpeed(round(pt[1]*KOREDV));
    
     //ускорение разгона
     //ускорение торможения
     AddI((pt[2]shl 16)+pt[3]);
    
     //номер джойстика
     //функциональная клавиша
          {Кнопка}  {Джойстик}{повторы}  {тип группы}
     typ:=2;
     AddI((i shl 6)+(i shl 3)+(1 shl 10)+typ);
     end;
    if not lz_Command(26,4,ng,[ng])then exit;;
    CheckMountEffect;
    
    {моторы}
    lzData.Clear;
    for i:=1 to 2 do
     for j:=0 to Pult[i].Count-1 do
      with TMotor(Pult[i][j])do
       begin
       if md_targ<0 then AddI((17 shl 16)+ConvertTP(TP))else AddI((18 shl 16)+ConvertTP(TP));
       if md_targ<GetMotorInfo(TP,1)then del_l:=-1 else del_l:=1;
    
       if md_targ<0 then
        begin
         AddI(-trunc(GParam(5)/KORED*65536));
         AddI(-trunc(GParam(4)/KORED*65536));
        end
       else
        begin
        AddI(-trunc((md_targ+del_l/2)/KORED*65536));
        AddSpeed(round(md_way*KOREDV));
        end
       end;
    if not lz_Command(28,3,Pult[1].Count+Pult[2].Count,[Pult[1].Count+Pult[2].Count])then exit;
    UpDiag:=2;
    if not JustC(23,[])then exit;
    (*EnterCriticalSection(csJoystick);
    j_Changed:=true;
    {J_Status[1]:=false;
    J_Status[2]:=false;}
    LastSign[1]:=-1;
    LastSign[2]:=-1;
    LeaveCriticalSection(csJoystick);*)
    
    {if(Pult[1].Count>0)then if not JustC(36,[1,1])then exit;
    if(Pult[2].Count>0)then if not JustC(36,[2,1])then exit;}
    UpDiag:=0;
    result:=true;
    Uploaded:=true;
    for i:=1 to 12 do
     FirstGr[i]:=0;
    
    finally
    
    __UPLOADING:=false;
    if Uploaded then WaitZero;
    end;
    end;

    Случайно открыл свою первую рабочую программу. Забавно, как со временем меняется стиль программирования :)

    В той что используется сейчас изменился протокол, так что прямого аналога нет, но примерно ту же функцию выполняет такой кусок:
    ----------------
    procedure TMotion.GetTargetForPLC(M: TMotor; Mo: TNormalMotionData);
    var
    Conf: TMotorConfig;
    ME: TElementMark;
    I: Integer;
    Ht, SP: Real;
    begin
    if not Uploaded then
    exit;
    Conf := PLCConf.Motor(M.MotorNumber);
    ME := Mark.ElementByMotor(M.MotorNumber);

    SP := Panel.GetValue(Speed);
    // Проверка разрешений движения
    if (Panel.GetStatus <> psGo) or (not Condition.CheckMotion) or FailedSafe or
    (SP = 0) or (not ME.CheckMotion) then
    Mo.CommandID := mcStop
    else
    Mo.CommandID := mcGo;

    Mo.Accel := LimitVal(1, Conf.MotorTyp.ProgramToDrive(ktAccel,
    Limits.GetParam(TAccelParam).Minimum));
    Mo.Deccel := LimitVal(1, Conf.MotorTyp.ProgramToDrive(ktAccel,
    Limits.GetParam(TDeccelParam).Minimum));

    if SP >= 0 then
    Ht := Effect.OutputTarget(M)
    else
    Ht := ME.GetTargetForPLC(false);

    // M.StartPos.Value := 0.5;

    if M.PositionType.InheritsFrom(TAngleWithTu rnsParam) then
    Ht := M.HackCircleTarget(Ht);

    Mo.Target := Conf.MotorTyp.ProgramToDrive(ktTarget, Ht);

    Mo.Speed := Conf.MotorTyp.ProgramToDrive(ktSpeed, abs(SP)); { }{ }{ }
    Mo.Time := 0;
    if SP >= 0 then
    Effect.ProcessCommand(M, Mo);

    Mo.Mask := M.Children + [M.MotorNumber];
    for I in Mo.Mask do
    GetMotor(I).RawCommand := Mo;
    end;
    ----------------

    kipar, 25 Апреля 2012

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

    −85

    1. 1
    [self.navigationItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:[(TANavigationBar *)self.navigationController.navigationBar backButtonWith:[UIImage imageNamed:@"ActivityNavBackButtonBackground"] highlight:nil leftCapWidth:30.0f]] autorelease]];

    Однако, это печально :(
    И не индус вроде

    dove06, 25 Апреля 2012

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

    +132

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    // Asynchronously load the DXF.
    // While we're doing that, the data can change, so we should guard against it.
    new WebappResourceLoader().loadResource(ResourceType.DXF, sDxfName + ".dxf",
    	new ResourceCallback<List<String>>() {
    		@Override
    		public void onSuccess(final List<String> result) {
    			if (!sDxfName.equals(dxfToLoad)) {
    				// Too slow, dude.
    				return;
    			}

    someone, 25 Апреля 2012

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