- 1
if(!empty($filter['features']) && !empty($filter['features'])) ...
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+50
if(!empty($filter['features']) && !empty($filter['features'])) ...
Simpla CMS /api/Products.php
−167
SELECT
slave.*,
-- ...
FROM
(SELECT * FROM driver WHERE id = '$driverID') as slave
LEFT JOIN
-- ...
Отыскал в работающем проекте
+21
angle_in_radians = acos(dot(normalize(o-a), normalize(o-b)));
Векторы такие сложные, а операции с ними так трудно запомнить, что даже игроделы не могут это сделать.
−90
- (void)movementScreenUp
{
int shift;
switch (_numberCell) {
case 3:
if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
shift = startPosition.y;
break;
}
if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
shift = - 50;
break;
}
if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
shift = - 90;
break;
}
case 4:
if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
shift = startPosition.y;
break;
}
if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
shift = - 25;
break;
}
if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
shift = - 90;
break;
}
if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
shift = - 90;
break;
}
case 5:
if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
shift = startPosition.y;
break;
}
if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
shift = - 1;
break;
}
if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
shift = - 40;
break;
}
if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
shift = - 86;
break;
}
if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
shift = - 86;
break;
}
case 6:
if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
shift = startPosition.y;
break;
}
if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
shift = startPosition.y;
break;
}
if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
shift = - 2;
break;
}
if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
shift = - 52;
break;
}
if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
shift = - 105;
break;
}
if (clickButtonGameCells.tag == 6 || clickButtonGameCells.tag == 60) {
shift = - 105;
break;
}
default:
break;
}
[UIView animateWithDuration:0.25 animations:^{
CGRect view_frame = self.frame;
view_frame.origin = CGPointMake(self.frame.origin.x, shift);
self.frame = view_frame;
}];
}
Магия цифр
−109
- (void)countDown
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = ([currentDate timeIntervalSinceDate:startDate]);
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
if ([timeString isEqualToString:@"02"])
{
[logoTimer invalidate];
logoTimer = nil;
// some other code
}
}
- (void)updateCounter
{
startDate = [NSDate dateWithTimeIntervalSinceNow:00];
logoTimer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:@selector(countDown)
userInfo:nil
repeats:YES];
}
Вот так незатейливо можно поставить задержку на 2 секунды
−120
private function uncaughtError (e:UncaughtErrorEvent):void {
// be a good girl and swallow
e.stopImmediatePropagation ();
}
написал какую-то хуету и сижу, радуюсь как маленький. да, я хочу поговорить об этом.
+8
#include <iostream>
struct Reader_msg;
template<class T>struct TMsg;
struct IMsg
{
virtual ~IMsg(){}
virtual void SendCast(Reader_msg& obj) = 0;
};
struct Some{};
struct Reader_msg
{
template<class T> void ReadMsg(T& msg)
{
//Здесь можно приляпать статик_ассерт
std::cout<<"ERROR UNKNOW TYPE \n";
}
void ReadMsg(int msg) { (void)msg; std::cout<<"TYPE IS INT\n"; }
void ReadMsg(float msg) { (void)msg; std::cout<<"TYPE IS FLOAT\n"; }
void ReadMsg(Some msg) { (void)msg; std::cout<<"TYPE IS SOME\n"; }
template<class T>void TakeMsg(T& msg) { msg.SendCast(*this); }
};
template<class T>struct TMsg:IMsg
{
T data;
void SendCast(Reader_msg& obj){ obj.ReadMsg(data); }
};
int main()
{
Reader_msg reader;
TMsg<int> msg1;
TMsg<float> msg2;
IMsg& msg3 = msg1;
IMsg& msg4 = msg2;
TMsg<Some> msg5;
TMsg<double> msg6;
reader.TakeMsg(msg1);
reader.TakeMsg(msg2);
reader.TakeMsg(msg3);
reader.TakeMsg(msg4);
reader.TakeMsg(msg5);
reader.TakeMsg(msg6);
}
http://liveworkspace.org/code/4FHDTq$6
+47
function executeNewsRightRelated(sfWebRequest $request)
{
$siteId = $request->getParameter('site')->id;
$tNewsList = $this->object->News;
$newsList = array();
foreach ($tNewsList as $news) {
$ids = array();
foreach ($news->Sites as $idModel) {
$ids[] = $idModel->id;
}
if (in_array($siteId, $ids)) {
$newsList[] = $news;
}
}
$this->newsList = $newsList;
}
+110
int strnlen(const char *s, int size)
{
int i;
for(i=0; i<size; i++) if(!*s) break;
return i;
}
+139
List<string> duplicities = new List<string>();
foreach (var localItem in FileCollectionLocal)
{
foreach (var remoteItem in FileCollectionRemote)
{
if (localItem.FileName == remoteItem.FileName)
{
duplicities.Add(localItem.FileName);
}
}
}