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

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

    +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
    <p>
                    <script>// <![CDATA[
                        if (navigator.appVersion.indexOf("Win") != -1) {
                            document.getElementById("windows").style.display = "inline";
                        } else if (navigator.appVersion.indexOf("Mac") != -1) {
                            document.getElementById("osx").style.display = "inline";
                        } else if (navigator.appVersion.indexOf("Linux") != -1) {
                            document.getElementById("linux").style.display = "inline";
                        } else {
                            document.getElementById("windows").style.display = "inline";
                            document.getElementById("osx").style.display = "inline";
                            document.getElementById("linux").style.display = "inline";
                        }
                        // ]]&gt;</script>
                </p>

    Недавно один Java-pазработчик не смог разобраться, как пофиксеть баг в WordPress и решил переписать наш корпоративный сайт на Java мотивируя это тем, что будет намного легче поддерживать и развивать новую ситсему. Что из этого получилось видно на наглядном примере js-кода в верстке.

    etual, 27 Февраля 2015

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

    +56

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    `        enum SearchFlag
             {
                 IgnoreCase = 0x00000001,    ///< Case differences are ignored
    -            WholeWorlds = 0x00000002    ///< Only whole words are matched
    +            WholeWords = 0x00000002    ///< Only whole words are matched
             };

    очепятка + копи-паста = world domination.

    http://lists.freedesktop.org/archives/poppler/2015-January/011251.html

    http://cgit.freedesktop.org/poppler/poppler/commit/?id=78abf540057181b708c546aee421f81a1dd5 8331

    Dummy00001, 22 Января 2015

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

    +155

    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
    public function actionNominate()
    	{
    		if (isset($_POST['user']) and isset($_POST['ref']))
    		{
    
    			$user = $ref = NULL;
    			$user = strip_tags(trim($_POST['user']));
    			$ref = strip_tags(trim($_POST['ref']));
    
    			$test = UserAwardsRef::model()->count(array("condition"=>"id_ref=$ref AND id_user=$user"));
    
    			if ($test==0)
    			{
    				if ($user and $ref)
    				{
    					$model = new UserAwardsRef();
    					$model->id_ref = $ref;
    					$model->id_user = $user;
    					if ($model->save())
    					{
    						echo 1;
    					} else {
    						echo 'error';
    					}
                    } else {
    
    					echo "error";
    				}
    
    			} else {
    				echo 2;
    			}
    
    		} else {
    
    			echo "error";
    		}
    
    	}

    Входящие параметры предполагаются - integer
    Необходимо один раз насрать в таблицу с ключами из поста.

    obidnov, 16 Января 2015

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

    +133

    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace nonopt
    {
        class Program
        {
            static void Main(string[] args)
            {
                string h = "h";
                string e = "e";
                string l1 = "l";
                string l2 = "l";
                string o1 = "o";
                string he = h + e;
    			string ll = l1 + l2;
                string hell = he + ll;
                string hello = hell + o1;
                string w = "w";
                string o2 = "o";
                string r = "r";
                string l3 = "l";
                string d = "d";
                string wo = w + o2;
                string rl = r + l3;
                string worl = wo + rl;
                string world = worl + d;
                string empty = " ";
                Console.WriteLine(hello + empty + world);
    			Console.ReadKey();
            }
        }
    }

    pewppy, 10 Января 2015

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

    +157

    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
    $('.file_work .left .content a.create').bind('click', function(){
            show.in_question(strings.question[2], {
                0:strings.question[2].buttons[0], 
                1:strings.question[2].buttons[1]
            }, function(action, string){
                if(action !='ok'){
                    return;
                }
                if(string.length<4){
                    show.error(strings.error[7], '');
                    return;
                }
                CreateTag(cache.current, string);
            });
        });

    хуита, 22 Декабря 2014

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