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

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

    −104

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @hands_by_value.each do |hand|
    	if @hands_by_value.slice(@hands_by_value.index(hand)+1..@hands_by_value.index(@hands_by_value.last)).include?(hand)
    			@hands_by_value.delete_at(@hands_by_value.index(hand))			
    		end
    	end

    Рукотворный array.uniq! похоже :)

    lnk, 01 Июля 2011

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

    +113

    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
    public string GetNormalImage(int newWidth, int newHeight, string sufix = "normal") {
                String[] tmp = _originalImagePath.Split('.');
                String newImagePath = "";
                for (int i = 0; i < tmp.Length - 1; i++)
                {
                    newImagePath += tmp[i];
                    newImagePath += "_";
                }
                newImagePath += sufix + ".";
                newImagePath += tmp[tmp.Length - 1];
    
                
                Image oldImage = Image.FromFile(_originalImagePath);
                if (oldImage.Height >= oldImage.Width) {
                    Image newImage;
                    newImage = FixedSize(oldImage, newWidth, newHeight);
                    newImage.Save(newImagePath);
                } else {
    
                    float heightRatio = (float)newHeight / (float)oldImage.Height;
                    float widthRatio = (float)newWidth / (float)oldImage.Width;
    
                    float bestRatio = 1;
                    if (heightRatio < widthRatio) {
                        bestRatio = heightRatio;
                    } else {
                        bestRatio = widthRatio;
                    }
    
                    var result = new System.Drawing.Bitmap((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio));
                    using (var graphics = Graphics.FromImage(result))
                    {
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;
                        graphics.DrawImage(oldImage, new Rectangle(Point.Empty, new Size((int)Math.Round(oldImage.Width * bestRatio), (int)Math.Round(oldImage.Height * bestRatio))));
                    }
                    result.Save(newImagePath);
                }
    
                return newImagePath;
            }

    ресайз изображения

    tuxcod, 30 Июня 2011

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

    −104

    1. 1
    <%= !!@case[:img] ? image_tag(@case[:img]) : "" %>

    pavel_so, 29 Июня 2011

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

    −144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #! /bin/sh
    
    # some code
    
    daemon1="/usr/home/daemon1.sh"
    daemon2="/home/daemon2.sh"
    
    # some code with variables

    Скрипт на BSD. Хомяк находится в /usr/home, а /home симлинк на него

    Elvenfighter, 29 Июня 2011

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