1. Лучший говнокод

    В номинации:
    За время:
  2. PHP / Говнокод #6985

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private function exportPTCsvFile(array $transactions, array $refunds, $fileName)
    	{
    		$csv[] = array('Date', 'Time Zone', 'Name',  'Type',  ' Status',  'Currency',  'Gross', 'Fee', 'Net', 'From Email Address', 'Transaction ID', ' Item Title', 'Deal ID', 'Deal City', 'Merchant ID', 'User ID', 'Purchase Date', 'CMS Transaction ID', 'CMS Quantity', 'CMS Amount', 'Kash Used', 'CC Digits', 'Coupon Link', 'Paymentech Response');
    
    		// headers...
    		
    		foreach ($csv as $titles) {
    		    print utf8_encode(implode(',', $titles))."\n";
    		}
                   // Rest of code...
    }

    kovel, 17 Июня 2011

    Комментарии (6)
  3. C# / Говнокод #6960

    +125

    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
    protected string getUpdateNotesDE(string fieldNameAlias, string fieldName, string fieldValue, ASPxDateEdit newValue)
            {
                if (isSaveField("fieldName"))
                {
                    if (fieldValue != "")
                        return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = " + Convert.ToDateTime(fieldValue).ToString("dd/MM/yyyy") + ", New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                    else
                        if (newValue.Text != "")
                            return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = , New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                }
                return "";
    
            }
    
     protected Boolean isSaveField(string fieldName)
            {
                if (locCom.getVisible(fieldName))
                    return true;
                return false;
            }
    
     public bool getVisible(string fldName)
                {
                    Boolean showall = Convert.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Show-all-fields"));
                    if (showall) return true;
    
                    if (fldAccess.Tables.Count == 0) return false;
    
                    foreach (System.Data.DataRow item in fldAccess.Tables[0].Rows)
                    {
                        if (item["fieldname"].ToString().Replace('@', 'a').Replace("%", "percent").Replace("$", "dollar").ToLower() == fldName.ToLower())
                            return Convert.ToBoolean(item["visible"]);
                    }
                    return false;
                }

    особенно доставляет
    protected string getUpdateNotesDE(string fieldName){
    if (isSaveField( !!! "fieldName" !!!)){}
    }

    valorkin, 15 Июня 2011

    Комментарии (6)
  4. bash / Говнокод #6947

    −127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    am=`cat $file | wc -l`
    for ((i=1;i<=$am;i++))
    do
        read z
        imsi=`echo $z | sed -e "s/^[0-9]*[ ]*//" `
    done < $file

    berezhinskiy, 14 Июня 2011

    Комментарии (6)
  5. PHP / Говнокод #6909

    +155

    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
    <script type="text/php">
    
    $color_op = Style::munge_colour( "#565656" );
    
    $font_op = Font_Metrics::get_font("arial", "normal");
    $font_op2 = Font_Metrics::get_font("arial", "bold");
    
    {literal}
    #	$pdf->text($left_op, $top_op, $text00, $font_op, 16, $color_op);
    #	$pdf->text($left_op, $top_op + 20, $text22, $font_op, 16, $color_op);
    #	$pdf->text($left_op, $top_op + 40, $text33, $font_op, 16, $color_op);	
    
    	$pdf->text($left_op, $top_op, $text00, $font_op2, 16, $color_op);
    	$pdf->text($left_op+87, $top_op, $text01, $font_op2, 16, $color_op2);
    	$pdf->text($left_op+87+15, $top_op, $text02, font_op, 16, $color_op);
    	
    {/literal}
    </script>

    Кусок из шаблона Smarty.

    _tL, 09 Июня 2011

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

    +128

    1. 1
    return Mouse.GetState().LeftButton == ButtonState.Pressed ? _manager.Creatures.Where(el => el.Rectangle.Intersects(new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 2, 2))).FirstOrDefault() : null;

    dotnetdeveloper, 08 Июня 2011

    Комментарии (6)
  7. Python / Говнокод #6899

    −83

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    # In Django model
    def processed_description(self):
        text = self.description. \
               replace('<table', '<div class="table">'
                                 '<div class="bgtop"></div>'
                                 '<div class="overflow"><table'). \
               replace('</table>', '</table></div>'
                                   '<div class="bgbottom"></div>'
                                   '</div>'). \
               replace('<th', '<th width="50%" align="left"')
        return text

    Пользователь хочет редактировать контент в WYSIWYG-редакторе. Дизайнер хочет, чтобы таблицы выглядели красиво. Верстальщику для красоты нужны дополнительные div-ы. Что делает программист? Говнокодит!

    zag, 08 Июня 2011

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

    +75

    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
    1.3 @@ -89,9 +89,6 @@
         1.4     public void openFile(File f) {
         1.5        try {
         1.6           Desktop.getDesktop().open(f);
         1.7 -//         String s = "cmd /c \"" + f.getAbsolutePath() + "\" ";
         1.8 -//         System.out.println(s);
         1.9 -//         java.lang.Process p = Runtime.getRuntime().exec(s);
        1.10        }
        1.11        catch (Exception e) {
        1.12           JOptionPane.showMessageDialog(null, "Ошибка при открытии файла", "Ошибка", JOptionPane.ERROR_MESSAGE);
        1.13 @@ -112,21 +109,6 @@
        1.14           temp.mkdir();
        1.15        }
        1.16        String fName = entry.getName();
        1.17 -      fName = fName.replaceAll("\\&", "_");
        1.18 -      fName = fName.replaceAll("\\(", "_");
        1.19 -      fName = fName.replaceAll("\\)", "_");
        1.20 -      fName = fName.replaceAll("\\[", "_");
        1.21 -      fName = fName.replaceAll("\\]", "_");
        1.22 -      fName = fName.replaceAll("\\{", "_");
        1.23 -      fName = fName.replaceAll("\\}", "_");
        1.24 -      fName = fName.replaceAll("\\^", "_");
        1.25 -      fName = fName.replaceAll("\\=", "_");
        1.26 -      fName = fName.replaceAll("\\!", "_");
        1.27 -      fName = fName.replaceAll("\\`", "_");
        1.28 -      fName = fName.replaceAll("\\+", "_");
        1.29 -      fName = fName.replaceAll("\\~", "_");
        1.30 -      fName = fName.replaceAll(" ", "_");
        1.31 -      fName = fName.replaceAll(("№"), "_");
        1.32        String dnFileName = temp.getName() + File.separator + fName;
        1.33  
        1.34        File dlFname = new File(dnFileName);

    Так как открытие файла происходило весьма оригинальным образом через cmd.exe - вполне логично было написано фильтрование символов, неперевариваемых этой cmd.exe.
    Как видно - задача решалась одной строкой - " Desktop.getDesktop().open(f);".

    maxt, 08 Июня 2011

    Комментарии (6)
  9. SQL / Говнокод #6883

    −121

    1. 1
    2. 2
    3. 3
    4. 4
    update RPout
    set ReserveCalculated = round((Base * ElementNorm) /100.0 + 1e-9, 2) * 
    sign(convert(money, floor(Base * ElementNorm) / 100.0)) * sign( 1 + 
    sign(convert(money, floor(Base * ElementNorm) / 100.0)))

    Отрицательные значения изменить на ноль плюс феерическая работа с типами данных.

    Blackened, 07 Июня 2011

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

    +172

    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
    <?php
    
    //...
    
    if(version_compare(phpversion(), '5.0') < 0) {
            insert_charset_header();
            require_once('phpversionfail.php');
            die();
    }
    
    require_once('include/utils/utils.php');
    
    if (version_compare(phpversion(), '5.0') < 0) {
        eval('
        function clone($object) {
          return $object;
        }
        ');
      }
    
    //....
    
    ?>

    Код из vTiger CRM. Индусы как обычно.

    mr.The, 31 Мая 2011

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

    +88

    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
    public synchronized static void reload() 
    	{
            synchronized (properties) 
    		{
                synchronized (questRewardRates)
    			{
                    synchronized (questDropRates)
    				{
                        properties = new ConcurrentHashMap<String, String>();
                        questRewardRates = new ConcurrentHashMap<Integer, Float>();
                        questDropRates = new ConcurrentHashMap<Integer, Float>();
                        load();
                    }
                }
            }
        }

    Я просто оставлю это здесь (c)

    VirtualVoid, 30 Мая 2011

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