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

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

    +97

    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
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    {$APPTYPE CONSOLE} {$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
    uses SysUtils, Classes, IniFiles, Variants;
    
    type TGetToken = function(var p: pointer): LongInt;
    procedure ParseData(var p: pointer; isKey: boolean); forward;
    procedure AdvanceIndex(var i: LongInt); forward;
    
    function GetIntegerToken(var p: pointer): LongInt;
    var value: LongInt = 0;
        negative: boolean;
    begin
      Inc(p);
      negative := PByte(p)^ = ord('-');
      if negative then Inc(p);
      repeat
        value := value * 10 + LongInt(PByte(p)^ - $30);
        Inc(p)
      until PChar(p)^ = 'e';
      Inc(p);
      if negative then value := - value;
      Result := value
    end;
    
    function GetListToken(var p: pointer): LongInt;
    var index: Integer = 0;
    begin
      Inc(p);
      while PChar(p)^ <> 'e' do begin
        AdvanceIndex(index);
        ParseData(p, false);
      end;
      Inc(p);
      Result := -1
    end;
    
    function GetDictToken(var p: pointer): LongInt;
    begin
      Inc(p);
      while PChar(p)^ <> 'e' do begin
        ParseData(p, true);
        ParseData(p, false);
      end;
      Inc(p);
      Result := -1
    end;
    
    function ParseError(var p: pointer): LongInt;
    begin
      Writeln('TYIIINTE CBET');
      Result := -1;
      Halt(Result)
    end;
    
    const FuncTable: array[0..3] of TGetToken = (ParseError, GetDictToken, GetIntegerToken, GetListToken);
    
    function GetStringToken(var p: pointer): string;
    var value: ShortString;
        length: LongInt = 0;
    begin
      repeat
        length := length * 10 + LongInt(PByte(p)^ - $30);
        Inc(p)
      until PChar(p)^ = ':';
      if length in [1..255] then begin
        PByte(p)^ := length;
        Move(p^, value, length+1);
        Result := value;
      end else Result := 'BINARY DATA';
      Inc(p, length + 1);
    end;
    
    var sl: TStringList;
        outf: TIniFile;
    
    procedure AdvanceIndex(var i: LongInt);
    begin
      sl.Add(IntToStr(i));
      Inc(i);
    end;

    type TSaveData = procedure(value: Variant);

    procedure SaveData(value: Variant);
    var
    key: string = '';
    i: LongInt;
    begin
    for i := 0 to sl.Count - 1 do key := key + '.' + sl[i];
    Delete(key, 1, 1);
    outf.WriteString('Torrent', key, VarToStr(value));
    if sl.Count > 0 then sl.Delete(sl.Count - 1);
    end;

    procedure PushKey(value: Variant);
    begin
    sl.Add(value)
    end;

    procedure PopKey(value: Variant);
    begin
    if sl.Count > 0 then sl.Delete(sl.Count - 1);
    end;

    procedure NOP(value: Variant);
    begin
    end;

    const SaveDataTable: array[0..3] of TSaveData = (SaveData, PushKey, PopKey, NOP);

    procedure ParseData(var p: pointer; isKey: boolean);
    var
    OpCode: ShortInt;
    value: Variant;
    begin
    OpCode := PByte(p)^;
    if OpCode >= $60 then value := FuncTable[OpCode shr 2 and 3](p)
    else if Opcode in [$30..$39] then value := GetStringToken(p)
    else ParseError(p);

    SaveDataTable[ord(isKey) + 2*ord(chr(OpCode) in ['d', 'l'])](value);
    end;

    var f: TFileStream;
    s: LongInt;
    p, cp: pointer;
    begin
    if ParamCount <> 1 then Writeln('Usage: ', ParamStr(0), ' filename.torrent')
    else
    try
    f := TFileStream.Create(ParamStr(1), fmOpenRead);
    s:= f.Size;
    GetMem(p, s + 1);
    f.ReadBuffer(p^, s);
    cp := p;
    outf := TIniFile.Create(ChangeFileExt(ParamStr(1), '.ini'));
    sl := TStringList.Create;
    ParseData(cp, false);
    finally
    if sl <> nil then sl.Destroy();
    if outf <> nil then outf.Destroy();
    if p <> nil then FreeMem(p);
    if f <> nil then f.Destroy()
    end
    end.

    Парсер torrent-файлов и сохранялка в INI-файл (пока без сумм фрагментов). Опа-лаба-стайл, писано левой ногой анскильного питуха.

    inkanus-gray, 09 Июля 2013

    Комментарии (15)
  3. Си / Говнокод #13322

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define InlineIsEqualGUID(rguid1, rguid2)  \
            (((unsigned long *) rguid1)[0] == ((unsigned long *) rguid2)[0] &&   \
            ((unsigned long *) rguid1)[1] == ((unsigned long *) rguid2)[1] &&    \
            ((unsigned long *) rguid1)[2] == ((unsigned long *) rguid2)[2] &&    \
            ((unsigned long *) rguid1)[3] == ((unsigned long *) rguid2)[3])

    Windows SDK, guiddef.h

    ret = InlineIsEqualGUID(&g_guid, guid_array + i); /* ??? */

    serg_ik, 07 Июля 2013

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

    +16

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(int i=0;i<World::size;i++)
    {
        for(int u=0;u<World::size;u++)
        {
                    //Задаётся зерно для генерации случайных чисел
            srand(GetTickCount()*i*u);                           
                    //Задаются случайные значения всем точкам от 0*0.1-10, до 100*0.1-10
            World::data[i][u]=(rand()%100)*0.1f-10.0f;                            
        }
    }

    http://habrahabr.ru/post/183986/

    Abbath, 20 Июня 2013

    Комментарии (15)
  5. Objective C / Говнокод #13165

    −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
    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
    - (void)initPlayerViewController
    {
    	BOOL isSuccess = NO;
    	do {
    		NSString *linkString = nil;
    		unsigned long long objectID = [_videoID intValue];
    		
    		int index = GetElementIndex(objectID, _WidevineTestStubs, WIDEVINE_TEST_COUNT);
    		if (index >= 0) {
    			//linkString = GetLink(_WidevineTestServers[index], _WidevineTestFiles[index]);
    			linkString = _WidevineTestLinks[index];
    		}
    		else {
    			linkString = GetString([_videoLink objectForKey:@"src"]);
    		}
    		if(linkString == nil)
    			goto _end;
    
    		self.linkType = GetLinkType(linkString);
    		switch (_linkType) {
    			case LINK_TYPE_HLS:
    				break;
    			case LINK_TYPE_WV_ADAPTIVE:
    			case LINK_TYPE_WV_MULTI:
    				linkString = WidevinePlay(linkString);
    				if ([linkString length] <= 0) {
    					goto _end;
    				}
    				break;
    			default:
    				goto _end;
    		}
    		
    		NSURL *link = [NSURL URLWithString:linkString];
    		if(link == nil)
    			break;
    
    		self.playerViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:link] autorelease];
    		_playerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    		_playerViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    
    		NSInteger startPosition = GetInteger([_videoLink objectForKey:@"play_start_time"]);
    		if(startPosition > 0) {
    			_playerViewController.moviePlayer.initialPlaybackTime = (NSTimeInterval)startPosition;
    		}
    		
    		[self addControlsView];
    		NSArray *audioTracks = [_videoLink objectForKey:@"audio_list"];
    		if ([audioTracks count] < 2) {
    			UIButton *audioButton = (UIButton *)[_controlsView viewWithTag:TAG_BUTTON_CHANGE_AUDIO];
    			audioButton.enabled = FALSE;
    		}
    		
    		isSuccess = YES;
    	} while(0);
    _end:
    	if(isSuccess) {
    		[_delegate onPlayerCreated:self];
            [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
    	}
    	else {
    		[_delegate onLinkError:self];
    	}
    }

    Тут есть все, и do while(0), и проваливающиеся case'ы, и TRUE/FALSE, и глобальные inline методы, и даже goto.

    ArtFeel, 13 Июня 2013

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

    +132

    1. 1
    private static string TestExistFiles(ref int maxd, ref Hashtable executedgroups)

    taburetka, 10 Июня 2013

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

    +147

    1. 1
    trim($_GET['password'])

    nc

    sleeper, 28 Мая 2013

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    try {
                die(@date("d.m.Y H:i:s") . "\t" . $this->x($id, true) . "\r\n");
    } catch (Exception $e) {
                die(@date("d.m.Y H:i:s") . "\tERROR: " . $e->getMessage() . "\r\n");
    }

    остаться в живых

    Lure Of Chaos, 15 Мая 2013

    Комментарии (15)
  9. C# / Говнокод #12957

    +101

    1. 1
    2. 2
    3. 3
    4. 4
    if(searchParams == null)
    {
    	throw new NullReferenceException("параметры поиска = null" + searchParams.ToString());
    }

    Эдакий InnerException, чтоб верняково

    NeoN, 01 Мая 2013

    Комментарии (15)
  10. Objective C / Говнокод #12881

    −102

    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
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    @interface CORERatingImages : NSObject
    {
        UIImage *imageForOne;
        UIImage *imageForTwo;
        UIImage *imageForThree;
        UIImage *imageForFour;
        UIImage *imageForFive;
    }
    +(CORERatingImages *) ratingImages;
    -(UIImage *) getRatingImage:(int) ratings;
    @property (nonatomic, retain) UIImage *imageForOne;
    @property (nonatomic, retain) UIImage *imageForTwo;
    @property (nonatomic, retain) UIImage *imageForThree;
    @property (nonatomic, retain) UIImage *imageForFour;
    @property (nonatomic, retain) UIImage *imageForFive;
    -(void) releaseResources;
    @end
    
    static CORERatingImages *ratingImages = nil;
    
    @implementation CORERatingImages
    @synthesize imageForOne;
    @synthesize imageForTwo;
    @synthesize imageForThree;
    @synthesize imageForFour;
    @synthesize imageForFive;
    
    +(CORERatingImages *) ratingImages
    {
        @synchronized(self)
        {
            if (ratingImages == nil)
            {
                ratingImages = [[self alloc] init];
            }
        }
        return ratingImages;
    }
    -(id) init
    {
        if (self = [super init])
        {
            self.imageForOne = [UIImage imageNamed:@"1.png"];
            self.imageForTwo = [UIImage imageNamed:@"2.png"];
            self.imageForThree = [UIImage imageNamed:@"3.png"];
            self.imageForFour = [UIImage imageNamed:@"4.png"];
            self.imageForFive = [UIImage imageNamed:@"5.png"];
        }
        return self;
    }
    -(UIImage *) getRatingImage:(int) ratings
    {
        if (ratings == 1)
        {
            return imageForOne;
        }
        else if (ratings == 2)
        {
            return imageForTwo;
        }
        else if (ratings == 3)
        {
            return imageForThree;
        }
        else if (ratings == 4)
        {
            return imageForFour;
        }
        else if (ratings == 5)
        {
            return imageForFive;
        }
        else
        {
            return [UIImage imageNamed:@"0.png"];
        }
    }
    -(void) dealloc
    {
        NSLog(@"release Images");
        [imageForOne release];
        [imageForTwo release];
        [imageForThree release];
        [imageForFour release];
        [imageForFive release];
        [super dealloc];
    }
    -(void) releaseResources
    {
        [ratingImages release];
        ratingImages = nil;
    }
    
    @end

    Массив или stringWithFormat: @"%d.png"?

    Не, не слышал.

    QuickNick, 11 Апреля 2013

    Комментарии (15)
  11. JavaScript / Говнокод #12807

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $.post("include/show_watching.php",
        function(data) {
            $('#content').empty().append(data);
        }
    );

    Вот такой вот POST-запрос.

    Stallman, 26 Марта 2013

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