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

    В номинации:
    За время:
  2. Куча / Говнокод #8385

    +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
    parse(Data) ->
    	io:format("~p~n", [Data]),
    	<<A:8, B:8, C/binary>> = Data,
    	FinalMark = case (bit_nth(0, A)) of 1 -> true; 0 -> false end,
    	MaskMark = case (bit_nth(0, B)) of 1 -> true; 0 -> false end,
    	Result1 = [{final, FinalMark}, {masked, MaskMark}],
    	Opcode = case <<A:4>> of
    		<<16#0:4>> -> continuation_frame;
    		<<16#1:4>> -> text_frame;
    		<<16#2:4>> -> binary_frame;
    		<<16#8:4>> -> connection_closed;
    		<<16#9:4>> -> ping;
    		<<16#a:4>> -> pong;
    		<<_:4>> -> unknown
    	end,
    	Result2 = Result1 ++ [{opcode, Opcode}],
    	<<LengthSign:7>> = <<B:7>>,
    	Length = if
    		LengthSign =< 125 ->
    			C1 = C,
    			LengthSign;
    		LengthSign == 126 ->
    			<<L0:16, C1/binary>> = C, L0;
    		LengthSign == 127 ->
    			<<L0:64, C1/binary>> = C, L0
    	end,
    	Result3 = Result2 ++ [{length, Length}],
    	case MaskMark of
    		true ->
    			<<MaskingKey0:8, MaskingKey1:8, MaskingKey2:8, MaskingKey3:8, C2/binary>> = C1,
    			MaskingKey = [MaskingKey0, MaskingKey1, MaskingKey2, MaskingKey3],
    			Result4 = Result3 ++ [{masking_key, MaskingKey}],
    			Payload = binary_to_list(C2),
    			TX = decode(Payload, lists:reverse(MaskingKey), 0, []);
    		false -> C2 = C1, Result4 = Result3,
    			Payload = binary_to_list(C2), TX = Payload
    	end,
    	Result = Result4 ++ [{msg, TX}],
    	Result.

    Пишу модуль для работы с веб-сокетами на Эрланге. Эта функция парсит и декодирует пакет, присылаемый клиентом.
    Функцию я уже переписал.

    rasufa, 01 Ноября 2011

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

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if (
    	$arItem["DEPTH_LEVEL"]==$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]>3
    	||$arItem["DEPTH_LEVEL"]<$previousLevel
    	&&$arItem["IS_PARENT"]
    	&&$arItem["DEPTH_LEVEL"]==3
    	&&$previousLevel-$arItem["DEPTH_LEVEL"]==1
    ) 
    .....

    Paranoid mode deteсted! Внимание! (Г)Код был в строку, для удобства чтения отформатировал.

    ProfBiss, 01 Ноября 2011

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

    +164

    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
    function GetDopNumbersArray($array)
    {
    				$i=0;
    		foreach ($array as $phone)
    				{
    					if($phone=="-")
    					{
    						$i++;}else
    						{
    					$dop_phones_arr[$i][]=$phone;}
    				}
    		return $dop_phones_arr;
    }

    Самый чудный способ расставления скобочек.

    alexxxnf, 31 Октября 2011

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

    +153

    1. 1
    2. 2
    3. 3
    4. 4
    $r = mysql_query("SELECT COUNT(*) FROM `TABLE`"); 
    $c = mysql_fetch_array($r); 
    $k = rand(0,$c[0]-1); 
    $r = mysql_query("SELECT * FROM `TABLE` LIMIT ".$k.",1");

    На форуме вчера увидел =) Вопрос состоял в том, чтобы вытащить из базы любое значение, рандом :D

    Dizzy221, 28 Октября 2011

    Комментарии (6)
  6. Java / Говнокод #8317

    +78

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    StringTokenizer st = new StringTokenizer(data[0][14].toString(), ",");
    String str = "";
    //int numAfPoint = 3;
    for (int k = 1; k < st.countTokens() + 3; k++) { //p
      str = st.nextToken();
      // .. 
    }

    Оригинальный обход токенов - а вдруг тройка лишних завалялась..

    nik_lazer, 27 Октября 2011

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

    +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
    19. 19
    20. 20
    21. 21
    <form action="" method=post>
         <input type="text" size="30" name=""><br><br>
         <textarea name="" rows="10" cols="40"></textarea><br> 
         <p style="font:15px sans-serif;color:#0e54a9;margin-top:5px;margin-bottom:-10px;">Антиспам:</p><br> 
         <?php 
          $i=1;
          do
          {
          $num[$i] = mt_rand(0,9);
          echo "<img src='img/".$num[$i].".jpg' border='0' align='bottom' vspace='5px'>";
          $i++;
          }
          while ($i<5);
          $captcha = $num[1].$num[2].$num[3].$num[4];
          ?>
          <br><br>
          <input name="captcha" type="hidden" value="<?php echo $captcha ;?>">
          <input name="pr" style="margin-top:-15px;margin-bottom:5px" type="text" size="9" maxlength="4"><br><br>
          <input type="submit" value="Відправити" name="submit"> 
          <input type="reset" value="Очистити" name="submit">
          </form>

    так мы рисуем капчу

    Sulik78, 26 Октября 2011

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

    +147

    1. 1
    //так как в mysql есть ограничение на джойны (61), делаем следующим образом:...

    alexoy, 26 Октября 2011

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

    +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
    QString str[5][5] = {"a", "b", "c", "d", "e",
                             "f", "g", "h", "i", "k",
                             "l", "m", "n", "o", "p",
                             "q", "r", "s", "t", "u",
                             "v", "w", "x", "y", "z"};
        QString enc, text = ui->lineEdit->text();
        int l = text.length();
        QString tmp[1][8] = {"s", "o", "m", "e", "t", "e", "x", "t"};
        for (int i = 0; i < 1; i++)
        {
            for (int j = 0; j < 9; j++)
            {
                for (int ix = 0; ix < 6; ix++)
                {
                    for (int jx = 0; jx < 6; jx++)
                    {
                        if(tmp[i][j] == str[ix][jx])
                            enc = str[ix][jx + 1];
                        ui->lineEdit_2->setText(enc);
                    }
                }
            }
        }
    }

    Такой-то квадрат Полибия!

    Mindless, 25 Октября 2011

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

    +116

    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
    <Grid Grid.Row="2" Margin="5">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                    <RowDefinition Height="auto"/>
                </Grid.RowDefinitions>
                <ContentPresenter Grid.Row="0" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[0]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[1]}"/>
                <ContentPresenter Grid.Row="0" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[2]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[3]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[4]}"/>
                <ContentPresenter Grid.Row="1" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[5]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[6]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[7]}"/>
                <ContentPresenter Grid.Row="2" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[8]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[9]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[10]}"/>
                <ContentPresenter Grid.Row="3" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[11]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[12]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[13]}"/>
                <ContentPresenter Grid.Row="4" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[14]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[15]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[16]}"/>
                <ContentPresenter Grid.Row="5" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[17]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="0" Content="{Binding ElementName=root,Path=Items[18]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="1" Content="{Binding ElementName=root,Path=Items[19]}"/>
                <ContentPresenter Grid.Row="6" Grid.Column="2" Content="{Binding ElementName=root,Path=Items[20]}"/>            
            </Grid>

    legat, 22 Октября 2011

    Комментарии (6)
  11. bash / Говнокод #8261

    −133

    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
    #!/bin/bash
    
    ps -eo pid,ppid,comm > data
    
    #treeNet[0]=1
    
    depth=0
    
    init=0
    tree()
    {
    
    #echo $1
    let depth=depth+1
    treeNet[$depth]=1
    
    for ((i=1;i<depth-1;i++))
    do
    # echo ${treeNet[$depth]}
    if [[ ${treeNet[$i]} -eq 0 ]]
    then
    echo -n " "
    fi
    if [[ ${treeNet[$i]} -eq 1 ]]
    then
    echo -n "¦ "
    fi
    
    done
    
    if [[ $init -ne 0 ]]
    then
    echo -n '¦====='
    else
    init=1
    fi
    #let depth=depth+1
    # treeNet[depth]=1
    #prints process name
    echo $(cat data | awk '{ if ($1 == '$1') print $3}' )
    
    
    #printing branches
    local count=0 #amount of child branches
    for i in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
    do
    let count=count+1
    #echo $i
    done
    
    #recursive call tree()
    local n=0;
    for child in $(cat data | awk ' {if ($2 == '$1' ) print $1 } ')
    do
    
    let n=n+1
    # echo -n " # child no $n of $count depth $depth debug ${treeNet[1]} ${treeNet[2]} ${treeNet[3]} ${treeNet[4]}"; 
    if [[ $n -eq $count ]]
    then
    #echo -n " last " 
    treeNet[$depth]=0
    fi
    # echo
    # let n=n+1
    tree $child
    done
    treeNet[$depth]=0
    
    let depth=depth-1
    return 0
    }
    
    
    tree 1

    kurganec, 21 Октября 2011

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