1. JavaScript / Говнокод #7455

    +171

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $('#bc8').html('<style type="text/css">#bc8 {display:none;}</style>');
    $('#bc7').html('<style type="text/css">#bc7 {display:none;}</style>');
    $('#bc12').html('<style type="text/css">#bc12 {display:none;}</style>');
    $('#bc16').html('<style type="text/css">#bc16 {display:none;}</style>');
    $('#bc18').html('<style type="text/css">#bc18 {display:none;}</style>');
    $('#bc17').html('<style type="text/css">#bc17 {display:none;}</style>');
    $('#bc9').html('<style type="text/css">#bc9 {display:none;}</style>');

    Хороший jQuery-программист

    TRANE73, 05 Августа 2011

    Комментарии (19)
  2. C# / Говнокод #7454

    +126

    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
    // Get credit spread rates and tenors
    mDtCreditSpreadTenors = aRDO.GetResultTable(mSelectCreditSpreadRates, mCode, mCreditSpreadCurveDate);
    
    // Check if any credit spread rates are returned
    if (mDtCreditSpreadTenors.Rows.Count == 0)
    {
        // If debugging
        if (System.Diagnostics.Debugger.IsAttached)
            // Get from fixed date
            mDtCreditSpreadTenors = aRDO.GetResultTable(mSelectCreditSpreadRates, mCode, 39396);
        else        
            // Add error
            aMissingData.Add(string.Format("Cannot find credit spread rates for date {0}", mCreditSpreadCurveDate.ToShortDateString()));
    }

    Счастливой отладки, суки!

    xxxcoderxxx, 05 Августа 2011

    Комментарии (5)
  3. PHP / Говнокод #7453

    +146

    1. 1
    2. 2
    3. 3
    public static function correctTextForHTML($inSTR) {
         return preg_replace("/\r\n|\n|\r/", "<br/>", $inSTR);
    }

    Sers, 05 Августа 2011

    Комментарии (20)
  4. PHP / Говнокод #7452

    +147

    1. 1
    2. 2
    3. 3
    public static function prepareHTML ($inStr) {
    		return htmlspecialchars(htmlspecialchars_decode($inStr));
    	}

    Sers, 05 Августа 2011

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

    +163

    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
    /**
    	 * удаляет ненужные нули для дробных значений
    	 *
    	 * @return unknown
    	 */
    	public static function removeExtraZero($power) {
    		if ($power == '') return "";
    
    		$a_tmp = explode('.', $power);
    		$a_tmp[1] = rtrim($a_tmp[1], '0');
    		if ($a_tmp[1] == '') return $a_tmp[0];
    		return $a_tmp[0] . '.' . $a_tmp[1];		
    	}

    Аналогия floatval()

    Sers, 05 Августа 2011

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

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    $em = '';
    	    foreach(array_unique(explode(',', $ae)) as $u) {
    		 if(!$u)
    		    continue;
    		  if($em)
    		    $em .= ',';
    		$em .= $u;
    	    }

    Кому сколько времени понадобилось, чтоб понять, что делает этот код?

    partizan22, 05 Августа 2011

    Комментарии (2)
  7. Куча / Говнокод #7449

    +140

    1. 1
    <a href='javascript:go("http://www.site.ru/?id=2167&lang=ru&ct=3&cid=2167&r=2167")' class="A_ThirdSelected"><nobr>Экономика</nobr></a>

    Функция go просто переадресовывает на нужный адрес. Видать писать ссылки в href уже не модно

    jQuery, 04 Августа 2011

    Комментарии (17)
  8. 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)
  9. 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)
  10. 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)