1. JavaScript / Говнокод #8236

    +164

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function trim(s)
    {
        var i,j;
        for (i = 0; i < s.length && s.charAt(i) == " "; i++);
        for (j = s.length-1; j >= 0 && s.charAt(j) == " "; j--);
        if (i<=j)
            return s.substring(i, j+1);
        else
            return '';
    }

    opzab, 19 Октября 2011

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

    +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
    protected function paperSizeOrientationValidator(p_printpropertiesobj:Object):Boolean
          	{
          		var ret_val:Boolean = (p_printpropertiesobj.printJob.paperWidth == _printPaperTab.paperWidth * PRINT_DPI &&
    		 			p_printpropertiesobj.printJob.paperHeight == _printPaperTab.paperHeight * PRINT_DPI)
    		 			||
    					(p_printpropertiesobj.printJob.paperHeight == _printPaperTab.paperWidth * PRINT_DPI &&
    		 			p_printpropertiesobj.printJob.paperWidth == _printPaperTab.paperHeight * PRINT_DPI)
    		 			|| 
    		 			((p_printpropertiesobj.printJob.paperWidth > _paperPrintMarginLow * _printPaperTab.paperWidth * PRINT_DPI && p_printpropertiesobj.printJob.paperWidth < _paperPrintMarginHigh * _printPaperTab.paperWidth * PRINT_DPI) &&  
    		 			(p_printpropertiesobj.printJob.paperHeight > _paperPrintMarginLow * _printPaperTab.paperHeight * PRINT_DPI && p_printpropertiesobj.printJob.paperHeight < _paperPrintMarginHigh * _printPaperTab.paperHeight * PRINT_DPI))
    		 			||
    		 			((p_printpropertiesobj.printJob.paperHeight > _paperPrintMarginLow * _printPaperTab.paperWidth * PRINT_DPI && p_printpropertiesobj.printJob.paperHeight < _paperPrintMarginHigh * _printPaperTab.paperWidth * PRINT_DPI) &&  
    		 			(p_printpropertiesobj.printJob.paperWidth > _paperPrintMarginLow * _printPaperTab.paperHeight * PRINT_DPI && p_printpropertiesobj.printJob.paperWidth < _paperPrintMarginHigh * _printPaperTab.paperHeight * PRINT_DPI))
          		
          		return ret_val;
          	}

    This is actually ActionScript. An unknown former colleague was trying to "validate paper orientation" before sending the page to the printer...

    bot225, 19 Октября 2011

    Комментарии (1)
  3. Си / Говнокод #8234

    +147

    1. 1
    signed bool

    ohlol, 18 Октября 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    void swap(word& w)
    {
         w=w<<8|w>>8;
    };

    И так, стартует конкурс "самый красивый swap". Жду ваши варианты. Призов не будет, так чисто пожрать.

    ohlol, 18 Октября 2011

    Комментарии (33)
  5. C# / Говнокод #8231

    +952

    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
    namespace AppendStrinAtBegin
    {
        class Program
        {
            static void ProcessDirectory(string path, string fileMask, Action<string> action)
            {
                Directory.EnumerateFiles(path, fileMask).ToList().ForEach(action);
                Directory.EnumerateDirectories(path).ToList().ForEach
                    (
                        subDirectory => ProcessDirectory(subDirectory, fileMask, action)
                    );
            }
    
            static void Main(string[] args)
            {
                Console.WriteLine("Path FileMask AppendedString");
                if (args.Length < 3)
                    return;
                var appendedString = args.Skip(2).Aggregate((workingSentence, next) => workingSentence+ " " +next);
                ProcessDirectory(args[0], args[1], (file) => ProcessFile(file, appendedString));
                Console.WriteLine("Gun done");
            }
    
            static void ProcessFile(string file, string appendedStringAtBegin)
            {
                var fileLines = File.ReadAllLines(file, Encoding.GetEncoding(1251));
                var fileResulted = fileLines.ToList();
                fileResulted.Insert(0, appendedStringAtBegin);
                File.WriteAllLines(file, fileResulted, Encoding.GetEncoding(1251));
            }
        }
    }

    ohlol, 18 Октября 2011

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

    +85

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    try {
    	   keySpec = new PBEKeySpec(s.toCharArray());
    	   tempKey = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
         } catch (InvalidKeySpecException i) {}
    
    if(tempKey == null) {
          keySpec = new PBEKeySpec(s.toCharArray());
          tempKey = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec);
    }

    Будь настойчив и не сдавайся!!!!

    kibberpunk, 18 Октября 2011

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

    +122

    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
    for (int y = 0; y < bmp.Height; y++)
            {
                for (int x = 0; x < bmp.Width; x++)
                {
                    Color col = bmp.GetPixel(x, y);
                    col = Color.FromArgb((col.R + col.G + col.B) / 3,
                        (col.R + col.G + col.B) / 3,
                        (col.R + col.G + col.B) / 3);
                    int rValue = int.Parse(col.R.ToString());
                    html.Append(getGrayShade(rValue));
                    if (x == bmp.Width - 1)
                        html.Append("<br/&rt");
                }
            }

    Нашел проект на codeproject, для конвертации изображения в аscii-art

    psina-from-ua, 18 Октября 2011

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

    +166

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $my_query = new WP_Query(array("post_status" => "publish",
                                   "post_type" => "portfolio",
                                   "post_parent" => $post->ID,
                                   "orderby" => "date",
                                   "posts_per_page" => 1));
    
    /*
     * Пиздец конечно, но это видимо самое гениальное, что я мог придумать
     * в 3 часа ночи
     */
    header("Location: ".get_permalink($my_query->posts[0]->ID));

    WordPress.

    varg242, 18 Октября 2011

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

    +145

    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
    program gays;
    uses crt;
    var k,k1,kn,n,i,j:integer;
        a,c:array [1..100,1..100] of real;
        f,x,b,d:array [1..100] of real;
        r:real;
    begin
      repeat
      Write ('put poriadok n<100, n=');
      readln(n);
      until n<100;
      for i:=1 to n do
       begin
         for j:=1 to n do
          begin
            write('a [',i,';',j,']=');
            readln(a[i,j]);
            c[i,j]:=a[i,j];
          end;
         write('b [',i,']=');
         readln(b[i]);
         d[i]:=b[i];
       end;
     //3blok
      for k:=1 to (n-1) do
       begin
         //4 blok
         if a[k,k]=0 then
          begin
             k1:=k;
             repeat
              k1:=k1+1 ;
             until (a[k1,k]<>0) or (k1>n);
             if a[k1,k]=0 then
              begin
                writeln('Vedushii elementi ravni nuly');
                halt;
              end;
             kn:=k1;
             for j:=1 to n do
              begin
                r:=a[k,j];
                a[k,j]:=a[kn,j];
                a[kn,j]:=r;
              end;
              r:=b[k];
              b[k]:=b[kn];
              b[kn]:=r;
          end;
              //5 blok
         b[k]:=b[k]/a[k,k];
         for i:=(k+1) to n do
           b[i]:=b[i]-a[i,k]*b[k];
         for j:=(k+1) to n do
          begin
            a[k,j]:=a[k,j]/a[k,k];
            for i:=(k+1) to n do
              a[i,j]:=a[i,j]-a[i,k]*a[k,j];
          end;
       end;
      //end 3 blok
      x[n]:=b[n]/a[n,n];
      // 7 blok
    
      for i:=(n-1) downto 1 do
       begin
         for j:=i+1 to n do
           b[i]:=b[i]-x[j]*a[i,j] ;
         x[i]:=b[i];
       end;
    
       // 8 blok
       for i:=1 to n do
         if x[i]<0 then writeln ('nomer otricatelnogo kornia =',i);
       for j:=1 to n do writeln('x[',j,']=',x[j]:10:4);
       // 9 blok
       for i:=1 to n do
        begin
          f[i]:=-d[i];
          for j:=1 to n do
            f[i]:=f[i]+c[i,j]*x[j];
          writeln('F=',f[i]:10:4);
        end;
    readkey;
    end.

    Очередной высер стажера при написании учетного решения в 1С

    alexoy, 18 Октября 2011

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    ...
    $access = array();  
    $access = file("access.php");  
    ...

    http://forum.php.su/topic.php?forum=33&topic=732

    x34e, 18 Октября 2011

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