1. Список говнокодов пользователя UncleAli

    Всего: 4

  2. Objective C / Говнокод #12964

    −100

    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
    {
    	//replace common symbols...
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"&" withString:@"and"]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"!" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"#" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"$" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"%" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"^" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"*" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"(" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@")" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"+" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"=" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"|" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"\\" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"?" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@">" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"<" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@";" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@":" withString:@""]];
    	[createWrapperName setStringValue:[[createWrapperName stringValue] stringByReplacingOccurrencesOfString:@"@" withString:@""]];
    	// ...
    }

    Так-то.

    Источник: https://sourceforge.net/p/wineskin/code/ci/master/tree/Wineskin%20Winery/Wineskin_WineryAppDelegate.m

    P. S. А тулза, между прочим, нужная. Наткнулся на багу, полез фиксить. Увидев AppDelegate.m на 2700+ строк, заинтересовался, и не зря: вышеприведенное — мелочи.

    UncleAli, 03 Мая 2013

    Комментарии (16)
  3. 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)
  4. Objective C / Говнокод #12788

    −116

    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
    { 
        NSString *xContent = myTextView.text;
        
        //temp file filename
        NSString *tmpFileName = @"test1.html";
        
        //temp dir
        NSString *tempDir = NSTemporaryDirectory();
        NSLog(@"tempDirectory: %@",tempDir);
        
        //create NSURL
        NSString *path4 = [tempDir stringByAppendingPathComponent:tmpFileName];
        NSURL* url = [NSURL fileURLWithPath:path4]; 
        
        //setup HTML file contents
        NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MathJax" ofType:@"js" inDirectory:@"mathjax-MathJax-v2.0"];
        NSLog(@"filePath = %@",filePath);
        
        //write to temp file "tempDir/tmpFileName", set MathJax JavaScript to use "filePath" as directory, add "xContent" as content of HTML file
        [self writeStringToFile:tempDir fileName:tmpFileName pathName:filePath content:xContent];
        
        NSURLRequest* req = [[NSURLRequest alloc] initWithURL:url]; 
        
        //original request to show MathJax stuffs
        [myWebView loadRequest:req];
    }
    
     -(void)writeStringToFile:(NSString *)dir fileName:(NSString *)strFileName pathName:(NSString *)strPath content:(NSString *)strContent{
        
        NSString *path = [dir stringByAppendingPathComponent:strFileName];
        
        NSString *foo0 = @"<html><head><meta name='viewport' content='initial-scale=1.0' />"
    "<script type='text/javascript' src='";
        
        NSString *foo1 = @"?config=TeX-AMS-MML_HTMLorMML-full'></script>"
        "</head>"
        "<body>";
        NSString *foo2 = @"</body></html>";
        NSString *fooFinal = [NSString stringWithFormat:@"%@%@%@%@%@",foo0,strPath,foo1,strContent,foo2];
        
        [fooFinal writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:nil];
    }

    http://new2objectivec.blogspot.com/2012/03/tutorial-how-to-setup-mathjax-locally.html

    Здорово, правда?

    UncleAli, 23 Марта 2013

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

    +161

    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
    function render_menu_item($tag,$value,$css=null){
    $length=strlen($tag);
       
        //Validate the tags
          if($tag[0]=='<' && $tag[$length-1]=='>'){
            $closingtag=str_replace('<','</',$tag);
            if($css)
                $tag=str_replace('>',' class="'.$css.'">',$tag);        
          }
          else{
            if($css){       
            $classtag='<'.$tag.' class="'.$css.'">';
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            $tag=$classtag;
            }
            else{
            $tag='<'.$tag.'>';
            $closingtag=str_replace('<','</',$tag);
            }
          }  
      return $tag.$value.$closingtag;
    }

    Вот так пишут доблестные Drupal-разработчики из Иордании. Сохранено оригинальное форматирование.

    UncleAli, 13 Мая 2010

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