1. C# / Говнокод #12799

    +138

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static Dictionary<object, object> _cache = new Dictionary<object, object>();
    .........
    if( _cache.ContainsKey( key ) )
    {
      lock( syncRoot )
      {
        _cache[key] = value;
        return;
      }
    }
    _cache.Add( key, value );

    Бараньи мозги.

    grobotron, 25 Марта 2013

    Комментарии (6)
  2. Java / Говнокод #12798

    +83

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private static boolean getIsDeclinedByRules(boolean oldIsSatisfy, boolean oldIsDeclined, boolean newIsSatisfy) {
        if (!oldIsSatisfy &&  oldIsDeclined && !newIsSatisfy) return true;
        if (!oldIsSatisfy &&  oldIsDeclined &&  newIsSatisfy) return false;
        if (!oldIsSatisfy && !oldIsDeclined && !newIsSatisfy) return true;
        if (!oldIsSatisfy && !oldIsDeclined &&  newIsSatisfy) return false;
        if ( oldIsSatisfy &&  oldIsDeclined && !newIsSatisfy) return true;
        if ( oldIsSatisfy &&  oldIsDeclined &&  newIsSatisfy) return true;
        if ( oldIsSatisfy && !oldIsDeclined && !newIsSatisfy) return true;
        if ( oldIsSatisfy && !oldIsDeclined &&  newIsSatisfy) return false;
        return true;
      }

    glprizes, 25 Марта 2013

    Комментарии (16)
  3. C# / Говнокод #12797

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public event ConnectedHandler OnConnected;
    .......
    lock( OnConnected )
    {
        if( OnConnected != null )
        {
            OnConnected( ... );
        }
    }

    Быдломакронабиратели...

    grobotron, 25 Марта 2013

    Комментарии (4)
  4. ActionScript / Говнокод #12796

    −106

    1. 1
    2. 2
    //дальше идет "родной" движок, спасибо не надо.
    return;

    Разбираюсь в исходнике одного индуса, поддерживаемого 4 года нашими разработчиками

    KirAmp, 25 Марта 2013

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static function checkCurl()
    {
    	if (in_array("curl", get_loaded_extensions()))
    		return TRUE;
    	else
    		return FALSE;
    }

    function_exist? Не, не слышал. Мануалы для лохов.

    DrFreez, 25 Марта 2013

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

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    $targetFolder = 'uploads/'; // Relative to the root
    // ...
    $targetPath = dirname(__FILE__) . '/' . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['file']['name'];

    "Непостоянство слеша", Pedro Molina, 2013. Холст, масло
    https://github.com/pekebyte/pekeUpload/blob/940cf27e5fef5038e2e414c72be6e34d68f2881d/upload.php

    scriptin, 24 Марта 2013

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    if (Database::getDbType() == 'pgsql')
          $stmt = Database::getInstance()->dbh->prepare("SELECT COUNT(*) AS count FROM torrent WHERE tracker = :tracker AND torrent_id = :id");
    else
          $stmt = Database::getInstance()->dbh->prepare("SELECT COUNT(*) AS `count` FROM `torrent` WHERE `tracker` = :tracker AND `torrent_id` = :id");

    https://github.com/ElizarovEugene/TorrentMonitor/blob/master/class/Database.class.php#L625 УПРЛС

    DrFreez, 24 Марта 2013

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public static function checkPath($path)
    {
    	if (substr($path, -1) == '/')
    		$path = $path;
    	else
    		$path = $path.'/';
    	return $path;
    }

    facepalm.jpg

    DrFreez, 24 Марта 2013

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

    +158

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    public static function checkWriteToTorrentPath($path)
    {
    	if (file_put_contents($path.'file.txt', ' '))
    	{
    		unlink($path.'file.txt');
    		return TRUE;
    	}
    	else
    		return FALSE;
    }

    is_writable ? Не, не слышал!
    https://github.com/ElizarovEugene/TorrentMonitor/blob/master/class/System.class.php#L48 Эпик!

    DrFreez, 24 Марта 2013

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

    +13

    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
    CompoundExpression*
    CompoundExpression::newBinaryExpression(
    	BasicBinaryOperation::Type operation,
    	const Expression *x,
    	const Expression *y
    ) {
    	vector<Expression::const_pointer> params(2);
    	params[0] = x;
    	params[1] = y;
    	
    	// integer power optimization
    	if (operation == BasicBinaryOperation::POWER) {
    		if (y->isNumber()) {
    			Number::const_pointer number_y = dynamic_cast<typeof number_y>(y);
    			if (number_y != NULL && number_y->isIntegerNumber()) {
    				IntegerNumber::const_pointer integer_y = dynamic_cast<typeof integer_y>(number_y);
    				if (integer_y != NULL) {
    					operation = BasicBinaryOperation::INT_POWER;
    					return new CompoundExpression(BinaryOperation::getOperation(operation), params);
    				}
    			}
    		}
    	}
    	
    	// x^(y/n), where 'n' is odd integer
    	// transform to '(x^y)^(1/n)'
    	if (operation == BasicBinaryOperation::POWER) {
    		if (y->isCompoundExpression()) {
    			auto compoundExpressionY = dynamic_cast<CompoundExpression::const_pointer>(y);
    			if (compoundExpressionY != NULL && compoundExpressionY->operation->isBinary()) {
    				auto innerOperation = compoundExpressionY->operation;
    				auto binaryOperation = dynamic_cast<BinaryOperation const *>(innerOperation);
    				if (binaryOperation != NULL && binaryOperation->getType() == BasicBinaryOperation::DIVIDE) {
    					Expression::const_pointer   numerator = compoundExpressionY->params[0];
    					Expression::const_pointer denominator = compoundExpressionY->params[1];
    					if (denominator->isNumber()) {
    						auto numberDenominator = dynamic_cast<Number::const_pointer>(denominator);
    						if (numberDenominator != NULL && numberDenominator->isIntegerNumber()) {
    							auto integerDenominator = dynamic_cast<IntegerNumber::const_pointer>(numberDenominator);
    							if (integerDenominator != NULL && (integerDenominator->intValue() % 2) != 0) {
    								auto base = CompoundExpression::newBinaryExpression(BasicBinaryOperation::POWER, x, numerator);
    								return CompoundExpression::newBinaryExpression(BasicBinaryOperation::NTH_ROOT, integerDenominator, base);
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    
    	return new CompoundExpression(BinaryOperation::getOperation(operation), params);
    }

    Моё. Потребовалось воткнуть оптимизацию арифметического выражения некоторого вида. В результате родился вот такой костыль.

    UncleAli, 24 Марта 2013

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