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

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

    +147

    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
    int __fastcall TForm1::iscomm(AnsiString str)
    {
    int i=1;
    while (str[i]==' ')
     i++;
    if (str[i]=='#')
     {
      return 1;
     }
    else
     {
      return 0;
     };
    };

    yasosiska, 27 Июня 2011

    Комментарии (7)
  3. JavaScript / Говнокод #7049

    +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
    jQuery("select[id='select1']").change(
    			function () 
    			{
    				var city_id = jQuery(this).attr("value");
    				jQuery("select[id='select_hotel']").html('<option>Выберите категорию</option>');
    				jQuery("select[name='room']").html('<option>Выберите категорию и отель</option>');
    				
    				jQuery("select[id='select_5']").change(
    					function () 
    					{
    						....................................
    					}
    				);			
    			}
    		);

    обратите внимание на то, как селекторы объектов написаны.. автор вместо "#select1" пишет "select[id='select1']" зачем это делать непонятно.
    наговнокодено на сайте el-tour.com

    magistr_bender, 24 Июня 2011

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

    +147

    1. 1
    2. 2
    if(!empty(_SESSION['order']['contact']['user_id']))
        $user_id = preg_replace('/\D|\s/', '', $_SESSION['order']['contact']['user_id']);

    Радует знание регулярных выражений =)

    mitallast, 24 Июня 2011

    Комментарии (7)
  5. Pascal / Говнокод #7001

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    uses crt;
    var s:integer;
    begin
    readln(s);
    writeln(ord(s[0]));
    readln;
    end.

    dos, 20 Июня 2011

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

    +123

    1. 1
    this.Border1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(111)))), ((int)(((byte)(111)))));

    Встретилось такое внутри сгенеренной системой InitializeComponent()

    absolut, 17 Июня 2011

    Комментарии (7)
  7. Си / Говнокод #6935

    +143

    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
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    // find the start and end of the upload file.
    static FILE * _uploadGet(request *wp, unsigned int *startPos, unsigned *endPos) {
       
       FILE *fp=NULL;	
    	struct stat statbuf;	
    	unsigned char c, *buf; 
    	   
    	
    	if (wp->method == M_POST)
    	{
    	   fstat(wp->post_data_fd, &statbuf);
    		lseek(wp->post_data_fd, SEEK_SET, 0);
          
    		printf("file size=%d\n",statbuf.st_size);
    		fp=fopen(wp->post_file_name,"rb");
    		if(fp==NULL) goto error;
    	}
    	else goto error;
    
       
       //printf("_uploadGet\n");
       do
    	{
    		if(feof(fp))
    		{
    			printf("Cannot find start of file\n");
    			goto error;
    		}
    		c= fgetc(fp);
    		if (c!=0xd)
    			continue;
    		c= fgetc(fp);
    		if (c!=0xa)
    			continue;
    		c= fgetc(fp);
    		if (c!=0xd)
    			continue;
    		c= fgetc(fp);
    		if (c!=0xa)
    			continue;
    		break;
    	}while(1);
    	(*startPos)=ftell(fp);
    
       if(fseek(fp,statbuf.st_size-0x200,SEEK_SET)<0) 
          goto error;
    	do
    	{
    		if(feof(fp))
    		{
    			printf("fmmgmt: Cannot find end of file\n");
    			goto error;
    		}
    		c= fgetc(fp);
    		if (c!=0xd)
    			continue;
    		c= fgetc(fp);
    		if (c!=0xa)
    			continue;
    		c= fgetc(fp);
    		if (c!='-')
    			continue;
    		c= fgetc(fp);
    		if (c!='-')
    			continue;
    		break;
    	}while(1);
    	(*endPos)=ftell(fp);
    
       return fp;
    error:
       return NULL;
    }

    Вот так вот китайцы парсят MIME при загрузке прошивки в роутер.

    SadKo, 12 Июня 2011

    Комментарии (7)
  8. C# / Говнокод #6913

    +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
    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
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    internal sealed class FontKeeper
    {
            private static readonly FontConverter s_converter = new FontConverter();
            private static readonly Regex s_font = new Regex(@"^(?<name>\w[\s\w]+);\s*(?<size>\d+)pt\s*(?:;(?<style>.*))?$", RegexOptions.IgnoreCase);
            private static readonly Regex s_style = new Regex(@"^\s*style\s*=\s*([\w\s,]+)$", RegexOptions.IgnoreCase);
            private const int defaultSize = 14;
    
            public FontKeeper(Font font) : this(s_converter.ConvertToString(font)) { }
    
            public FontKeeper(string fontString)
            {
                Match m = s_font.Match(fontString);
                if (!m.Success)
                    throw new ArgumentException("Неверный формат строки");
    
                Name = m.Groups["name"].Value.Trim();
                int sz;
                if (!int.TryParse(m.Groups["size"].Value, out sz))
                    sz = defaultSize;
                Size = sz;
    
                //Флаги стиля
                ParseStyle(m.Groups["style"].Value);
            }
    
            private void ParseStyle(string value)
            {
                Match m = s_style.Match(value);
                if (!m.Success) return;
    
                string[] styles = m.Groups[1].Value.Split(new[] { ',' });
                foreach (var style in styles)
                {
                    try
                    {
                        Style |= (FontStyle)Enum.Parse(typeof(FontStyle), style.Trim(), true);
                    }
                    catch { }
                }
            }
    
            public string Name { get; set; }
            public int Size { get; set; }
            public FontStyle Style { get; set; }
            public float FontFactor
            {
                get { return (float)Size / defaultSize; }
                set { Size = (int)(value * defaultSize); }
            }
    
            public Font CreateFont()
            {
                return new Font(Name, Size, Style);
            }
    }

    Небольшой класс для хранения и динамического изменения шрифтов

    lomomike, 10 Июня 2011

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

    +163

    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
    elseif (intval($countryID)>0 && intval($regionID)>0){
                    $SQL = "SELECT DISTINCT ".TABLE_PREFIX."hotels".LANG_PREFIX.".stars FROM  ".TABLE_PREFIX."hotels".LANG_PREFIX.", ".TABLE_PREFIX."regions".LANG_PREFIX."
                    WHERE   ".TABLE_PREFIX."regions".LANG_PREFIX.".id=".TABLE_PREFIX."hotels".LANG_PREFIX.".region_id
                    AND ".TABLE_PREFIX."regions".LANG_PREFIX.".id =".$regionID."";                               
                    $qRS = mysql_query ($SQL) or die ("<hr size=\"1\"><b>Не удалось выполнить: </b> \"" . $SQL . "\"<br>" . mysql_error());
                    if (mysql_num_rows($qRS)) {
                            while ($row = mysql_fetch_object($qRS)) {
                                    $stars[$row->stars]++;
                            }
                    }
                    krsort($stars);
                    foreach ($stars as $key=> $value) {
                            $ret .= get_hotels($key, 100, $regionID, $countryID);        
                    }

    Washington, 09 Июня 2011

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

    −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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    try:
            dday = time.strftime("%d", time.localtime(os.path.getmtime(path + d))).lstrip('0')
            dmonth = time.strftime("%m", time.localtime(os.path.getmtime(path + d))).lstrip('0')
            dhour = time.strftime("%H", time.localtime(os.path.getmtime(path + d))).lstrip('0')
            dmin = time.strftime("%M", time.localtime(os.path.getmtime(path + d))).lstrip('0')
            screenpath = os.listdir(spath)
            for screen in screenpath:
                sday = time.strftime("%d", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
                smonth = time.strftime("%m", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
                shour = time.strftime("%H", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
                smin = time.strftime("%M", time.localtime(os.path.getmtime(spath + screen))).lstrip('0')
                if dday == sday:
                    if dmonth == smonth:
                        if dhour == shour:
                            if dmin == smin:
                                scr = spath + screen
                                if scr:
                                    return str(scr)
                                else:
                                    return None
        except:
            return "None"

    Проверка даты создания двух файлов

    pztrn, 08 Июня 2011

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

    −318

    1. 1
    self._DEBUG=Debug.Debug(debug)

    В библиотеке xmpppy. Дебаг на дебаге.

    diok, 05 Июня 2011

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