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

    В номинации:
    За время:
  2. 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)
  3. 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)
  4. 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)
  5. bash / Говнокод #17868

    −106

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

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

    xvost, 26 Марта 2015

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

    +138

    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
    #define poff    acurp + curp * (nSQs+2)        /*probs: offset*/
    long psum() {return  c(poff+ 1);}    long pmax()    {return c(poff+2);}
    long pn     (long n)                {return          c(poff+2+n);   }
    void setp   (long n, long x){set    (poff+2+n, x);} /*prob changes:*/ 
    void setmax         (long x){set    (poff+2,   x);} /*metasearching*/
    void setsum         (long x){set    (poff+1,   x);}
    long get2ndmax()    {long n= poff+2, x=pmax(), m=n,  s=0,end=n+nSQs;   
         do     {n++;}   while  (c(n) != x);  /*find 2nd-highest <=pmax*/     
         do     {m++;    if (s < c(m) && m !=n) s= c(m);}/*jue tncheck?*/
                 while      (s < x    && m < end);       return  s;}
    void addtoSQ(long i, long val) {long x;   /*increase prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  psum()+val;if (x > maxint) return;   /*has max normalizer*/
         setsum (x);    /*normalizer +*/ x =  pn(i)+val; setp(i, x); 
         if (x > pmax()) setmax (x);}   /*maximal SQprob has increased */    
    void subofSQ(long i, long val) {long x;   /*decrease prob of ith SQ*/
         if  (val < 1 || i >nSQs || i<1) return;        /*not possible!*/
         x =  pn(i)-val; if (x < 0)      return;/*no neg probabilities!*/
         setsum (psum()- val);           setp(i,x);/*don't check if =0!*/   
         if (x + val  == pmax()) setmax (get2ndmax());} /*change of max*/
    void incSQ()        {long i= top();  addtoSQ(i,1);} /*top, not pop!*/
    void decSQ()        {long i= top(),  x,y,z; /*decrem prob of the SQ*/
         if  (i> nSQs   || i< 1) return;/*no such search Q number known*/
         x =  pn(i);     if     (x==0)   return;        /*SQ: already 0*/
         y  = psum();    z =     pmax();              
         if  (x == 1 &&  y    <= z+1)    stop    /*leave at least 2 SQs*/
         if  (x == z)    setmax         (get2ndmax());  /*change of max*/
         setp(i, x-1);   setsum (y-1);}                 /*normalizer -1*/
    long upSQ;          /*SQ probability:enumerator  +=  upSQ: increase*/
    void oldSQ()   {long a=pop()+ndecl,  n,i; if(a<0||a> oldp)stop/*bad*/
         n=old[a].size;  a=old[a].start;/*all SQs of old nondecl: +upSQ*/
         tncheck  n+=a;  for(i=a;i<n;i++)addtoSQ(SQ[q[i].Q],     upSQ);}
    
    void setpat()       {long i= pop(); /*instantiate my search pattern*/
         if  (i<0 || i > patp)     stop /*no such search pattern exists*/
         set (acurp,i);}/*next SQ-search defined via new probabilities!*/
    void pupat()        {long    i  =    apatp;   /*push search pattern*/ 
         if  (i>maxpat)  stop    i++;    set(apatp,i);  /*not too many?*/
         cpabn  (poff+1, acurp + 1 + i *(2+ nSQs),       2 + nSQs,  
                                         acurp + 1,      aendpats);     }  
    void popat()        {long i= apatp;  if(i==0)   stop
         set(apatp,i-1); push(i); }                /*pop search pattern*/

    Полный исходник http://www.idsia.ch/~juergen/oopscode.c

    j123123, 17 Марта 2015

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

    +135

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define   CONC_LINE(a)  CONC(a, __LINE__)
    #define   CONC(a, b)  __CONC(a, b)
    #define __CONC(a, b)  a##b
    // ...
    int CONC_LINE(name);

    Способ присовокупить к названию переменной номер строки, где её объявили.
    Объясните кто-нибудь, почему #define CONC_LINE (a) __CONC ( a, __LINE__ ) дает: name__LINE__?

    refactor, 11 Марта 2015

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

    +158

    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
    <?PHP
    	
    	# Регистрация
    
    	if(isset($_POST["login"])){
    	
    	if(isset($_SESSION["captcha"]) AND strtolower($_SESSION["captcha"]) == strtolower($_POST["captcha"])){
    	unset($_SESSION["captcha"]);
    
    	$login = $func->IsLogin($_POST["login"]);
    	$pass = $func->IsPassword($_POST["pass"]);
    	$rules = isset($_POST["rules"]) ? true : false;
    	$time = time();
    	$ip = $func->UserIP;
    	$UserIP = $_SERVER['REMOTE_ADDR'];
    	
    	$email = $func->IsMail($_POST["email"]);
    	$referer_id = (isset($_COOKIE["i"]) AND intval($_COOKIE["i"]) > 0 AND intval($_COOKIE["i"]) < 1000000) ? intval($_COOKIE["i"]) : 1;
    	$referer_name = "";
    	if($referer_id != 1){
    		$db->Query("SELECT user FROM db_users_a WHERE id = '$referer_id' LIMIT 1");
    		if($db->NumRows() > 0){$referer_name = $db->FetchRow();}
    		else{ $referer_id = 1; $referer_name = "wolframavtor"; }
    	}else{ $referer_id = 1; $referer_name = "wolframavtor"; }
    	
    		if($rules){
    
    			if($email !== false){
    		
    			if($login !== false){
    			
    				if($pass !== false){
    			
    					if($pass == $_POST["repass"]){
    						
    						$db->Query("SELECT COUNT(*) FROM db_users_a WHERE user = '$login'");
    						if($db->FetchRow() == 0){
    						
    						# Регаем пользователя
    						$db->Query("INSERT INTO db_users_a (user, email, pass, referer, referer_id, date_reg, ip) 
    						VALUES ('$login','{$email}','$pass','$referer_name','$referer_id','$time',INET_ATON('$ip'))");
    						
    						$lid = $db->LastInsert();
    						
    						$db->Query("INSERT INTO db_users_b (id, user, a_t, last_sbor) VALUES ('$lid','$login','1', '".time()."')");
    						
    						# Вставляем статистику
    						$db->Query("UPDATE db_stats SET all_users = all_users +1 WHERE id = '1'");
    						
    						echo "<center><b><font color = 'green'>Вы успешно зарегистрировались. Используйте форму слева для входа в аккаунт</font></b></center><BR />";
    						?></div>
    						<div class="clr"></div>	
    						<?PHP
    						return;
    						}else echo "<center><b><font color = 'red'>Указанный логин уже используется</font></b></center><BR />";
    						
    					}else echo "<center><b><font color = 'red'>Пароль и повтор пароля не совпадают</font></b></center><BR />";
    			
    				}else echo "<center><b><font color = 'red'>Пароль заполнен неверно</font></b></center><BR />";
    			
    			}else echo "<center><b><font color = 'red'>Логин заполнен неверно</font></b></center><BR />";
    
    		}else echo "<center><font color = 'red'><b>Email имеет неверный формат</b></font></center>";
    
    		}else echo "<center><b><font color = 'red'>Вы не подтвердили правила</font></b></center><BR />";
    	
    		}else echo "<center><font color = 'red'><b>Символы с картинки введены неверно</b></font></center>";
    
    	}
    	
    	
    ?>

    ШЕДЕВРАЛЬНО!

    proweber1, 09 Марта 2015

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

    +79

    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
    private short findHeaderLength() {
        return (short)(
            1+
            3+
            4+
            2+
            2+
            2+
            1+
            1+
            4+
            4+
            4+
            1+
            1+
            2+
            (32*fieldArray.length)+
            1
        );
    }

    DBFHeader

    bormand, 06 Марта 2015

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

    +51

    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
    #include <ppl.h>
    #include <windows.h>
    #include <ppltasks.h>
    #include <iostream>
    #include <vector>
    
    using namespace Concurrency;
    using namespace std;
    
    CRITICAL_SECTION cs6;
    
    int main(int argc, char* argv[])
    {
    	size_t concurentThreadsSupported = std::thread::hardware_concurrency();
    	cout << concurentThreadsSupported << endl;
    	//deadlock hazard increased with concurentThreadsSupported decreasing
    
    	size_t taskAmountForWasteVirtualCores = concurentThreadsSupported - 1;//must be equal to (virtual processor thread amount from Concurrency::IResourceManager) - 1
    	vector<task<void>> t;
    	for (size_t i = 0; i<taskAmountForWasteVirtualCores; ++i)
    		t.push_back(create_task([]{
    			Sleep(INFINITE);//some very long IO operation or deadlocked by EnterCriticalSection or sql transaction or other
    		}));
    	Sleep(1000);
        cout << "another way:" << endl;
        InitializeCriticalSection(&cs6);
        auto locker = create_task([]{
            cout << "locker" << endl;
            EnterCriticalSection(&cs6);//same as begin sql transaction
            cout << "locker entered cs 6" << endl;
            Concurrency::wait(500);//Deadlock by any concurrency context switching directly or indirectly by std or MFC (events, mutex, etc)
            cout << "locker played" << endl;
            LeaveCriticalSection(&cs6);//same as end sql transaction
            cout << "~locker ok" << endl;
        });
        auto locked = create_task([]{
            cout << "locked" << endl;
            EnterCriticalSection(&cs6);//same as begin sql transaction
            cout << "locked entered cs 6" << endl;
            Concurrency::wait(500);
            cout << "locked played" << endl;
            LeaveCriticalSection(&cs6);//same as end sql transaction
            cout << "~locked ok" << endl;
        });
    	Sleep(1000);
    	cout << "FAIL" << endl;
    	return 0;
    }

    Нашел дидлок)
    http://rextester.com/KHC72232
    http://rextester.com/EMG65441

    laMer007, 04 Марта 2015

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