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

    +113

    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
    #include <stdio.h>
     
    int main()
    {
            void say_hello()
            {
                    puts("Hello govnokod!");
            }
     
            say_hello();
    
    	return 0;
    }

    http://ideone.com/QZipp

    rat4, 11 Июля 2012

    Комментарии (78)
  2. JavaScript / Говнокод #11397

    +156

    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
    var renderHours = function(s){
            var html = '<ul>';
            var json = Ext.decode(s);
            for(i in json)
                if(typeof json[i].from_d != 'undefined')
                    html += '<li>с <b>'
                        + hours[json[i].from_d][1]
                        + '</b> -  по <b>'
                        + hours[json[i].to_d][1]
                        + '</b> ('
                        + json[i].from_h +':'+ json[i].from_m +'-'
                        +json[i].to_h +':'+ json[i].to_m +')</li>';
                
            return html+'</ul>';
        };

    Вот такое попалось

    Sulik78, 11 Июля 2012

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

    +56

    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
    <html>
    <head>
    <style>
       body{
        background-color: #3366CC; /* Цвет фона веб-страницы */
       }
    </style>
    </head>
    <body>
    <?php
    	/*error_reporting(E_ALL);*/
    	class Mirror{
    		public $sizeX;
    		public $sizeY;
    		public $filenameI;
    		public $filenameO;
    		public $red;
    		public $green;
    		public $blue;
    		public $alpha;
    		function __construct($f){
    			$this->filenameI=$f.".png";
    			$this->filenameO=$f."2.png";
    			$size=getimagesize($this->filenameI);
    			$this->sizeX=$size[0];
    			$this->sizeY=$size[1];
    		}
    		function saveImg(){
    			if(!file_exists($this->filenameO)){
    				$xx=$this->sizeX;
    				$yy=($this->sizeY)*2;
    				$im = imagecreatetruecolor($xx, $yy);
    				imageAlphaBlending($im, false);
    				imageSaveAlpha($im, true);
    				for($x=0;$x<$xx;$x++){
    					for($y=0;$y<$yy;$y++){
    						$r=$this->red[$x][$y];
    						$g=$this->green[$x][$y];
    						$b=$this->blue[$x][$y];
    						$alph=$this->alpha[$x][$y];
    						$color=ImageColorAllocateAlpha($im, $r, $g, $b, $alph);
    						imagesetpixel($im, $x, $y, $color);
    					}
    				}
    				imagepng($im, $this->filenameO);
    				imagedestroy($im);
    			}
    			echo "<img src=\"".$this->filenameI."\" /><hr>\n";
    			echo "<img src=\"".$this->filenameO."\" /><br>\n";
    		}
    		function loadImg(){
    			$im = imagecreatefrompng($this->filenameI);
    			for($x=0;$x<$this->sizeX;$x++){
    				for($y=0;$y<$this->sizeY;$y++){
    					$rgb = imagecolorat($im, $x, $y);
    					$color=imagecolorsforindex($im, $rgb);
    					$this->red[$x][$y]=$color['red'];
    					$this->green[$x][$y]=$color['green'];
    					$this->blue[$x][$y]=$color['blue'];
    					$this->alpha[$x][$y]=$color['alpha'];
    				}
    			}
    			imagedestroy($im);
    		}
    		function createMirror(){
    			if(!file_exists($this->filenameO)){
    				$yy=($this->sizeY*2);
    				for($x=0;$x<$this->sizeX;$x++){
    					$alph=0;
    					for($y=$this->sizeY;$y<$yy;$y++){
    						if($alph<126){
    							$alph++;
    						}
    						$this->red[$x][$y]=$this->red[$x][$this->sizeY-($y-$this->sizeY)-1];
    						$this->green[$x][$y]=$this->green[$x][$this->sizeY-($y-$this->sizeY)-1];
    						$this->blue[$x][$y]=$this->blue[$x][$this->sizeY-($y-$this->sizeY)-1];
    						$this->alpha[$x][$y]=$alph+$this->alpha[$x][$this->sizeY-($y-$this->sizeY)-1];
    						if($this->alpha[$x][$y]>127) $this->alpha[$x][$y]=127;
    					}
    				}
    			}
    		}
    	}
    	$filename="alpha";
    	$mirror=new Mirror($filename);
    	$mirror->loadImg();
    	$mirror->createMirror();
    	$mirror->saveImg();
    ?>
    </body>
    </html>

    Делал для одного сайта зеркальное отражение картинки (photoshop использовать не умеем-с). Почему-то сервер часто падал.
    Как оно работает, можно посмотреть здесь http://xcont.com/perc/newperceptron/cell/mirror.php

    xcont, 11 Июля 2012

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

    +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
    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
    // Получение имени выполняемого метода, вызывать можно только из Published-методов класса.
    // Для обычных методов: FindClassMethodNames(ClassType()), для статических методов FindClassMethodNames(self).
    {$optimization OFF}
    function FindClassMethodNames(obj: TClass): string;
    var _AdrPtr: Pointer;
    begin
      asm
        mov eax, obj
        mov edx, dword ptr [esp + 272]
        push ebx
        push esi
        push edi
        push $7FFFFFFF
        xor edi, edi
        jmp @@haveVMT
       @@outer:
        mov eax, dword ptr [eax]
       @@haveVMT:
        mov esi, dword ptr [eax].vmtMethodTable
        test esi, esi
        je @@parent
        movzx ecx, word ptr [esi]
        add esi, 2
       @@inner:
        pop ebx
        push edx
        sub edx, dword ptr [esi + 2]
        jl @@no1
        cmp edx, ebx
        jg @@no1
        mov ebx, edx
        mov edx, dword ptr [esi + 2]
        mov edi, edx
       @@no1:
        pop edx
        push ebx
        movzx ebx, word ptr [esi]
        add esi, ebx
        dec ecx
        jnz @@inner
       @@parent:
        mov eax, dword ptr [eax].vmtParent
        test eax, eax
        jne @@outer
        mov _AdrPtr, edi
        pop edi
        pop esi
        pop ebx
      end;
      Result := obj.MethodName(_AdrPtr);
    end;
    {$optimization ON}
    
    // пример использования
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(FindClassMethodNames(ClassType()));
    end;

    А есть нормальный способ получить имя выполняемого метода, и строку кода заодно?

    ctm, 11 Июля 2012

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

    +155

    1. 1
    element.data('selected') ? element.show() : $.noop();

    Либо человек из ассемблера пришел, либо "IF" сильно ему по жизни насолил.

    InnerJoin, 11 Июля 2012

    Комментарии (18)
  6. Куча / Говнокод #11393

    +124

    1. 1
    2. 2
    http://habrahabr.ru/post/147484/
    Я просто оставлю это здесь.

    Fai, 10 Июля 2012

    Комментарии (94)
  7. Си / Говнокод #11392

    +141

    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
    int main()
      {
        int i = 0;
        goto A;
        for (;i<3; ++i)
        L:{
            {
              int x;
              x += i;
              if (0) { A: x = 0; goto B; }
              printf("X: %d ",x);
            }
            {
              int y;
              y -= i;
              if (0) { B: y = 10; goto L; }
              printf("Y: %d\n",y);
            }
          }
      }

    Отсюда: http://rsdn.ru/forum/cpp/4812647.flat.aspx Автор походу уверен в гениальности кода.

    slavap, 10 Июля 2012

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

    +24

    1. 1
    2. 2
    3. 3
    Fixed f = 0.2;
    	f = std::abs(f);
    	std::cout << (float)f;

    Угадайте, чему будет равно f?
    Fixed - тип из той же библиотеки, что и в http://govnokod.ru/11294

    TarasB, 10 Июля 2012

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

    +129

    1. 1
    return GetByteArray((Object)obj);

    На всякий случай.

    Em1ss1oN, 10 Июля 2012

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

    +119

    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
    /**
     * Imbues the given {@link Font} with support for fallback fonts,
     * needed to display CJK characters in fonts that do not support them.
     * 
     * This is an ugly mess that depends on internal Sun APIs. Use sparingly!
     *
     * @param font the font
     * @return the composite font UI resource
     */
    public static FontUIResource getCompositeFontUIResource(final Font font) {
    	try {
    		Class<?> klass;
    		
    		try {
    			// Java 7
    			klass = Class.forName("sun.font.FontUtilities");
    		} catch (final ClassNotFoundException e) {
    			// Java 6
    			klass = Class.forName("sun.font.FontManager");
    		}
    		
    		// Invoke static method that wraps the font
    		val method = klass.getMethod("getCompositeFontUIResource", Font.class);
    		return (FontUIResource) method.invoke(null, font);
    	} catch (final ClassNotFoundException e) {
    		// Long block of catches that cannot happen on a Sun JRE
    		throw new AssertionError(e);
    	} catch (final IllegalAccessException e) {
    		throw new AssertionError(e);
    	} catch (final IllegalArgumentException e) {
    		throw new AssertionError(e);
    	} catch (final InvocationTargetException e) {
    		throw new AssertionError(e);
    	} catch (final NoSuchMethodException e) {
    		throw new AssertionError(e);
    	} catch (final SecurityException e) {
    		throw new AssertionError(e);
    	}
    }

    someone, 10 Июля 2012

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