1. Objective C / Говнокод #12884

    −112

    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
    +(NSString*)filterDigits:(NSString*)number
    {
        unichar zer = '0', nine = '9', cur;
        unsigned long l = [number length];
        NSMutableData *buf = [NSMutableData data];
        for (unsigned long j = 0; j!=l; j++)
        {
            cur = [number characterAtIndex:j];
            if (cur>=zer&&cur<=nine)
            {
                char digit = (char)cur;
                [buf appendBytes:&digit length:sizeof(char)];
            }
            
        }
        NSString* ret = [[[NSString alloc] initWithData:buf encoding:NSUTF8StringEncoding] autorelease];
        return ret;
    }

    Золотые у тебя руки парень. Но всеравно не оттуды растут (;

    Psionic, 11 Апреля 2013

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

    +149

    1. 1
    2. 2
    3. 3
    // Hack - blacklist
    if ($msg->abonent == '12345678910')
        die("Database error");

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

    neTpyceB, 11 Апреля 2013

    Комментарии (2)
  3. SQL / Говнокод #12882

    −163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $query = $sql -> query("SELECT *, COUNT(`id`) as count FROM `d_download` WHERE `id` = '{$id}'", true);
    
    if($query['count'] == 1) {
     // code
    }

    Проверка, что значение найдено.

    neTpyceB, 11 Апреля 2013

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

    −102

    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
    93. 93
    94. 94
    @interface CORERatingImages : NSObject
    {
        UIImage *imageForOne;
        UIImage *imageForTwo;
        UIImage *imageForThree;
        UIImage *imageForFour;
        UIImage *imageForFive;
    }
    +(CORERatingImages *) ratingImages;
    -(UIImage *) getRatingImage:(int) ratings;
    @property (nonatomic, retain) UIImage *imageForOne;
    @property (nonatomic, retain) UIImage *imageForTwo;
    @property (nonatomic, retain) UIImage *imageForThree;
    @property (nonatomic, retain) UIImage *imageForFour;
    @property (nonatomic, retain) UIImage *imageForFive;
    -(void) releaseResources;
    @end
    
    static CORERatingImages *ratingImages = nil;
    
    @implementation CORERatingImages
    @synthesize imageForOne;
    @synthesize imageForTwo;
    @synthesize imageForThree;
    @synthesize imageForFour;
    @synthesize imageForFive;
    
    +(CORERatingImages *) ratingImages
    {
        @synchronized(self)
        {
            if (ratingImages == nil)
            {
                ratingImages = [[self alloc] init];
            }
        }
        return ratingImages;
    }
    -(id) init
    {
        if (self = [super init])
        {
            self.imageForOne = [UIImage imageNamed:@"1.png"];
            self.imageForTwo = [UIImage imageNamed:@"2.png"];
            self.imageForThree = [UIImage imageNamed:@"3.png"];
            self.imageForFour = [UIImage imageNamed:@"4.png"];
            self.imageForFive = [UIImage imageNamed:@"5.png"];
        }
        return self;
    }
    -(UIImage *) getRatingImage:(int) ratings
    {
        if (ratings == 1)
        {
            return imageForOne;
        }
        else if (ratings == 2)
        {
            return imageForTwo;
        }
        else if (ratings == 3)
        {
            return imageForThree;
        }
        else if (ratings == 4)
        {
            return imageForFour;
        }
        else if (ratings == 5)
        {
            return imageForFive;
        }
        else
        {
            return [UIImage imageNamed:@"0.png"];
        }
    }
    -(void) dealloc
    {
        NSLog(@"release Images");
        [imageForOne release];
        [imageForTwo release];
        [imageForThree release];
        [imageForFour release];
        [imageForFive release];
        [super dealloc];
    }
    -(void) releaseResources
    {
        [ratingImages release];
        ratingImages = nil;
    }
    
    @end

    Массив или stringWithFormat: @"%d.png"?

    Не, не слышал.

    QuickNick, 11 Апреля 2013

    Комментарии (15)
  5. Python / Говнокод #12880

    −97

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    @render_to_json()
    def view(request):
        # ...
        return {'name':obj.name for obj in
                    Company.objects.filter(id=cid, is_valid=True)}

    Не, ну а чё? )

    Crazyzubr, 11 Апреля 2013

    Комментарии (26)
  6. Objective C / Говнокод #12879

    −113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if ([_categories count] != 0) {
        for (NSString *item in _categories) {
            [path appendFormat:@"categories/%@/", item];
        }
    }

    Случайно обнаружил у себя :)

    zummenix, 10 Апреля 2013

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

    +150

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    $Not = array('\\',",","/","¬","#",";",":","~","[","]","{","}",")","(","*","^","%","$","<",">","?","!",'"',"'","|");
    ...
    
    function check($string){
    $string = preg_replace("/[^a-zA-Z a-яА-яёЁ]/i", "",$string);
    $string = str_replace($Not,'',$string);
    $string = htmlspecialchars($string);
    
    return $string;
    }

    Нашёл у себя убойный фильтр. Работает как зверь :-)

    straga_coda, 10 Апреля 2013

    Комментарии (5)
  8. Objective C / Говнокод #12877

    −113

    1. 1
    2. 2
    3. 3
    4. 4
    + (BOOL) isInteger:(CGFloat) number
    {
        return number - (int) number<0.0001;
    }

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

    Xtasy, 10 Апреля 2013

    Комментарии (39)
  9. Assembler / Говнокод #12876

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    xorl %eax, %eax                           # cx - source, ebx - result
        movw %cx, %ax
        andw $0x8000, %ax
        shrw $15, %ax
        movl $0xFFFFFFFF, %ebx
        addl %eax, %ebx
        notl %ebx
        andl $0xffff0000, %ebx
        addw %cx, %bx

    LispGovno, 10 Апреля 2013

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

    +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
    <?/**
        * Возвращаем все товары по фильтру
        * @author Алексей Чигинцев
        * Доработал и убрал участки еблизма: Арбора Сергей
    	* Почувствовал, что могу все улучшить, но все разъебал еще хуже чем было изначально: Влад Черноскутов
        * Ниче не знаю техничкой роблю: Алексей MOSkvin
        * имхо: Вадим стиль руки хуй
        * @param array $options - список используемых параметров
        * @return array|false - массив товаров либо false
        */
        function getGoodsFilter($options = array(),$_FILTER) {
          	$price_expr = '`price`';$_sub = $_out = array();$sql = $_sub_child = '';
            $cat = new Catalog(self::$db);
            $cat->load();
            $filter_query = self::parseFilterQuery($_FILTER);
            if ($options['SS'] && (!$options['first'] && !$options['second'] && !$options['last']))
            {//получаем всех детей
                $_sub_child = $cat->get_child(41);        
                if($options['id_man'][0]!=''){$whereand1 = $filter_query;}else{$whereand1 ="";}
                if($options['sort_type']){$order1 = ' ORDER BY `'.$options['sort_field'].'` '.$options['sort_type'];
                } else {$order1 =""; }
                if (!empty($_sub_child)){$i=0;
                	foreach ($_sub_child as $v){
    	                if($i<count($_sub_child)-1){$_sub_chil .= $v.','; $i++; }else{$_sub_chil .= $v; }}
    	                if($whereand1!=""){$_sub[] = self::$db->resultAsArray('SELECT * FROM `'.self::$table.'` WHERE `is_dollar`= "0" `cid` IN('.$_sub_chil .') '.$whereand1.$order1);
                    }else{$_sub[] = self::$db->resultAsArray('SELECT * FROM `'.self::$table.'` WHERE `is_dollar`= "0" cid` IN('.$_sub_chil .') AND name` LIKE "%'.mysql_real_escape_string($options['SS']).'%" '.$order1
                    	);}}
                if ($_sub){ foreach($_sub as $v){if (!empty($v)){ 
                    		foreach ($v as $v_child){ 
                                $_out[$v_child['id']] = $v_child; 
                    }}}}
                if (!empty($_out)) return $_out;
                    else return false;
            }elseif ($options['SS'] && ($options['first'] || $options['second'] || $options['last']))    
                { 	$whereand1 = "";
                    if($options['id_man'][0]){$whereand1 = $filter_query;}
                    if($options['sort_type']){
                    $order1 = ' ORDER BY `'.$options['sort_field'].'` '.$options['sort_type'];}else{$order1 ="";}    
                    $_where_price = false;
                    if ($options['last']){switch ($options['last']){
                        case 1: $_where_price .= ' '.$whereand1.'AND ((`is_dollar`=0 AND (`price` > 0 AND `price` <= 25000)) OR (`is_dollar`=1 AND (`price` > 0 AND `price` <= '.__dollar(25000).'))) '.$order1; break;
                        case 2: $_where_price .= ' '.$whereand1.'AND ((`is_dollar`=0 AND (`price` > 25000 AND `price` <= 50000)) OR (`is_dollar`=1 AND (`price` > '.__dollar(25000).' AND `price` <= '.__dollar(50000).'))) '.$order1; break;
                        case 3: $_where_price .= ' '.$whereand1.'AND ((`is_dollar`=0 AND `price` > 50000) OR (`is_dollar`=1 AND (`price` > '.__dollar(50000).')))'.$order1; break;
                        default: $where_price = false; break;
                    }}$_sub_child = $cat->get_child($options['first']);
                        if (!$_sub_child){$_out = self::$db->resultAsArray('SELECT * FROM `'.self::$table.'` WHERE 
    	                                    `name` LIKE "%'.mysql_real_escape_string($options['SS']).'%" 
    	                                    AND `is_dollar`= "0" AND  `cid`='.intval($options['first']).' 
    	                                ' . ($options['second'] ? ' AND `id_man`='.intval($options['second']).' ' : '') . '
    	                                ' . ($_where_price ? $_where_price : '') . ''.$whereand1.$order1);
                            if (!empty($_out)) return $_out;else return false;
                        }else{foreach ($_sub_child as $v){
                                    $_sub[] = self::$db->resultAsArray('SELECT * FROM `'.self::$table.'` WHERE 
                                        `name` LIKE "%'.mysql_real_escape_string($options['SS']).'%" 
                                        AND `is_dollar`= "0"  AND  `cid`='.intval($v).' 
                                    ' . ($options['second'] ? ' AND `id_man`='.intval($options['second']).' ' : '') . '
                                    ' . ($_where_price ? $_where_price : '') . '');
                                }if ($_sub){foreach ($_sub as $v){if (!empty($v)){
                                            foreach ($v as $v_child){   
                                            	$_out[$v_child['id']] = $v_child; 
                                        	}}}}
                                if (!empty($_out)) return $_out;else return false;
                    }}elseif (!$options['SS'] && ($options['first'] || $options['second'] || $options['last'])){
                            $_where_price = false;$whereand1 = "";
                            if($options['id_man'][0]){$whereand1 = $filter_query;}
                            if($options['sort_type']){$order1 = ' ORDER BY CAST(`' .$options['sort_field'].'` AS SIGNED) '.$options['sort_type'];}else{$order1 ="";}        
    						if ($options['last']){switch ($options['last']){
                                    case 1: $_where_price .= ' '.$whereand1.'AND (`is_dollar`=1 AND (`price` > 0 AND `price` <= '.__dollar(25000).')) '; break;
    								case 2: $_where_price .= ' '.$whereand1.'AND (`is_dollar`=1 AND (`price` > '.__dollar(25000).' AND `price` <= '.__dollar(50000).')) '; break;
    								case 3: $_where_price .= ' '.$whereand1.'AND (`is_dollar`=1 AND (`price` > '.__dollar(50000).'))'; break;
                                    default: $where_price = false; break;
                            }}
                            //получаем детей для $options['first'] - если дети есть ищем по их массиву
                            $_sub_child = $cat->get_child($options['first']);
                        }else return false;}

    Работаю в веб-студии, расклад такой:
    1) Чувак-извращенец как-то поднял сайт с фильтром по каталогу, уволился.
    2) Пришел второй чувак, ему поручили фикс этого творения - сломал все что работало.
    3) Пришел я, починил все необычными костылями, вроде как работало
    4) Пришел еще один чувак, доработал до мульти выбора в фильтре)) - все слетело, поставил мега крутые костыли, они и представлены
    5) Пришел очередной чувак и порешал все, терь работает, но все костыли живут и будут жить))))))

    arbora, 10 Апреля 2013

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