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

    В номинации:
    За время:
  2. C++ / Говнокод #19340

    0

    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
    #define EncryptAES256(sched) \
    		"pxor (%["#sched"]), %%xmm0 \n" \
    		"aesenc	16(%["#sched"]), %%xmm0 \n" \
    		"aesenc	32(%["#sched"]), %%xmm0 \n" \
    		"aesenc	48(%["#sched"]), %%xmm0 \n" \
    		"aesenc	64(%["#sched"]), %%xmm0 \n" \
    		"aesenc	80(%["#sched"]), %%xmm0 \n" \
    		"aesenc	96(%["#sched"]), %%xmm0 \n" \
    		"aesenc	112(%["#sched"]), %%xmm0 \n" \
    		"aesenc	128(%["#sched"]), %%xmm0 \n" \
    		"aesenc	144(%["#sched"]), %%xmm0 \n" \
    		"aesenc	160(%["#sched"]), %%xmm0 \n" \
    		"aesenc	176(%["#sched"]), %%xmm0 \n" \
    		"aesenc	192(%["#sched"]), %%xmm0 \n" \
    		"aesenc	208(%["#sched"]), %%xmm0 \n" \
    		"aesenclast	224(%["#sched"]), %%xmm0 \n"
    		
    	void ECBEncryptionAESNI::Encrypt (const ChipherBlock * in, ChipherBlock * out)
    	{
    		__asm__
    		(
    			"movups	(%[in]), %%xmm0 \n"
    			EncryptAES256(sched)
    			"movups	%%xmm0, (%[out]) \n"	
    			: : [sched]"r"(GetKeySchedule ()), [in]"r"(in), [out]"r"(out) : "%xmm0", "memory"
    		);
    	}

    https://github.com/PurpleI2P/i2pd/blob/openssl/Crypto.cpp принципиально новый подход - определять дефайном какое-то макроговно, чтобы потом его использовать внутри асмовставок

    j123123, 22 Января 2016

    Комментарии (9)
  3. Си / Говнокод #19280

    −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
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    // Add a UPnP port
    bool Win32UPnPAddPort(UINT outside_port, UINT inside_port, bool udp, char *local_ip, wchar_t *description, bool remove_before_add)
    {
    	bool ret = false;
    	HRESULT hr;
    	IUPnPNAT *nat = NULL;
    	wchar_t ip_str[MAX_SIZE];
    	BSTR bstr_ip, bstr_description, bstr_protocol;
    	wchar_t *protocol_str = (udp ? L"UDP" : L"TCP");
    	// Validate arguments
    	if (outside_port == 0 || outside_port >= 65536 || inside_port == 0 || inside_port >= 65536 ||
    		IsEmptyStr(local_ip) || UniIsEmptyStr(description))
    	{
    		return false;
    	}
    
    	StrToUni(ip_str, sizeof(ip_str), local_ip);
    	bstr_ip = SysAllocString(ip_str);
    	bstr_description = SysAllocString(description);
    	bstr_protocol = SysAllocString(protocol_str);
    
    	hr = CoCreateInstance(CLSID_UPnPNAT, NULL, CLSCTX_INPROC_SERVER, IID_IUPnPNAT, (void **)&nat);
    
    	if (SUCCEEDED(hr))
    	{
    		if (nat != NULL)
    		{
    			IStaticPortMappingCollection *collection = NULL;
    			hr = nat->get_StaticPortMappingCollection(&collection);
    
    			if (SUCCEEDED(hr))
    			{
    				if (collection != NULL)
    				{
    					IStaticPortMapping *mapping = NULL;
    
    					if (remove_before_add)
    					{
    						hr = collection->Remove((long)outside_port, bstr_protocol);
    					}
    
    					hr = collection->Add((long)outside_port, bstr_protocol, (long)inside_port,
    						bstr_ip, VARIANT_TRUE, bstr_description, &mapping);
    
    					if (SUCCEEDED(hr))
    					{
    						ret = true;
    
    						if (mapping != NULL)
    						{
    							mapping->Release();
    						}
    					}
    
    					collection->Release();
    				}
    				else
    				{
    					WHERE;
    				}
    			}
    			else
    			{
    				WHERE;
    			}
    
    			nat->Release();
    		}
    		else
    		{
    			WHERE;
    		}
    	}
    	else
    	{
    		WHERE;
    	}
    
    	SysFreeString(bstr_ip);
    	SysFreeString(bstr_description);
    	SysFreeString(bstr_protocol);
    
    	return ret;
    }

    Отсюда https://github.com/SoftEtherVPN/SoftEtherVPN/blob/master/src/Cedar/Win32Com.cpp#L157
    Там еще много такого. https://github.com/SoftEtherVPN/SoftEtherVPN/blob/master/src/Cedar/Win32Com.cpp#L963 вот например тоже забавная хрень. Нашел эту штуку по ссылке с говнохабра http://habrahabr.ru/post/208782/

    j123123, 04 Января 2016

    Комментарии (9)
  4. JavaScript / Говнокод #19274

    +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
    componentDidMount() {
            this.clickListener = (e) => {
    
                var input = document.getElementById('searchInput');
                var filtersBar = document.getElementById('filters');
                var searchBar = document.getElementById('search');
                var clearButton = document.getElementById('suggestInputClearBtn');
                var isNav = e.target.className.indexOf('suggestNavBtn') >= 0;
    
                if(input == e.target || searchBar == e.target || filtersBar == e.target || clearButton == e.target || isNav || e.target.className.indexOf('tags-controller-wrapper') !== -1)
                    return;
    
                var classes = e.target.c†.split(' ');
    
                for(var cls of classes){
                    if(cls == 'autocompleteItem')
                    {
                        return;
                    }
                }
    
                if(this.props.isSuggestInputVisible)
                    this.props.onCloseAutosuggestion();
    
            };
            this.attachClickListener();
        }

    Я бы только за if без скобок прибил) Обратите внимание на 4 выборки по id которые можно было не делать каждый раз при клике, а если приглядеться то можно понять, что можно было совсем не выбирать ни разу, а если бы пионер знал что всплытие событие можно остановить то этот метод занял бы три строчки и на десерт обратите внимание как он перебирает значение className циклом - это при том что в этом проекте можно писать на es6 Это самый дебильный код который я видел в этом году

    inwebart, 29 Декабря 2015

    Комментарии (9)
  5. JavaScript / Говнокод #19272

    −3

    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
    class Point {
        x: number;
        y: number;
        constructor(x: number, y: number) {
            this.x = x;
            this.y = y;
        }
        getDist() { 
            return Math.sqrt(this.x * this.x + 
            this.y * this.y); 
        }
    }
    var p = new Point(3,4);
    var dist = p.getDst(); // <- пропущена буква i в названии метода getDist()
    alert("Hypotenuse is: " + dist);

    Неработающий пример кода на TypeScript прямо на главной странице официального сайта этого языка ( http://www.typescriptlang.org ). TypeScript, если что, разработка Microsoft. Надеюсь, винду они не пишут с такими же позорными ошибками

    syxov, 29 Декабря 2015

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

    −3

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    #include <iostream>
    #include <time.h>
    #include <windows.h>
    #include <thread>
    #include <conio.h>
    #include <locale.h>
    #include <string>
    #include <tchar.h>
    using namespace std;
    //functions
    void DrawUI();
    void setup();
    bool first_r;
    void ShowHelp();
    void Up();
    void Left();
    void Right();
    void Down();
    void ShowFoodMenu();
    //vars
    bool lock = false;
    bool play = false;
    //functions
    float Cal2Weight(float calEat);
    // game center
    int posx = 16; //yes, this is a center of room
    int posz = 5;
    
    static HANDLE _ConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);//console out
    //for game center
    BOOL SetCurrentPos(SHORT x, SHORT y)
    {
    	COORD pos = { x, y };
    	return SetConsoleCursorPosition(_ConsoleOut, pos);
    }
    //some class declarations
    //food
    class Food
    {
    public:
    	Food(float calority, string name);
    	~Food();
    	void SetCalority(float newCalority) { itsCalority = newCalority; };
    	void SetName(string newName) { itsName = newName; };
    	float GetCalority() const { return itsCalority; }
    	string GetName() const { return itsName; };
    private:
    	float calority;
    	float itsCalority;
    	float newCalority;
    	string name;
    	string newName;
    	string itsName;
    };
    //food constructor
    Food::Food(float calority, string name)
    {
    	float itsCalority = calority;
    	string itsName = name;
    }
    //food destructor
    Food::~Food() {}
    //cat
    class Cat
    {
    public:
    	Cat(int age, float weight, string name);
    	~Cat();
    	void SetWeight(float newWeight) { itsWeight = newWeight; };
    	void SetAge(int newAge) { itsAge = newAge; };
    	void SetName(string newName) { itsName = newName; };
    	int GetAge() const { return itsAge; };
    	float GetWeight() const { return itsWeight; };
    	void Eat(string foodname);
    	string GetName() const { return itsName; };
    
    private:
    	int itsAge;
    	float itsWeight;
    	int age;
    	float weight;
    	int newAge;
    	float newWeight;
    	string itsName;
    	string newName;
    	string name;
    	string foodname;
    };
    //cat destructor
    Cat::~Cat() {}
    //making cat
    Cat Cat1(1, 1, "Unnamed");
    //food declaration
    Food Fries(2350, "Fries");
    Food Chips(1540, "Chips");
    Food Potatoes(251, "Potatoes");
    Food Water(0, "Water");
    Food Meat(200, "Meat");
    Food CatFood(65, "Special Cat Food");
    //for eating, bad code because i don't need normal, it works

    Мой очень старый код мелкой игры. Куча бреда для винды.

    catnikita255, 29 Декабря 2015

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void CDiagram::readDomElement( const QDomElement & de )
    {
    // ...
            QString sstratum = de.attribute( "stratum", "1" );
            bool ok = false;
            int istratum = sstratum.toInt( &ok );
            setStratum( ok ? istratum : CTSWConfig::m_SyncStratum );
    // ...
    }

    Парсинг xml конфигов, код не мой, но надо переделывать.

    OlegUP, 18 Декабря 2015

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class widget {};
    class gadget {};
    class bobo {};
    
    int main()
    {
        widget w(gadget(), bobo()); //Прототип функции или переменная? хмм
    
        return 0;
    }

    хмм...

    CriDos, 07 Декабря 2015

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

    +9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (Label125->Color == clGreen)
    {
      CreateOrderApi();// создаем накладную
    }
    else 
    {
      MessageBox("Не удалось создать накладную", "Ошибка", MB_OK | MB_ICONERROR);
    }

    expresscourier, 15 Октября 2015

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

    −2

    1. 1
    <a href="download.php?file=%D0%BA%D0%B0%D0%BA%D0%BE%D0%B9-%D1%82%D0%BE-%D1%84%D0%B0%D0%B9%D0%BB">

    Что такого? Попробуйте сохранить 9000 файлов по таким ссылкам каким-нибудь там FlashGot.

    thepotato, 05 Октября 2015

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

    +4

    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
    48. 48
    private void button2_Click(object sender, EventArgs e)
            {
     
            int n1 = Convert.ToInt16(textBox1.Text);
            int n2 = Convert.ToInt16(textBox4.Text);
            int n3 = Convert.ToInt16(textBox7.Text);
            int n4 = Convert.ToInt16(textBox10.Text);
            int n5 = Convert.ToInt16(textBox13.Text);
            int n6 = Convert.ToInt16(textBox16.Text);
            int n7 = Convert.ToInt16(textBox19.Text);
            int n8 = Convert.ToInt16(textBox22.Text);
     
            int b1 = Convert.ToInt16(textBox2.Text);
            int b2 = Convert.ToInt16(textBox5.Text);
            int b3 = Convert.ToInt16(textBox8.Text);
            int b4 = Convert.ToInt16(textBox11.Text);
            int b5 = Convert.ToInt16(textBox14.Text);
            int b6 = Convert.ToInt16(textBox17.Text);
            int b7 = Convert.ToInt16(textBox20.Text);
            int b8 = Convert.ToInt16(textBox23.Text);
     
            int c1 = Convert.ToInt16(textBox3.Text);
            int c2 = Convert.ToInt16(textBox6.Text);
            int c3 = Convert.ToInt16(textBox9.Text);
            int c4 = Convert.ToInt16(textBox12.Text);
            int c5 = Convert.ToInt16(textBox15.Text);
            int c6 = Convert.ToInt16(textBox18.Text);
            int c7 = Convert.ToInt16(textBox21.Text);
            int c8 = Convert.ToInt16(textBox24.Text);
     
            int ii, S2, S1, ti, ip, iip, iis, dp, ds, n;
                /*Индекс инфляции ii=S2/S1,
                *Темп инфляции ti=ii-1
                *простых процентов iip=((1+n*ip)*ii-1)/n
                 * для сложных iis=(1+is)nii(1/n)-1
                 * Реальная доходность простые% dp=(n*iip+1-ii)/ii
                 * Реальная доходность сложные% ds=(1+iis)/ii(1/n)-1
                 * сумма всей корзины S1 и S2
                 */
            S1 = n1 * b1 + n2 * b2 + n3 * b3 + n4 * b4 + n5 * b5 + n6 * b6 + n7 * b7 + n8 * b8;// сумма S1
            S2 = n1 * c1 + n2 * c2 + n3 * c3 + n4 * c4 + n5 * c5 + n6 * c6 + n7 * c7 + n8 * c8;// сумма S2
     
            ii = S2 / S1; // индекс инфляции
     
            ti = ii - 1; // темп инфляции
                
                n= n1+n2+n3+n4+n5+n6+n7+n8; // n= общее кол-во товаров и услуг
                iip = ((1 + n * ip) * ii - 1) / n;

    Diman3241, 28 Сентября 2015

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