1. Ruby / Говнокод #8239

    −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
    def self.find_or_create params
      if params[:rule_id].present?
        rule = new_from_params params
        return nil if rule.nil?
        parent_rule = Rule.find_by_id params[:rule_id]
    
        if parent_rule and Rule.calc_md5(rule.to_hash) == parent_rule.crc
          parent_rule.rule_id = parent_rule.id
          parent_rule.grouped_by = rule.grouped_by
          parent_rule.sorted_by = rule.sorted_by
          parent_rule.save
          return parent_rule
        end
        rule_id = params.delete :rule_id
      end
    
      params = clear_and_sort params
      if (rule = Rule.find_by_crc(Rule.calc_md5(params))).present?
        rule.rule_id = rule_id
        rule.grouped_by = params[:grouped_by]
        rule.sorted_by = params[:sorted_by]
        rule.save
      else
        rule = new_from_params params.merge(:rule_id => rule_id)
        rule.save
      end
      rule
    end

    Метод модели, используется для поиска, создания и чего-то еще...

    emerald, 19 Октября 2011

    Комментарии (7)
  2. Java / Говнокод #8238

    +82

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

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

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

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

    +147

    1. 1
    signed bool

    ohlol, 18 Октября 2011

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

    +146

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

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

    ohlol, 18 Октября 2011

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