- 1
- 2
- 3
- 4
- 5
$query = $sql -> query("SELECT *, COUNT(`id`) as count FROM `d_download` WHERE `id` = '{$id}'", true);
if($query['count'] == 1) {
// code
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−163
$query = $sql -> query("SELECT *, COUNT(`id`) as count FROM `d_download` WHERE `id` = '{$id}'", true);
if($query['count'] == 1) {
// code
}
Проверка, что значение найдено.
−102
@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"?
Не, не слышал.
−97
@render_to_json()
def view(request):
# ...
return {'name':obj.name for obj in
Company.objects.filter(id=cid, is_valid=True)}
Не, ну а чё? )
−113
if ([_categories count] != 0) {
for (NSString *item in _categories) {
[path appendFormat:@"categories/%@/", item];
}
}
Случайно обнаружил у себя :)
+150
$Not = array('\\',",","/","¬","#",";",":","~","[","]","{","}",")","(","*","^","%","$","<",">","?","!",'"',"'","|");
...
function check($string){
$string = preg_replace("/[^a-zA-Z a-яА-яёЁ]/i", "",$string);
$string = str_replace($Not,'',$string);
$string = htmlspecialchars($string);
return $string;
}
Нашёл у себя убойный фильтр. Работает как зверь :-)
−113
+ (BOOL) isInteger:(CGFloat) number
{
return number - (int) number<0.0001;
}
В классе используется только ради того, чтобы при передаче нецелого флоата вывести километровый NSLog, в котором долго жаловаться на жизнь и полпикселя.
+123
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
+147
<?/**
* Возвращаем все товары по фильтру
* @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) Пришел очередной чувак и порешал все, терь работает, но все костыли живут и будут жить))))))
+13
std::string StringUtilities::replace(const std::string& strValue,
uint8_t piWhat,
uint8_t piWith)
{
size_t len = strValue.length();
uint8_t* lTemp = new uint8_t[len + 1];
memset(lTemp, '\0', len + 1); //+ 1 for \0
memcpy(lTemp, strValue.c_str(), len);
for (size_t i = 0; i < len; i++)
{
if (lTemp[i] == piWhat)
lTemp[i] = piWith;
}
return string( (int8_t*) lTemp );
}
Любители велосипедов...
+132
</head>
<script type="text/javascript">
$(document).ready(function() {
...
});
</script>
<body>
Не до, и не после - между блять!