1. Pascal / Говнокод #13332

    +133

    1. 1
    2. 2
    Участник, прошу тебя: не поленись, пройди по анкетам и поставь всем минусы.
    Минуисуя участников, ты помогаешш обществу снижать ЧСВ.

    Участник, прошу тебя: не поленись, пройди по анкетам и поставь всем минусы.
    Минуисуя участников, ты помогаешш обществу снижать ЧСВ.

    Stertor, 09 Июля 2013

    Комментарии (1)
  2. Pascal / Говнокод #13331

    +133

    1. 1
    ADMIN LOH

    Stertor, 09 Июля 2013

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

    +128

    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
    static readonly Regex binary = new Regex("^[01]{1,32}$", RegexOptions.Compiled);
    static void Main() {
        Test("");
        Test("01101");
        Test("123");
        Test("0110101101010110101010101010001010100011010100101010");
    }
    static void Test(string s) {
        if (binary.IsMatch(s)) {
            Console.WriteLine(Convert.ToInt32(s, 2));
        } else {
            Console.WriteLine("invalid: " + s);
        }
    }

    http://stackoverflow.com/questions/1271562/binary-string-to-integer
    Мучает вопрос. Зачем ставить регулярку? Почему бы просто не словить FormatExeption?

    neeedle, 09 Июля 2013

    Комментарии (180)
  4. 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)
  5. Куча / Говнокод #13328

    +133

    1. 1
    2. 2
    Не поленись, пройди по анкетам и поставь всем минусы.
    минуисуя участников, ты помогаешш обществу.

    Stertor, 08 Июля 2013

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

    +161

    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
    </if>
    															</if>
    														</ul>
    													</if>
    												</td>
    												</if>
    											</tr>
    										</if>
    									</foreach>
    								</table>
    							</div>
    						</div>
    						<br />
    					</div>
    				</if>
    			</foreach>
    		</if>
    	</div>

    facepalm

    CheshirskyCode, 08 Июля 2013

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

    −110

    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
    // last parameter is the setter code if value allowed to be set
    #define SET_USING_CONFIG(cellSwitch,configKey,...)\
                cell.cellSwitch = [(EExhibitorsListConfigItem*)[self.configInfo configItemAtIndex:0] configKey];\
                if (cell.cellSwitch) {\
                    __VA_ARGS__;\
                }
    
     SET_USING_CONFIG(isLikesCountOn, showLikes,
        cell.likesCount = exhibitor.Rating;
        cell.likedByMe  = exhibitor.IsRated; );
    
    SET_USING_CONFIG(isInFavoritesOn, showFavoritesIndicator,
                         
        __weak EExhibitorCell *weakCell = cell;
    
        cell.didChangeFavouritesStateBlock = ^(BOOL newFavState) {
            [EExhibitorsListViewController updateFavoriteState:newFavState
                              ofExhibitor:exhibitor
                                   inCell:weakCell];
        };
    );

    Define master!

    Headless, 08 Июля 2013

    Комментарии (8)
  8. JavaScript / Говнокод #13325

    +136

    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
    function NameBro() {
        var userAgent = navigator.userAgent.toLowerCase();
        // Определим Internet Explorer
        if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("opera") == -1 && userAgent.indexOf("webtv") == -1) {
            return "msie";
     	}
     	// Opera
     	if (userAgent.indexOf("opera") != -1) {
     		return "opera";
        }
     	// Gecko = Mozilla + Firefox + Netscape
        if (userAgent.indexOf("gecko") != -1) {
     		return "gecko";
        }
        // Safari, используется в MAC OS
        if (userAgent.indexOf("safari") != -1) {
     		return "safari";
        }
        // Konqueror, используется в UNIX-системах
        if (userAgent.indexOf("konqueror") != -1) {
     		return "konqueror";
        }
        return "unknown";
    }
    
    var bro = NameBro();
    
    $(function() {
    if(bro == "msie") {
    	$("body").html("Пшел нах с маего супир сайта бамжара ибаная. И где ты только комп взял украл или на памойки нашел? Харашо нынчи бамжы жывут сук пздц((");
    	window.location.hash = "Сматри бомж тибя дажы в адресной страке затралли азазазаз.";
    }
    })

    PragramistOtBoga, 08 Июля 2013

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

    +154

    1. 1
    list($V_id, $V_image, $V_title, $V_text, $V_url, $V_link_to, $V_status) = array('','','','','','','');

    множественное присваивание?! не, не слыщал

    dead_star, 08 Июля 2013

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