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

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

    +126

    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
    public static bool IsLong(string tmpStr)
    {
    	bool blRetVal = true;
    	for (int i = 0; i < tmpStr.Length; i++)
    	{
    		if (tmpStr[i] != '0' && tmpStr[i] != '1' && tmpStr[i] != '2' &&
    			tmpStr[i] != '3' && tmpStr[i] != '4' && tmpStr[i] != '5' &&
    			tmpStr[i] != '6' && tmpStr[i] != '7' && tmpStr[i] != '8' &&
    			tmpStr[i] != '9')
    			blRetVal = false;
    	}
    	return blRetVal;
    }
    
    static public string ConvertDateTimeForSQL(DateTime tmpDateTime)
    {
    	return (
    		tmpDateTime.Year.ToString() + "-" +
    		(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
    		(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString() + " " +
    		(tmpDateTime.Hour < 10 ? "0" : "") + tmpDateTime.Hour.ToString() + ":" +
    		(tmpDateTime.Minute < 10 ? "0" : "") + tmpDateTime.Minute.ToString() + ":" +
    		(tmpDateTime.Second < 10 ? "0" : "") + tmpDateTime.Second.ToString());
    }
    
    static public string ConvertDateTimeShortForSQL(DateTime tmpDateTime)
    {
    	return (tmpDateTime.Year.ToString() + "-" +
    		(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
    		(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString());
    }
    
    -----------------------------------
    P.S. Версия .NET 3.5

    yorikim, 17 Января 2012

    Комментарии (4)
  3. Java / Говнокод #9107

    +65

    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
    for (...) {
      Comparator<Date> date_comparator = new Comparator<Date>() {
        @Override
        public int compare(Date s1, Date s2) {
          long n1 = s1.getTime();
          long n2 = s2.getTime();
          if (n1 < n2)
            return -1;
          else if (n1 > n2)
            return 1;
          else
            return 0;
        }
      };
      Date beforeSaveDate = (Date) beforeSaveParam.getValue();
      beforeSaveDate.setSeconds(0);
      Date toSaveDate = (Date) toSaveParam.getValue();
      comparedValue = date_comparator.compare(beforeSaveDate, toSaveDate);
    }

    Задача была сравнить две даты, игнорируя при этом секунды.

    LexeY4eg, 13 Января 2012

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

    +118

    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
    private Excel._Application _excel;
    ...
    private void RefreshFormulas(FormulaRefreshOption formulaRefreshOption, object objectToRefresh)
    		{
    			//Где-то в дебрях километрового метода бросилось в глаза
                            ...
    			try
    			{
    				Excel.Range intersection = selection, selection2 = selection;
    				while (selection2 != null)
    				{
    					intersection = _excel.Intersect(selection2, selection2.Dependents,
    						Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						 Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
    						   Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    
    
    					System.Windows.Forms.Application.DoEvents();
    					excelUtilities.RecalculateRangeInstance(true, intersection/*_excel.Selection as Excel.Range*/);
    					selection2 = intersection;
    				}
    
    			}
    			catch (Exception) { /*ignore the exception because .Dependents will throw an exception if there aren't any dependents*/}
                            ...
    		}

    fade, 04 Января 2012

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

    +144

    1. 1
    $

    TarasGovno, 04 Января 2012

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

    +1001

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    void Object::destroy ()
    {
      evas_object_del (o);
      
      // do a suicide as the delete operator isn't public available
      // the reason is that the C design below is a suicide design :-(
      //delete (this); // TODO: why does this make problems sometimes???
    }

    source: trunk/BINDINGS/cxx/elementaryxx/src/Object.cpp @ 65926

    rat4, 04 Января 2012

    Комментарии (4)
  7. PHP / Говнокод #8875

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    <?php
    @fwrite($fp, "<?php
    \$config['dbhost'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbhost'])))."\";
    \$config['dbuser'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbuser'])))."\";
    \$config['dbpass'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbpass'])))."\";
    \$config['dbname'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbname'])))."\";
    \$config['dbpref'] = \"".str_replace("\"","\\\\\"",stripslashes(trim($_POST['dbprefix'])))."\";
    ?>");
    ?>

    avecms нах.

    TBoolean, 19 Декабря 2011

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    if(!$this->result = $this->dbo->query($this->sql))
    {
       throw new Exception('Error Query: '. $this->sql);
    }

    Ооо я знаю про исключения...

    Sulik78, 19 Декабря 2011

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

    +168

    1. 1
    preg_match('/(.*?)[.,!|]/',ltrim(preg_replace('/[\n\r]+/','|',strip_tags($item[$this->tooltip])),'|'),$regs);

    жонглирование регулярками

    Lure Of Chaos, 18 Декабря 2011

    Комментарии (4)
  10. JavaScript / Говнокод #8860

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    this.getRgbaAtColor = function(color)
    {
    	color = (color.charAt(0)=="#") ? color.substring(1,9):color;
    	color = (color.substring(0,2)=="0x") ? color.substring(2,10):color;var r =  parseInt(color.substring(0,2),16);
    	var g = parseInt(color.substring(2,4),16);
    	var b = parseInt(color.substring(4,6),16);
    	var a = color.substring(6,8);
    	a = (a=="") ? 255:parseInt(a,16);
    	return "rgba("+r+","+g+","+b+","+(a/255)+")";
    }

    геймдев..

    KirAmp, 17 Декабря 2011

    Комментарии (4)
  11. PHP / Говнокод #8857

    +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
    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
    //так было до
    <?php
        // дневной/ночной фон
        $now=date("G");
        if (($now > 8) and ($now<21))
            {echo "странице задаётся дневной фон";}
        else
    	{echo "странице задаётся ночной фон";}
    
        //время на сервере	        
        echo date("Время на сервере H:i");
    
        //Выводятся знаменательные события в истории за этот день (ps: просто из папки events берётся фйл с названием $today
        $today=date("d_M");
        $event=file("event/$today");
        $line=count($event);
        echo "<center>",$event[rand(0,$line-1)],"</center>";
        $mon=explode("_",$today);
        $rus=array("Dec"=>"декабря");
        echo "<a href=\"http://ru.wikipedia.org/wiki/",$mon[0],"_",$rus[$mon[1]]>Подробнее о этом дне в Истории</a>";
    
        //история посещений
        $ip=$_SERVER['REMOTE_ADDR']." | ".date("d M H:i:s")."\n";
    ?>
    
    //так стало после
    <?php
        // дневной/ночной фон
        $now=date("d_M_G:i:s");
        $time=explode("_",$now);
        $hour=explode(":",$time[2]);
        if (($hour[0] > 8) and ($hour[0]<21))
            {echo "странице задаётся дневной фон";}
        else
            {echo "странице задаётся ночной фон";}
    
        //время на сервере
        echo "Время на сервере ",$hour[0],":",$hour[1];
    
        //Выводятся знаменательные события в истории за этот день (ps: просто из папки events берётся фйл с названием $today
        $today=$time[0]." ".$time[1];
        $event=file("event/$today");
        $line=count($event);
        echo "<center>",$event[rand(0,$line-1)],"</center>";
        $rus=array("Dec"=>"декабря");
        echo "<a href=\"http://ru.wikipedia.org/wiki/",$time[0],"_",$rus[$time[1]]>Подробнее о этом дне в Истории</a>"; 
    
        //история посещений
        $ip=$_SERVER['REMOTE_ADDR']." | ".$now."\n";
    ?>

    Так сказать попытка оптимизировать код. Был первый вариант, где функция date использовалась 4 раза с разными параметрами.
    Ну и я решил свести всё к одной date... уж и не знаю... был ли смысл) быстрее ли от этого всё будет работать...))

    Vladis_s, 17 Декабря 2011

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