1. Лучший говнокод

    В номинации:
    За время:
  2. Куча / Говнокод #19080

    −1

    1. 1
    2. 2
    "WCT" или "ебанутым нет покоя" - уже на главной Швабра!
    http://habrahabr.ru/post/271519/

    gost, 24 Ноября 2015

    Комментарии (50)
  3. C++ / Говнокод #18975

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    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
    В крестах всё легально, главное - попросить прощения в комментах...

    bormand, 05 Ноября 2015

    Комментарии (50)
  4. Ruby / Говнокод #18439

    −114

    1. 1
    2. 2
    3. 3
    def days(index)
      ((15662003>>(2*(index-1)))&3) + 28
    end

    Вычисление количества дней в месяце по индексу.

    yuryroot, 06 Июля 2015

    Комментарии (50)
  5. Assembler / Говнокод #18259

    +159

    1. 1
    2. 2
    mov eax, "allahu akbar"
    push eax

    Короче слушай сюда, петушок, я буду объяснять тебе доступными словами, что бы ты понял.
    Вот попадаешь ты на зону, тебя встречает DHCP, он говорит тебе какая у тебя камера(Маска подсети), койка(ip адрес) и разъясняет порядок на хате(параметры области). Как только тебя определяют, то об этом узнает местная крыса(DNS), этот ушлый чухан вообще всё обо всех знает и сливает инфу по первому стуку в ебало(nslookup). Поэтому как только попадаешь в хату, представься что ты мужик(nsname), однако этот хуй может всем пиздеть что ты хуйло, или вообще идти в несознанку, поэтому лучше знать несколько крыс. Так вот, сидишь ты такой на своей койке и тебе нужно написать маляву(пакет) корешу, малявы передают через чуханов(маршрутизаторы, концентраторы, коммутаторы). Если ты передашь через чухана-концентратора, то знай, этот олень настолько тупой, что тут же забывает кто ему передал маляву и кому ее надо отдать, поэтому что бы не получить пизды, раздает ее всем, даже тебе. Если ты передаешь через чухана-коммутатора, то знай, он куда смышленей и передаст маляву куда надо, но только в пределах своей хаты, ибо связей не имеет. А вот маршрутизатора уже чуханом назвать сложно, этот тип может доставить маляву куда угодно, даже в соседнюю хату и даже в соседнюю зону, ибо связи решают.

    DesmondHume, 30 Мая 2015

    Комментарии (50)
  6. C# / Говнокод #17960

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    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"

    Порадовало "малое количество"

    Psilon, 08 Апреля 2015

    Комментарии (50)
  7. PHP / Говнокод #17824

    +159

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    /**
     * @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');

    Эмм. Это так и должно быть?

    Rijen, 20 Марта 2015

    Комментарии (50)
  8. C++ / Говнокод #17505

    +54

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    // 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

    LispGovno, 23 Января 2015

    Комментарии (50)
  9. C++ / Говнокод #16769

    +57

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    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-игр за авторством одного известного разработчика.

    bazhenovc, 25 Сентября 2014

    Комментарии (50)
  10. PHP / Говнокод #16256

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    //! Массив типов пользователей
    $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'];
    }

    Формирование массива с типами клиентов

    psrustik, 30 Июня 2014

    Комментарии (50)
  11. PHP / Говнокод #16208

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    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

    Ну за каким хуем обрабатывать один элемент как отдельный случай?!

    bormand, 23 Июня 2014

    Комментарии (50)