1. Java / Говнокод #8238

    +82

    1. 1
    2. 2
    3. 3
    if (getAgentAgrees() && (firstOrdered || secondOrdered) && !(getDisclaimer().getDisplayed())) {
        getDisclaimer().setDisplayed(false);
    }

    Минут пять вникал в условия, в итоге выяснил, что код только тратит время (моё и процессора).

    roman-kashitsyn, 19 Октября 2011

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (whole_text.toLowerCase().search(new RegExp(search_phrase, 'i')) < 0) {
        $(this).css('display', 'none');
    } else {
        $(this).css('display', 'block');
    }

    striker, 19 Октября 2011

    Комментарии (17)
  3. 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)
  4. 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)
  5. Си / Говнокод #8234

    +147

    1. 1
    signed bool

    ohlol, 18 Октября 2011

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

    +146

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

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

    ohlol, 18 Октября 2011

    Комментарии (33)
  7. 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)
  8. 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)
  9. 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)
  10. 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)