- 1
$years = range(date('Y', $now), date('Y', strtotime('+ 1 year', $now)));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+149
$years = range(date('Y', $now), date('Y', strtotime('+ 1 year', $now)));
Пятница в моей голове... А надо было всеголтшь действующий и следующий
+147
<cbimport_import_check_checkimport>
надо вдуматся что бы понять
нода из конфигурации модуля под маженто
+156
// Если больше 23:30, то сверяем мультиреестровые
if (mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')) >= mktime(23, 30, 0, date('m'), date('d'), date('Y')) || $notime == 1)
$sql .= ' AND pi.multiregistry = "1"';
else
$sql .= ' AND pi.multiregistry = "0"';
Колдуем даты
+127
//top edge
if (normal)
for (int i = y; i > 0; i--)
if (_map[x, i] == 0)
if ((i - 1) > minDist) { mnt.Corners[0] = new Point(x, i - 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
//top-right edge
if (normal)
for (int i = 0; ((x + i) < MAP_SIZE) & ((y - i) > 0); i++)
if (_map[x + i, y - i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[1] = new Point(x + i - 1 - minDist, y - i + 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
//right edge
if (normal)
for (int i = x; i < MAP_SIZE; i++)
if (_map[i, y] == 0)
if ((MAP_SIZE - i - 1) > minDist) { mnt.Corners[2] = new Point(i - 1 - minDist, y); break; }
else { normal = false; mnt.Height = -1; }
//bottom-right edge
if (normal)
for (int i = 0; ((x + i) < MAP_SIZE) & ((y + i) < MAP_SIZE); i++)
if (_map[x + i, y + i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[3] = new Point(x + i - 1 - minDist, y + i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//bottom edge
if (normal)
for (int i = y; i > 0; i++)
if (_map[x, i] == 0)
if ((i - 1) > minDist) { mnt.Corners[4] = new Point(x, i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//bottom-left edge
if (normal)
for (int i = 0; ((x - i) < MAP_SIZE) & ((y + i) > 0); i++)
if (_map[x - i, y + i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[5] = new Point(x - i + 1 + minDist, y + i - 1 - minDist); break; }
else { normal = false; mnt.Height = -1; }
//left edge
if (normal)
for (int i = x; i > 0; i--)
if (_map[i, y] == 0)
if ((i + 1) > minDist) { mnt.Corners[6] = new Point(i + 1 + minDist, y); break; }
else { normal = false; mnt.Height = -1; }
//top-left edge
if (normal)
for (int i = 0; ((x - i) > 0) & ((y - i) > 0); i++)
if (_map[x - i, y - i] == 0)
if (Math.Sqrt(2) * (MAP_SIZE - i) > minDist) { mnt.Corners[7] = new Point(x - i + 1 + minDist, y - i + 1 + minDist); break; }
else { normal = false; mnt.Height = -1; }
Мне было лень думать. Очень лень.
+102
if (
!(this.Department.Length == 4 &&
"0123456789".Contains(this.Department[0]) &&
"0123456789".Contains(this.Department[1]) &&
"0123456789".Contains(this.Department[2]) &&
"0123456789".Contains(this.Department[3])) &&
!(this.Department.Length == 4 &&
"0123456789".Contains(this.Department[0]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])) &&
!(this.Department.Length == 5 &&
"0123456789".Contains(this.Department[0]) &&
"0123456789".Contains(this.Department[4]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[1]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[2]) &&
"ABCDEFGHIJKLMNOPQRSTUVWXYZ".Contains(this.Department[3])))
{
return "error";
}
Он видимо не знал о существовании регулярных выражений
+8
....
#define MAX_PROC_LIST 1024
enum PROCCESS_TYPE
{
OFFRO,
GFEER,
OLLYD,
FLOOT,
SFOIT,
};
typedef struct
{
PROCCESS_TYPE tType;
unsigned short uPid;
bool bIA32;
}ACTIVE_PROCCESS_INFO, *PACTIVE_PROCCESS_INFO;
....
bool MONITOR_PROCCESS_ENGINE::GetActiveProccessInfo(PACTIVE_PROCCESS_INFO pActiveInfoProccess, const unsigned int nIndex)
{
if(nIndex < 0) return false;
PROCESSENTRY32 pe32;
HANDLE hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
bool bFound = false;
pe32.dwSize = sizeof( PROCESSENTRY32 );
if(!Process32First( hProcessSnap, &pe32 )) return false;
char szNameImage[MAX_PATH];
ZeroMemory(szNameImage, MAX_PATH);
do
{
if(pe32.th32ProcessID == aProccessList[nIndex])
{
bFound = true;
wcstombs(szNameImage, (const wchar_t *)pe32.szExeFile, wcslen(pe32.szExeFile));
break;
}
} while( Process32Next( hProcessSnap, &pe32 ));
CloseHandle(hProcessSnap);
if(bFound && strlen(szNameImage))
{
if(!strcmp(szNameImage, szActiveList32[0]))
pActiveInfoProccess->tType = OFFRO;
else
if(!strcmp(szNameImage, szActiveList32[1]))
pActiveInfoProccess->tType = GFEER;
else
if(!strcmp(szNameImage, szActiveList32[2]))
pActiveInfoProccess->tType = OLLYD;
else
if(!strcmp(szNameImage, szActiveList32[3]))
pActiveInfoProccess->tType = FLOOT;
else
if(!strcmp(szNameImage, szActiveList32[4]))
pActiveInfoProccess->tType = SFOIT;
else return false;
pActiveInfoProccess->uPid = (unsigned short) aProccessList[nIndex];
pActiveInfoProccess->bIA32 = true; // Fixme x64?
}
else return false;
return true;
}
Cи в стиле C++
+151
if (Scene.generatedFast || (typeof generatedFast != "undefined" && generatedFast) )
+146
getInsideText($part1[0],'<string>','</string>',1,true);
function getInsideText($str,$fstr,$lstr,$limit=0,$trim=true){
$temp_arr=array();
$lcnt=0;
while(strpos($str,$fstr)!==false && ($limit ? $lcnt<$limit : true)){
$fpos=($fstr ? strpos($str,$fstr)+strlen($fstr) : 0);
$str=substr($str,$fpos);
$lpos=strpos($str,$lstr);
$val=($lpos!==false ? substr($str,0,$lpos) : $str);
$temp_arr[]=($trim ? trim($val) : $val);
$str=substr($str,$lpos+strlen($lstr));
$lcnt++;
}
return ($limit==1 ? (isset($temp_arr[0]) ? $temp_arr[0] : '') : $temp_arr);
}
Конечный автомат своими силами.
+16
class Context;
class AbstractState
{
Context * m_context;
protected:
Context * context() const { return m_context; }
public:
AbstractState(Context * context) : m_context(context) { };
virtual ~AbstractState() { }
virtual void doSomething() = 0;
};
class Context
{
std::unique_ptr<AbstractState> m_state;
public:
enum State
{
State1,
State2,
};
Context() { switchToState(State1); }
void switchToState(State newState);
void doSomething() { m_state->doSomething(); }
void someCleanup() { }
};
class ConcreteState1 : public AbstractState
{
public:
ConcreteState1(Context * context) : AbstractState(context) { }
virtual void doSomething()
{
context()->switchToState(Context::State2);
context()->someCleanup();
}
};
class ConcreteState2 : public AbstractState
{
public:
ConcreteState2(Context * context) : AbstractState(context) { }
virtual void doSomething()
{
context()->switchToState(Context::State1);
context()->someCleanup();
}
};
void Context::switchToState(State newState)
{
switch(newState)
{
case State1:
m_state.reset(new ConcreteState1(this));
return;
case State2:
m_state.reset(new ConcreteState2(this));
return;
}
}
Бывает, на меня находит состояние "сначала делай, потом думай", благо результат был быстро обнаружен отладчиком.
−169
DECLARE @IsPerson BIT
,@ContactTypeID INT
SET @ContactTypeID = CASE WHEN @IsPerson = 0 THEN 3 ELSE 4 END
IF (LEN(ISNULL(@FirstName,'')) <= 0 AND LEN(ISNULL(@LastName,'')) <= 0 AND (LEN(@EntityName) > 0 OR LEN(@TradingAs) > 0))
BEGIN
SET @IsPerson = 0
END
ELSE
BEGIN
SET @IsPerson = 1
END
Такая себе Stored Procedure...
Magic numbers - это всё фигня. Меня всегда интересовало, почему тип контакта всегда 4?
И, да, строки идут именно в такой очерёдности.