- 1
- 2
"WCT" или "ебанутым нет покоя" - уже на главной Швабра!
http://habrahabr.ru/post/271519/
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
"WCT" или "ебанутым нет покоя" - уже на главной Швабра!
http://habrahabr.ru/post/271519/
+1
class CBaseEntity {
// ...
void (CBaseEntity ::*m_pfnThink)(void);
virtual void Think( void ) { if (m_pfnThink) (this->*m_pfnThink)(); };
// ...
// Ugly code to lookup all functions to make sure they are exported when set.
#ifdef _DEBUG
void FunctionCheck( void *pFunction, char *name )
{
if (pFunction && !NAME_FOR_FUNCTION((uint32)pFunction) )
ALERT( at_error, "No EXPORT: %s:%s (%08lx)\n", STRING(pev->classname), name, (uint32)pFunction );
}
BASEPTR ThinkSet( BASEPTR func, char *name )
{
m_pfnThink = func;
FunctionCheck( (void *)*((int *)((char *)this + ( offsetof(CBaseEntity,m_pfnThink)))), name );
return func;
}
// ...
};
// Ugly technique to override base member functions
// Normally it's illegal to cast a pointer to a member function of a derived class to a pointer to a
// member function of a base class. static_cast is a sleezy way around that problem.
#ifdef _DEBUG
#define SetThink( a ) ThinkSet( static_cast <void (CBaseEntity::*)(void)> (a), #a )
// ...
#else
#define SetThink( a ) m_pfnThink = static_cast <void (CBaseEntity::*)(void)> (a)
// ...
#endif
https://github.com/ValveSoftware/halflife/blob/5d761709a31ce1e71488f2668321de05f791b405/dlls/cbase.h
> it's illegal
В крестах всё легально, главное - попросить прощения в комментах...
−114
def days(index)
((15662003>>(2*(index-1)))&3) + 28
end
Вычисление количества дней в месяце по индексу.
+159
mov eax, "allahu akbar"
push eax
Короче слушай сюда, петушок, я буду объяснять тебе доступными словами, что бы ты понял.
Вот попадаешь ты на зону, тебя встречает DHCP, он говорит тебе какая у тебя камера(Маска подсети), койка(ip адрес) и разъясняет порядок на хате(параметры области). Как только тебя определяют, то об этом узнает местная крыса(DNS), этот ушлый чухан вообще всё обо всех знает и сливает инфу по первому стуку в ебало(nslookup). Поэтому как только попадаешь в хату, представься что ты мужик(nsname), однако этот хуй может всем пиздеть что ты хуйло, или вообще идти в несознанку, поэтому лучше знать несколько крыс. Так вот, сидишь ты такой на своей койке и тебе нужно написать маляву(пакет) корешу, малявы передают через чуханов(маршрутизаторы, концентраторы, коммутаторы). Если ты передашь через чухана-концентратора, то знай, этот олень настолько тупой, что тут же забывает кто ему передал маляву и кому ее надо отдать, поэтому что бы не получить пизды, раздает ее всем, даже тебе. Если ты передаешь через чухана-коммутатора, то знай, он куда смышленей и передаст маляву куда надо, но только в пределах своей хаты, ибо связей не имеет. А вот маршрутизатора уже чуханом назвать сложно, этот тип может доставить маляву куда угодно, даже в соседнюю хату и даже в соседнюю зону, ибо связи решают.
+133
if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("");
else if (textBox[0].Text != "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%'", textBox[0].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%'", textBox[1].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%'", textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0}", textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("group={0}", textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%'", textBox[0].Text, textBox[1].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%'", textBox[1].Text, textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1}", textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0} and group={1}", textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%'", textBox[0].Text, textBox[1].Text, textBox[2].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2}", textBox[1].Text, textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1} and group={2}", textBox[2].Text, textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text);
else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2} and group={3}", textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3} and group={4}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
"Есть 5 текстовых полей и желание понять, как можно в зависимости от пустоты или заполненности этих полей, одного или нескольких создать малое количество операторов if else"
Порадовало "малое количество"
+159
/**
* @package mod_jlcurrency
* @author Zhukov Artem ([email protected])
* @version 1.1
* @copyright (C) 2012 by JoomLine (http://www.joomline.net)
* @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
*
*/
// No direct access
defined('_JEXEC') or die('Restricted access');
$vl = array();
$vl[$params->get('JPY')]=$params->get('JPY');$vl[$params->get('ZAR')]=$params->get('ZAR');
$vl[$params->get('KRW')]=$params->get('KRW');$vl[$params->get('CHF')]=$params->get('CHF');
$vl[$params->get('SEK')]=$params->get('SEK');$vl[$params->get('CZK')]=$params->get('CZK');
$vl[$params->get('UAH')]=$params->get('UAH');$vl[$params->get('UZS')]=$params->get('UZS');
$vl[$params->get('TRY')]=$params->get('TRY');$vl[$params->get('TMT')]=$params->get('TMT');
$vl[$params->get('TJS')]=$params->get('TJS');$vl[$params->get('SGD')]=$params->get('SGD');
$vl[$params->get('XDR')]=$params->get('XDR');$vl[$params->get('RON')]=$params->get('RON');
$vl[$params->get('PLN')]=$params->get('PLN');$vl[$params->get('NOK')]=$params->get('NOK');
$vl[$params->get('MDL')]=$params->get('MDL');$vl[$params->get('LTL')]=$params->get('LTL');
$vl[$params->get('LVL')]=$params->get('LVL');$vl[$params->get('CNY')]=$params->get('CNY');
$vl[$params->get('KGS')]=$params->get('KGS');$vl[$params->get('CAD')]=$params->get('CAD');
$vl[$params->get('KZT')]=$params->get('KZT');$vl[$params->get('INR')]=$params->get('INR');
$vl[$params->get('EUR')]=$params->get('EUR');$vl[$params->get('USD')]=$params->get('USD');
$vl[$params->get('DKK')]=$params->get('DKK');$vl[$params->get('HUF')]=$params->get('HUF');
$vl[$params->get('BRL')]=$params->get('BRL');$vl[$params->get('BGN')]=$params->get('BGN');
$vl[$params->get('BYR')]=$params->get('BYR');$vl[$params->get('AMD')]=$params->get('AMD');
$vl[$params->get('GBP')]=$params->get('GBP');$vl[$params->get('AZN')]=$params->get('AZN');
$vl[$params->get('AUD')]=$params->get('AUD');
Эмм. Это так и должно быть?
+54
// We now have a locale string, but the global locale can be changed by
// another thread. If we allow this thread's locale to be updated before we're done
// with this string, it might be freed from under us.
// Call versions of the wide-to-MB-char conversions that do not update the current thread's
// locale.
//...
/*
* Note that we are using a risky trick here. We are adding this
* locale to an existing threadlocinfo struct, and thus starting
* the locale's refcount with the same value as the whole struct.
* That means all code which modifies both threadlocinfo::refcount
* and threadlocinfo::lc_category[]::refcount in structs that are
* potentially shared across threads must make those modifications
* under _SETLOCALE_LOCK. Otherwise, there's a race condition
* for some other thread modifying threadlocinfo::refcount after
* we load it but before we store it to refcount.
*/
MS VS 2013 CRT
+57
class C3D
{
public:
//C3D() {} // Constructor
//~C3D() {} // Destructor
void(*init)(float R, float A, float B, float Rmin, float Rmax, float Bmin, float Bmax); // Initialize work with 3D standard camera
void(*setCamera)(int iType); // Set type of camera
void(*setPosition)(float x, float y, float z); // Set position
void(*setRender3D)();
UINT(*addMesh)(LPCWSTR sMesh); // Add Mesh
void(*renderMesh)(UINT idMesh, float x, float y, float z);
void(*renderMeshSubset)(UINT idMesh, UINT idSubset, float x, float y, float z);
void(*renderMeshSubsetRotateX)(UINT idMesh, UINT idSubset, float x, float y, float z, float a);
// простыня указателей на функции урезана
void setHModule(HMODULE hLib)
{
m_hLib = hLib;
(FARPROC &)init = GetProcAddress(m_hLib, "init3D"); // Initialize work with 3D standard camera
(FARPROC &)setCamera = GetProcAddress(m_hLib, "setCamera"); // Set type of camera
(FARPROC &)setPosition = GetProcAddress(m_hLib, "setPosition"); // Set position
(FARPROC &)setRender3D = GetProcAddress(m_hLib, "setRender3D");
(FARPROC &)addMesh = GetProcAddress(m_hLib, "addMesh"); // Add Mesh
(FARPROC &)renderMesh = GetProcAddress(m_hLib, "renderMesh");
(FARPROC &)renderMeshSubset = GetProcAddress(m_hLib, "renderMeshSubset");
(FARPROC &)renderMeshSubsetRotateX = GetProcAddress(m_hLib, "renderMeshSubsetRotateX");
// простыня GetProcAddress урезана
}
protected:
HMODULE m_hLib; // NetWars.dll
};
Некий SDK для MMO-игр за авторством одного известного разработчика.
+161
//! Массив типов пользователей
$UserTypes = array();
$result = $db->Query("SELECT 'Физ.лицо' AS type_user_rus, 'human' AS type_user FROM DUAL
UNION ALL
SELECT 'Юр.лицо' AS type_user_rus, 'firm' AS type_user FROM DUAL");
if( $db->isError( $result ) ){
die( $result->getMessage() . " at line " . __LINE__ . " in file " . __FILE__ );
}
while( $row = $result->fetchRow( DB_FETCHMODE_ASSOC ) )
{
$UserTypes[$row['TYPE_USER']] = $row['TYPE_USER_RUS'];
}
Формирование массива с типами клиентов
+156
if (count($vCard) == 1) {
print_r($vCard -> n);
print_r($vCard -> tel);
} else {
foreach ($vCard as $vCardPart)
{
print_r($vCardPart -> n);
print_r($vCardPart -> tel);
}
}
https://github.com/nuovo/vCard-parser
Ну за каким хуем обрабатывать один элемент как отдельный случай?!