1. PHP / Говнокод #7187

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if ($category) {
            $api_categories = $category['api_categories'];
            $params['categories'] = $category['api_categories'];
    } else {
        $api_categories = array();
        foreach ($categories as $category_data) {
            $api_categories = array_merge($api_categories, $category_data['api_categories']);
        }
    }
            
    $params['categories'] = $api_categories;

    Вот нафигачил то

    striker, 07 Июля 2011

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

    +955

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    static string foo()
            {
                int i = 0;
                //code
                return "some string "+ i++;
            }

    Irdis, 07 Июля 2011

    Комментарии (49)
  3. Assembler / Говнокод #7185

    +151

    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
    PROCEDURE StartMusic (Song : POINTER; Polling, OldIRQ : BOOLEAN); ASSEMBLER;
      ASM
        MOV  AH,0
        MOV  BL,Polling
        MOV  BH,OldIRQ
        CMP  BH,1
        JE   @Invert
        MOV  BH,1
        JMP  @GoOn
      @Invert:
        XOR  BH,BH
      @GoOn:
        LES  SI,DWORD PTR Song
        CALL _HscPlayer
      END;

    Нашел в HSC-TRACKER V1.5, файл playhsc.pas. Оригинальная инверсия булевого значения - true на false и наоборот.
    Для не знающих ассемблера:

    if (OldIRQ == 1)
    OldIRQ = 0
    else
    OldIRQ = 1;
    Реализуется куда проще:
    OldIRQ ^= 1;

    DemonId7, 06 Июля 2011

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

    +168

    1. 1
    if(!(!isset($_GET['email']) || $_GET['email']!='')){

    Используем закон двойного отрицания и закон деморгана

    Esr, 06 Июля 2011

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

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function AdminMain()
    {
    	global $config, $user, $site, $db; // $user, $site и $db используются в подпрограммах.
    
    	if(isset($_GET['exe']) && $_GET['exe'] == 'exit'){
    		$user->UnsetCookie('admin');
    		GO(Ufu('index.php'));
    	}elseif(!isset($_GET['exe'])){
    		$exe = 'adminpanel';
    	}else{
    ...
    }

    из LinkorCMS...

    invision70, 06 Июля 2011

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function bark($msg) {
      stdhead();
      stdmsg("Удаление торрента!", $msg);
      stdfoot();
      exit;
    }

    TBDev v 3.1 Ru. Лично меня функция повеселила, не знаю как вас) Подобное часто встречается..

    invision70, 06 Июля 2011

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $send = mysql_query("INSERT INTO comments VALUES(NULL,'$postid','$text','$name','$email','$date')");
    
    if ($send == 'true')
    {
    ....
    }

    Еще кусок из Light CMS

    invision70, 06 Июля 2011

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

    +156

    1. 1
    2. 2
    $postid = htmlspecialchars($_POST['postid']);
    mysql_query("UPDATE posts SET comments = comments + 1 WHERE id = $postid");

    Кусок из Light CMS :)

    invision70, 06 Июля 2011

    Комментарии (4)
  9. ActionScript / Говнокод #7179

    −106

    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
    public function Rotate():void
    		{
    			switch(type)
    			{
    				case 'line':
    					if (figure[0][1])
    					{
    						figure = [[1], [1], [1], [1]];
    						position.y += 1;
    						position.x -= 1;
    					}
    					else
    					{
    						figure = [[1, 1, 1, 1]];
    						position.y -= 1;
    						position.x += 1;
    					}
    					break;
    				case 'square':
    					return;
    					break;
    				case 'pyramide':
    					if (!figure[0][0] && figure[1][0] && figure.length == 2)
    					{
    						figure = [[0, 1], [1, 1], [0, 1]];
    					}
    					else if (!figure[0][0] && figure[0][1] && figure.length == 3)
    					{
    						figure = [[1, 1, 1], [0, 1, 0]];
    					}
    					else if (figure[0][0] && figure[0][1] && figure.length == 2)
    					{
    						figure = [[1, 0], [1, 1], [1, 0]];
    					}
    					else if (figure[0][0] && !figure[0][1] && figure.length == 3)
    					{
    						figure = [[0, 1, 0], [1, 1, 1]];
    					}
    					break;
    				case 'lL':
    					if (figure[0][0] && !figure[0][1])
    						figure = [[0, 0, 1], [1, 1, 1]];
    					else if (!figure[0][0] && !figure[0][1])
    						figure = [[1, 1], [0, 1], [0, 1]];
    					else if (figure[0][0] && figure[0][1] && figure.length == 3)
    						figure = [[1, 1, 1], [1, 0, 0]];
    					else if (figure[0][0] && figure[0][1] && figure.length == 2)
    						figure = [[1, 0], [1, 0], [1, 1]];
    					break;
    				case 'rL':
    					{
    					if (!figure[0][0] && figure[0][1])
    						figure = [[1, 0, 0], [1, 1, 1]];
    					else if (figure[0][0] && !figure[0][1])
    						figure = [[1, 1], [1, 0], [1, 0]];
    					else if (figure[0][0] && figure[0][1] && figure.length == 3)
    						figure = [[1, 1, 1], [0, 0, 1]];
    					else if (figure[0][0] && figure[0][1] && figure.length == 2)
    						figure = [[0, 1], [0, 1], [1, 1]];
    					}
    					break;
    				case 'lZ':
    					if (figure[0][0] && !figure[0][1])
    						figure = [[0, 1, 1], [1, 1, 0]];
    					else if (!figure[0][0] && figure[0][1])
    						figure = [[1, 0], [1, 1], [0, 1]];
    					break;
    				case 'rZ':
    					if (!figure[0][0] && figure[0][1])
    						figure = [[1, 1, 0], [0, 1, 1]];
    					else if (figure[0][0] && figure[0][1])
    						figure = [[0, 1], [1, 1], [1, 0]];
    					break;
    			}
    		}

    "Поворот" фигур в тетрисе

    KirAmp, 06 Июля 2011

    Комментарии (14)
  10. Pascal / Говнокод #7178

    +98

    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
    function Prime (N: longword): boolean;
    var
    	i : longword;
    	Max : single;
    begin
    	if N = 2
    		then Prime := true
    	else if (N <= 1) or (N mod 2 = 0)
    		then Prime := false
    	else begin
    		Prime := true;
    		i := 3; Max := sqrt(N);
    		while i <= Max do begin
    			if N mod i = 0 then begin
    				Prime := false; 
    				exit
    			end;
    			i := i + 2
    		end
    	end
    end;
    
    var
    	a, i : longword;
    
    begin
    	read(a);
    	for i := 2 to a do
    		if Prime(i)
    			then writeln(i, ' is a prime number');
    end.

    Нахождение простых чисел.

    sunshinelf, 06 Июля 2011

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