1. 1C / Говнокод #8241

    −137

    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
    Для Каждого Стр0 из ДеревоНаФорме.Строки Цикл
    		Сум0 =0;
    	Для Каждого Стр1 из	Стр0.Строки Цикл
    		Сум1 =0;
    		Для Каждого Стр2 из Стр1.Строки Цикл;
    			 Попытка
    		Стр2.СуммаВсего = Стр2.Количество * Стр2.Нормочасы*ЦенаНормочаса *(1-Стр2.СкидкаНаРаботы/100)+ Стр2.Количество * Стр2.Цена *(1-Стр2.СкидкаНаЗапчасти/100) ;
    		Стр2.СтоимостьУстановки = Стр2.Количество * Стр2.Нормочасы*ЦенаНормочаса;		
    				Сум1=Сум1+ Стр2.СуммаВсего;
    		 	 исключение КонецПопытки;
    		 КонецЦикла;
    		 Стр1.СуммаВсего = Сум1;
    		 Сум0 = Сум0+Сум1;
    	 КонецЦикла;
    	 Стр0.СуммаВсего = Сум0; 
    КонецЦикла;

    Умопомрачительный подсчёт итога по колонке "СуммаВсего" в дереве.
    ДеревоНаФорме - дерево на форме. При интеркативном изменении числовых реквизитов - пересчитывается строка, но! на всякий случай здесь - в Попытке-Исключении пересчитываем СуммуВсего по строке ещё раз... Ну и конечно порадовала изящность конструкции....

    Pauchog, 19 Октября 2011

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

    +121

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $ df -k /
    /                      (/dev/vgroot/lvol3     ) :  2083856 total allocated Kb
                                                       1701112 free allocated Kb
                                                        382744 used allocated Kb
                                                            18 % allocation used

    HP-UX. вывод df (disk free) тулзы. почти все тратят минут пять на чтение вывода, пытаясь понять смысл "free allocated" и ту тонкую разницу которая отличает это выражение от "used allocated".

    Dummy00001, 19 Октября 2011

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

    +82

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

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

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

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

    +147

    1. 1
    signed bool

    ohlol, 18 Октября 2011

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

    +146

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

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

    ohlol, 18 Октября 2011

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