1. Java / Говнокод #7448

    +147

    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
    String classToType(Class cls) {
        if (cls == Point.class) {
          return "int2";
        } else if ((cls == Integer.TYPE) || (cls == Integer.class)) {
          return "int";
        } else if ((cls == Double.TYPE) || (cls == Double.class)) {
          return "double";
        } else if (cls == String.class) {
          return "String";
        } else if ((cls == Boolean.TYPE) || (cls == Boolean.class)) {
          return "boolean";
        } else {
          return null;
        }
      }

    Lure Of Chaos, 04 Августа 2011

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

    −92

    1. 1
    my_age = [lambda k, f=f: f**k for f in xrange(10) if 'I want'][4](2) + 2

    F**k yeah...

    Niceblack, 04 Августа 2011

    Комментарии (4)
  3. Java / Говнокод #7445

    +76

    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
    public class ThreadPoolExecutor implements Executor {
    	private int maximumPoolSize; 	// ìàêñèìàëüíîå êîëè÷åñòâî ïîòîêîâ
    	private long keepAliveTime; 	// âðåìÿ îæèäàíèÿ íîâîé çàäà÷è
    	private Integer poolSize;			// êîëè÷åñòâî ñîçäàííûõ ïîòîêîâ
    	private Vector workQueue;			// î÷åðåäü çàäà÷
    	private Vector threadPool;			// ïóë ïîòîêîâ
    
    	public ThreadPoolExecutor(int maxPoolSize, long time) {
    		this.maximumPoolSize = maxPoolSize;
    		this.keepAliveTime = time;
    		this.poolSize = new Integer(0);
    		workQueue = new Vector();
    		threadPool = new Vector();
    		new Thread() {	
    			public void run() {
    				for (;;) {
    					try {
    						Thread.sleep(keepAliveTime);
    					} catch (InterruptedException e) {
    						System.out.println("interrupted");
    					}
    					interruptIfIdle();
    				}
    			}
    		}.start();
    	}
    
    	public void execute(Runnable task) {
    		if (task == null)
    			throw new NullPointerException();
    		workQueue.addElement(task);
    		for (;;) {
    			int status = addIfUnderMaximumPoolSize(task);
    			if (status > 0)
    				return;
    			if (status == 0) {
    				reject(task);
    				return;
    			}
    		}
    	}
    	
    	public void shutdown() {
    		if (threadPool.size() > 0) 
    			for (int i=0; i < threadPool.size(); i++) {
    				((Thread) threadPool.elementAt(i)).interrupt();
    			}
    	}
    	
    	public void reject(Runnable task) {
    		//
    	}
    	
    	private int addIfUnderMaximumPoolSize(Runnable task) {
    		Thread t = null;
    		int status = 0;
    		synchronized (poolSize) {
    			if (poolSize.intValue() < maximumPoolSize) {
    				Runnable next = (Runnable) workQueue.elementAt(0);
    				workQueue.removeElementAt(0);
    				if (next == task) {
    					status = 1;
    				} else
    					status = -1;
    				t = addThread(next);
    			}	
    		}
    		return status;
    	}
    	
    	private Thread addThread(Runnable task) {
    		Thread thread = new Thread(task);
    		threadPool.addElement(thread);
    		thread.run();
    		poolSize = new Integer(poolSize.intValue()+1);
    		return new Thread();
    	}
    		
    	private void interruptIfIdle() {
    		synchronized (threadPool) {
    			for (int i=0; i < threadPool.size(); i++) {
    				try {
    					((Thread) threadPool.elementAt(i)).interrupt();
    				} finally {
    					poolSize = new Integer(poolSize.intValue()-1);
    				}
    			}
    		}
    	}
    	
    }

    Junior пишет весьма упрощенный ThreadPoolExecutor для BlackBerry (сорри, не тот пост кинул в прошлый раз).

    enikey, 04 Августа 2011

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

    +152

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    if (getMaterialDom().ztest_)
     {
      device.SetRenderState(D3DRS_ZENABLE, TRUE);
      device.SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
     }
     else
      device.SetRenderState(D3DRS_ZENABLE, FALSE);
    
    if (getMaterialDom().zwrite_)
    	device.SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
    else
    	device.SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

    Реализация параметров материала z-test и z-write в 3D-движке.

    Kirinyale, 04 Августа 2011

    Комментарии (30)
  5. Куча / Говнокод #7443

    +144

    1. 1
    Чтобы удалить или заблокировать пользователя, наведите курсор на его фотографию.

    из одноглазников

    jQuery, 04 Августа 2011

    Комментарии (12)
  6. JavaScript / Говнокод #7442

    +174

    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
    var reps = 2
    var speed = 500
    
    var message = '0';
    var p='15';
    var T="";
    var C=0;
    var mC=0;
    var s=0;
    var sT=null;
    if(reps<1)reps=1;
    function doTheThing(){
    T=message[mC];
    A();}
    function A()
    {
    s++
    if(s>15){s=1}
    
    if(s==1){document.title='W'}
    if(s==2){document.title='WE'}
    if(s==3){document.title='WEL'}
    if(s==4){document.title='WELC'}
    if(s==5){document.title='WELCO'}
    if(s==6){document.title='WELCOM'}
    if(s==7){document.title='WELCOME'}
    if(s==8){document.title='WELCOME T'}
    if(s==9){document.title='WELCOME TO'}
    if(s==10){document.title='WELCOME TO M'}
    if(s==11){document.title='WELCOME TO MY'}
    if(s==12){document.title='WELCOME TO MY S'}
    if(s==13){document.title='WELCOME TO MY SI'}
    if(s==14){document.title='WELCOME TO MY SIT'}
    if(s==15){document.title='WELCOME TO MY SITE'}
    
    if(C<(8*reps)){
    sT=setTimeout("A()",speed);
    C++
    }else{
    C=0;
    s=0;
    mC++
    if(mC>p-1)mC=0;
    sT=null;
    doTheThing();}}
    doTheThing();

    Накопал на древнем сайте по веб-дизайну, какого то самоучки )
    ощущение что делалось чтобы показать как не надо делать , но лежало без подписей вообще

    nazymko, 04 Августа 2011

    Комментарии (20)
  7. Java / Говнокод #7441

    +72

    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
    package com.uva.concurrent;
    
    import com.uva.log.Log;
    import com.uva.log.Message;
    
    public class ThreadExecutor implements Executor {
    	private final String name;
    
    	public ThreadExecutor(String name) {
    		this.name = name;
    	}
    
    	public void execute(Runnable target) {
    		new Thread(target, name).start();
    	}
    	
    	/** Execute given runnable in separate thread. All exceptions will be caught.
    	 * @param runnable - runnable to execute. */
    	public void executeSilent(final Runnable runnable) {
    		new Thread() {	
    			public void run() {
    				try {
    					runnable.run();
    				} 
    				catch (RuntimeException e) {
    					Log.exception(name, Message.CRITICAL_ERROR, e);
    					throw e;
    				}
    			}
    		}.start();
    	}
    }

    Junior пишет весьма ThreadPoolExecutor для BlackBerry.

    enikey, 04 Августа 2011

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

    +147

    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
    {
        //-----------------------------------------
        // Declare and initialize variables
        WSADATA wsaData;
        int iResult = 0;
    
        int iError = 0;
        INT iNuminfo = 0;
    
        int i;
    
        // Allocate a 16K buffer to retrieve all the protocol providers
        DWORD dwBufferLen = 16384;
    
        LPWSAPROTOCOL_INFO lpProtocolInfo = NULL;
    
        // variables needed for converting provider GUID to a string
        int iRet = 0;
        WCHAR GuidString[40] = { 0 };
    
        // Initialize Winsock
        iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
        if (iResult != 0) {
            wprintf(L"WSAStartup failed: %d\n", iResult);
            return 1;
        }
    
        lpProtocolInfo = (LPWSAPROTOCOL_INFO) MALLOC(dwBufferLen);
        if (lpProtocolInfo == NULL) {
            wprintf(L"Memory allocation for providers buffer failed\n");
            WSACleanup();
            return 1;
        }
    
        iNuminfo = WSAEnumProtocols(NULL, lpProtocolInfo, &dwBufferLen);
        if (iNuminfo == SOCKET_ERROR) {
            iError = WSAGetLastError();
            if (iError != WSAENOBUFS) {
                wprintf(L"WSAEnumProtocols failed with error: %d\n", iError);
                if (lpProtocolInfo) {
                    FREE(lpProtocolInfo);
                    lpProtocolInfo = NULL;
                }
                WSACleanup();
                return 1;
            } else {
                wprintf(L"WSAEnumProtocols failed with error: WSAENOBUFS (%d)\n",
                        iError);
                wprintf(L"  Increasing buffer size to %d\n\n", dwBufferLen);
                if (lpProtocolInfo) {
                    FREE(lpProtocolInfo);
                    lpProtocolInfo = NULL;
                }
                lpProtocolInfo = (LPWSAPROTOCOL_INFO) MALLOC(dwBufferLen);
                if (lpProtocolInfo == NULL) {
                    wprintf(L"Memory allocation increase for buffer failed\n");
                    WSACleanup();
                    return 1;
                }
                iNuminfo = WSAEnumProtocols(NULL, lpProtocolInfo, &dwBufferLen);
                if (iNuminfo == SOCKET_ERROR) {
                    iError = WSAGetLastError();
                    wprintf(L"WSAEnumProtocols failed with error: %d\n", iError);
                    if (lpProtocolInfo) {
                        FREE(lpProtocolInfo);
                        lpProtocolInfo = NULL;
                    }
                    WSACleanup();
                    return 1;
                }
    
            }
        }
    
        wprintf(L"WSAEnumProtocols succeeded with protocol count = %d\n\n",
                iNuminfo);
        for (i = 0; i < iNuminfo; i++) {
            wprintf(L"Winsock Catalog Provider Entry #%d\n", i);
    
    --- skipped ---
    
            wprintf(L"\n");
        }
    
        if (lpProtocolInfo) {
            FREE(lpProtocolInfo);
            lpProtocolInfo = NULL;
        }
        WSACleanup();
    
        return 0;
    }

    http://msdn.microsoft.com/en-us/library/ms741574(v=VS.85).aspx

    Я считаю это говнокодом, т.к. автор данного примера страдает сильнейшие паранойей. Всем переменным он присваивает нолики, например перед return строки 87, 52 и т.д. ... Даже iResult, lpProtocolInfo и т.д. в начале...

    fddpro, 04 Августа 2011

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

    +160

    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
    // File: /controllers/register.php
    
    //......
    $sql = 'INSERT INTO `users` SET `ID`=NULL, `login`="'.mysql_real_escape_string(substr($_POST['login'], 0, 12)).'", `pass`= blah blah blah....';
    //......
    
    
    
    // File: /templates/default/index.tpl
    /*
    //... 
    <td><div>Hello, <b>{LOGIN}</b></div><!---- blah blah blah ---><div>Server time: <?php echo getCurrentTime();?></div>
    //
    */
    
    
    //File: /index.php
    
    //......
    $sql = 'SELECT * FROM `users` WHERE `id`=........';
    $data = SYS::$db->getDataRow($sql);
    if(sizeof($data)>0) {
          showTeplate(TEMPLATE_NAME, 'index', $data);
    }
    //......
    
    //Function showTeplate();
    
    function showTeplate($tpl_name, $file_name, $data) {
           $template_code = file_get_contents(TPL_PATH.'/'.$tpl_name.'/'.$file_name.'.'.TPL_EXT);
           foreach($data as $name=>$value) {
                  $template_code = str_replace('{'.strtoupper($name).'}', $value, $template_code);
           }
           
          //......
           eval($template_code);
          //......
    
    }

    Внимание, загадка! Найти уязвимость.

    jokz, 04 Августа 2011

    Комментарии (24)
  10. JavaScript / Говнокод #7438

    +164

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function withoutCyr(inрut) {
      var value = inрut.value;
      var re = /а|б|в|г|д|е|ё|ж|з|и|й|ё|к|л|м|н|о|п|р|с|т|у|ф|х|ц|ч|ш|щ|ъ|ы|ь|э|ю|я/gi;
        if (re.test(value)) {
             value = value.replace(re, '');
             inрut.value = value;
       }
    }

    jQuery, 03 Августа 2011

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