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

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if ((subchannel == undefined || "none") && (subsubchannel == undefined || "none")) {
        subchannel = channel;
        subsubchannel = subchannel;
    } else if ((subchannel != undefined || "none") && (subsubchannel == undefined || "none")) {
        subsubchannel = subchannel;
    } else if ((subchannel == undefined || "none") && (subsubchannel != undefined || "none")) {
        subchannel = channel;
    } else {
        subchannel = subchannel;
        channel = channel;
    }

    Скопировал из похожего проекта не глядя, и потом удевляюсь что херня получается. А там ведь как-то работает, бля...

    russling, 21 Апреля 2015

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

    +142

    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
    #include <inttypes.h>
    #include <stdio.h>
     
    typedef union
    {
      struct
      {
        #define BITG(n) uint8_t bit##n : 1
        BITG(0);
        BITG(1);
        BITG(2);
        BITG(3);
        BITG(4);
        BITG(5);
        BITG(6);
        BITG(7);
        #undef BITG
      } bits;
      uint8_t value;
    }getbit;
     
    uint8_t bit_sum(uint8_t, uint8_t);
     
     
    uint8_t bit_sum(uint8_t a, uint8_t b)
    {
      getbit op1, op2, opr;
      uint8_t carry;
      op1.value=a; op2.value=b;
      #define OP1(n) op1.bits.bit##n
      #define OP2(n) op2.bits.bit##n
      #define OPR(n) opr.bits.bit##n
      #define XOR(a,b) ((a)^(b))
      #define AND(a,b) ((a)&(b))
      OPR(0) = XOR(OP1(0), OP2(0));
      carry = AND(OP1(0), OP2(0));
      #define SETBIT(n)                \
      OPR(n) = XOR                     \
               (                       \
                 carry,                \
                 XOR(OP1(n), OP2(n))   \
               );
     
      #define CARRYBIT(n)              \
      carry = XOR                      \
              (                        \
                AND(OP1(n), OP2(n)),   \
                AND                    \
                (                      \
                  XOR(OP1(n), OP2(n)), \
                  carry                \
                )                      \
              );
      SETBIT(1);
      CARRYBIT(1);
      SETBIT(2);
      CARRYBIT(2);
      SETBIT(3);
      CARRYBIT(3);
      SETBIT(4);
      CARRYBIT(4);
      SETBIT(5);
      CARRYBIT(5);
      SETBIT(6);
      CARRYBIT(6);
      SETBIT(7);
      return opr.value;
      #undef SETBIT
      #undef CARRYBIT
      #undef OP1
      #undef OP2
      #undef OPR
      #undef XOR
      #undef AND
    }
     
    int main (int argc, char *argv[], char *envp[])
    {
      uint8_t a, b, c;
      scanf ("%"SCNu8"%"SCNu8, &a, &b);
      c = bit_sum(a,b);
      printf("%"PRIu8"\n", c);
      return 0;
    }

    Побитовое сложение двух 8-битных чисел по схеме двоичного сумматора

    j123123, 20 Апреля 2015

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    Кажется сбылась чья-то мечта. Калькулятор на чистом css
    
    http://habrahabr.ru/company/paysto/blog/255511/
    http://experiments.hertzen.com/css3calculator/

    blablabla2, 16 Апреля 2015

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

    +890

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    Int64 iObjectId;
    
    public Int64 ObjectId
    {
        get { return iObjectId; }
        set {
             if (iObjectId == null) { value = 0; } else value = iObjectId;
        }
    }

    Помимо того, что условие (iObjectId == null) никогда не выполняется, сеттер еще и делает свойство ObjectId фактически readonly.
    (Авторское форматирование кода сохранено.)

    svetkeen, 15 Апреля 2015

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

    −124

    1. 1
    2. 2
    3. 3
    if __name__ == "__main__":
        def f():
            pass

    Динамичненько

    xyilka, 11 Апреля 2015

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

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    self.symbol_ban = {".":".00",  "!":".01",  "@":".02",  "#":".03",  "$":".04",  "%":".05",  "^":".06",
                               "&":".07",  "*":".08",  "+":".09", "\n":".10", "\t":".11", "\"":".12", "\'":".13",
                               "/":".14",  "<":".15",  ">":".16",  '`':".17", '\\':".19",  " ":".20",  "=":".21",
                               "(":".22",  ")":".23"}
    new_path = map((lambda x, y: [x, y]), ["a_"+"".join([j if (j not in self.symbol_ban) else self.symbol_ban[j] for j in i[0]])   for i in path], [j[1] if j[1] in ("dir", "file") else self.Ex(1)    for j in path])

    часть sax парсера xml для экранирования входных данных, писал для бакалаврской. диплом отдали

    socrat775, 09 Апреля 2015

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

    −352

    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
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    	UITableViewCell *cell = nil;
    
    	if (indexPath.row == self.titles.count - 1)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = YES;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    			[UIAlertView bk_showAlertViewWithTitle:@"Logout"
    										   message:@"Do you want to logout?"
    								 cancelButtonTitle:@"NO"
    								 otherButtonTitles:@[@"YES"]
    										   handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
    											   @strongify(self);
    
    											   if (buttonIndex != 0)
    											   {
    												   [[SWCore instance] logout];
                                                       // fix
                                                       [SVProgressHUD show];
                                                       // end fix
    											   }
    										   }];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else if (indexPath.row == self.titles.count - 2)
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingButtonCell" forIndexPath:indexPath];
    
    		SWSettingButtonCell *scell = (SWSettingButtonCell *) cell;
    
    		[scell.settingButton setTitleForAllStates:self.titles[indexPath.row]];
    
    		[scell.settingButton bk_removeEventHandlersForControlEvents:UIControlEventTouchUpInside];
    
    		scell.settingIcon.visible = NO;
    
    		@weakify(self);
    		[scell.settingButton bk_addEventHandler:^(id sender) {
    
    			@strongify(self);
    			[self performSegueWithIdentifier:@"pushSettingsSegue" sender:nil];
    		}                      forControlEvents:UIControlEventTouchUpInside];
    	}
    	else
    	{
    		cell = [tableView dequeueReusableCellWithIdentifier:@"settingCell" forIndexPath:indexPath];
    
    		SWSettingCell *scell = (SWSettingCell *) cell;
    
    		scell.settingLabel.text = self.titles[indexPath.row];
    		[scell.settingIcon setImage:self.icons[indexPath.row]];
    
    		switch (indexPath.row)
    		{
    			case 0:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PROFILE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_profile_icon_on"] : [UIImage imageNamed:@"settings_profile_icon_off"];
    			}
    				break;
    
    			case 1:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_EVENTS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_events_button_on"] : [UIImage imageNamed:@"settings_events_button_off"];
    			}
    				break;
    
    			case 2:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHONE_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_phone_button_on"] : [UIImage imageNamed:@"settings_phone_button_off"];
    			}
    				break;
    
    			case 3:
    			{
    				scell.settingSwitch.on  = [[SWCore account].settings[[NSString stringWithFormat:SETTINGS_PHOTOS_VISIBILITY]] isEqualToString:SETTING_PUBLIC];
    				scell.settingIcon.image = scell.settingSwitch.isOn ? [UIImage imageNamed:@"settings_photos_button_on"] : [UIImage imageNamed:@"settings_photos_button_off"];
    			}
    				break;
    
    			default:
    				break;
    		}
    
    		scell.settingSwitch.tag = indexPath.row;
    		[scell.settingSwitch bk_removeEventHandlersForControlEvents:UIControlEventValueChanged];

    Один из самых классных методов cellForRowAtIndexPath что я когда-либо видел

    shadeapps, 06 Апреля 2015

    Комментарии (11)
  9. Java / Говнокод #17878

    +77

    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
    int processRequest(Request rq) {
        try {
            ... blablabla ...
            if ("".equals(object.getPrefix())) {
                throw new IllegalArgumentException(bundle.getMessage(MessageKeys.ILLEGAL_PREFIX));
            }
            ... blablabla ...
        } catch (IllegalArgumentException ex) {
            if (ex.getMessage().equals(bundle.getMessage(MessageKeys.ILLEGAL_PREFIX))) {
                return ErrorCodes.ILLEGAL_PREFIX;
            }
            return ErrorCodes.UNKNOWN_ERROR;
        }
        ... blabla ...
        return ErrorCodes.OK;
    }

    Интересный подход

    debugger, 27 Марта 2015

    Комментарии (11)
  10. bash / Говнокод #17868

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    cat huiz.sh
    
    #!/bin/sh
    whois $1

    Нашёл на старом сервере.

    xvost, 26 Марта 2015

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

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // var doc = new Document(file);
    var stream = new MemoryStream();
    file.CopyTo(stream);
    file.Position = 0;
    stream.Position = 0;
    var doc = new Document(stream);

    Ебал в рот Spire.Doc
    Нагло жует чужие потоки
    Причем только если документ - RTF
    Какого хуя вообще?

    ebal, 18 Марта 2015

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