- 1
foos.removeAll(Collections.singleton(null));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+69
foos.removeAll(Collections.singleton(null));
foos.remove(null)?не, не наш метод.
+109
static void Main()
{
int i = 0;
Console.WriteLine(String.Format("{0} {1} {2}", i, i, i));
}
Я долго не видел там немного гoвна, но оказалось оно там есть
−120
- (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
{
if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
{
return nil;
};
NSFetchRequest *fr=[[NSFetchRequest alloc] init];
[fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
[fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
[fr setIncludesPropertyValues:YES];
NSError *err;
NSArray *res=[context executeFetchRequest:fr error:&err];
if (err!=nil)
{
NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
return nil;
}
else
{
if ([res count]<=0)
{
NSLog(@"[res count]<=0");
//NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
return nil;
}
else if([res count]>1)
{
NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
return nil;
}
else //[res count] == 1
{
return [res objectAtIndex:0];
};
};
}
Фетч
+148
$type = isset($config['type']) ? $config['type'] : 'default';
switch($type) {
default:
$blockClass = 'adminhtml/widget_grid_massaction_item_additional_default';
break;
}
Magento core
+130
Прокси-граббер
http://rghost.ru/47337858
Товарищи, попробуйте мой новый прокси-граббер! Это только эскиз, так что прошу строго не судить. Однопоточный. Парсит с 2 сайтов.
−102
a=[1,2,3,1,2,1,4]
for i in a:
if i is 1:
zzz=222
else:
print zzz
http://ideone.com/nhqqRU
Сегодня весь день чинил странный баг, смысл которого сводится вот к такой синтетки.
Притом если условие не выполниться на первой итерации http://ideone.com/G3Uf7V , то будет эксепшен.
+159
<?php if( (!isset($post_id) ) || ( isset($post_id)) ) { ?>
Одна платная Wordpress тема
−172
sub company_stuff_add_array_elems
{
my $list = shift;
my $count = 0;
foreach ( @$list )
{
$count += $_;
}
return $count;
}
List::Util::sum
http://perldoc.perl.org/List/Util.html
−89
def set_path
if name && (!path || path == "/")
self.path = self.parent.present? ? "#{self.parent.path}/#{name}" : "/#{name}"
elsif !new_record? && name && path && name_was != name
parts = path.split("/")
parts.pop
self.path = [parts.join("/"), name].join("/")
elsif !new_record? && name && self.parent_id_changed?
self.path = self.parent.present? ? "#{self.parent.path}/#{name}" : "/#{name}"
elsif new_record? && name && path
self.path = [path, name].join("/")
end
if path && self.parent.blank?
parts = path.split("/")
self.name = parts.pop
parent_path = parts.join("/")
if parent_path.blank? || parent_path == "/"
self.parent = nil
else
possible_parent = site.asset_folders.find_by_path(parent_path)
self.parent = possible_parent.present? ? possible_parent : self.class.create(path: parent_path, site: site)
end
end
true
end
Как не нужно работать с путями в Rails-приложении. Это и еще примерно 500 строк было заменено на 11 строк кода, включая пустые.
+10
static int
_S_compare(size_type __n1, size_type __n2)
{
const difference_type __d = difference_type(__n1 - __n2);
if (__d > __gnu_cxx::__numeric_traits<int>::__max)
return __gnu_cxx::__numeric_traits<int>::__max;
else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
return __gnu_cxx::__numeric_traits<int>::__min;
else
return int(__d);
}