1. C++ / Говнокод #19059

    +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
    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
    template<size_t n>
    struct counterNumber {
        char data[n+1];
    };
     
    template<size_t index, size_t val>
    counterNumber<val> magic(counterNumber<index>, counterNumber<val>);
     
    #define COUNTER_READ() \
        (sizeof( \
            magic(counterNumber<1>(), \
            	magic(counterNumber<2>(), \
            		magic(counterNumber<4>(), \
            			magic(counterNumber<8>(), \
            				magic(counterNumber<16>(), \
            					magic(counterNumber<32>(), \
            						magic(counterNumber<64>(), \
            							magic(counterNumber<128>(), counterNumber<0>())))))))))-1)
     
    #define COUNTER_INC() \
        counterNumber<COUNTER_READ()+1> magic( \
            counterNumber<(COUNTER_READ()+1)&~COUNTER_READ()>, \
            counterNumber<(COUNTER_READ()+1)&COUNTER_READ()>)
     
    #include <iostream>
    using namespace std;
    #define TO_STRING(x) #x
     
     
    #define REG_FUNCTIONAL(headFunction) \
        template<> \
        constexpr auto foo< COUNTER_READ() >() \
        { \
            return TO_STRING(headFunction); \
        } \
        COUNTER_INC(); \
        headFunction
     
    template<size_t n>
    constexpr auto foo(void){return "";}
     
     
    REG_FUNCTIONAL(void function(int a)){(void)a;}
    REG_FUNCTIONAL(void function1(int a)){(void)a;}
     
     
    	// your code goes here
    template<size_t n>
    std::string callFoo()
    {
        return std::string(foo<n>())+callFoo<n-1>();
    }
     
    template<>
    std::string callFoo<0>()
    {
        return std::string(foo<0>());
    }
     
    int main() {
    	std::cout<<callFoo<COUNTER_READ()-1>();
    	return 0;
    }

    https://ideone.com/bASDDc

    IKing, 21 Ноября 2015

    Комментарии (6)
  2. JavaScript / Говнокод #19058

    +6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function fvalidate(val) {
    		if($('[name=pwidc]').val() == false) {$('[name=pwidc]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=pwidc]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemname]').val()) {$('[name=itemname]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemname]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemsale]').val()) {$('[name=itemsale]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemsale]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=salemax]').val()) {$('[name=salemax]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=salemax]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemid]').val()) {$('[name=itemid]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemid]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemcount]').val()) {$('[name=itemcount]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemcount]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemcountmax]').val()) {$('[name=itemcountmax]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemcountmax]').css({'background-color':'#FFFFFF','color':'#000000'});}
    	if(!$('[name=itemmask]').val()) {$('[name=itemmask]').css({'background-color':'red','color':'#FFFFFF'}); return false;}else{$('[name=itemmask]').css({'background-color':'#FFFFFF','color':'#000000'});}
    }

    Номинация "Валидация года".
    Скопировано с js файлов одного из сайтов ;D

    skydev, 21 Ноября 2015

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

    +2

    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
    85. 85
    public static byte[] HMACSHA256(ProtectedData key, byte[] data)
    {
        using (var _key = key.Get())
        using (var hmac = new HMACSHA256(_key))
            return hmac.ComputeHash(data);
    }
    
    public static byte[] HMACSHA256(ProtectedData key, Stream stream)
    {
        using (var _key = key.Get())
        using (var hmac = new HMACSHA256(_key))
            return hmac.ComputeHash(stream);
    }
    
    public static byte[] HMACSHA256(byte[] key, byte[] data)
    {
        using (var hmac = new HMACSHA256(key))
            return hmac.ComputeHash(data);
    }
    
    public static byte[] HMACSHA256(byte[] key, Stream stream)
    {
        using (var hmac = new HMACSHA256(key))
            return hmac.ComputeHash(stream);
    }
    
    public static byte[] MD5(byte[] data)
    {
        using (var h = System.Security.Cryptography.MD5.Create())
        { return h.ComputeHash(data); }
    }
    
    public static byte[] MD5(Stream stream)
    {
        using (var h = System.Security.Cryptography.MD5.Create())
        { return h.ComputeHash(stream); }
    }
    
    public static byte[] SHA1(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA1.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA1(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA1.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA256(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA256.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA256(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA256.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA384(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA384.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA384(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA384.Create())
            return h.ComputeHash(stream);
    }
    
    public static byte[] SHA512(byte[] data)
    {
        using (var h = System.Security.Cryptography.SHA512.Create())
            return h.ComputeHash(data);
    }
    
    public static byte[] SHA512(Stream stream)
    {
        using (var h = System.Security.Cryptography.SHA512.Create())
            return h.ComputeHash(stream);
    }

    Психанул

    yourmom, 20 Ноября 2015

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

    −2

    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
    var $skrolmemory = -1 * $(document).scrollTop() * $speed_rotate;
    $ass_skrolmemory =   $(document).scrollTop() * $speed_rotate;
    
    
    interval_one = setInterval(function() 
    		{
    			if ($stop_skrool)
    			{			
    				$({deg: $skrolmemory}).animate({deg: $skrolmemory - $ass_skrolmemory },
    				{
    				 duration: 0,
    				 step: function ($now) 
    					{
    						$(".krug, .img_derzatel_vrashaushiysa, .center_img").css(
    						{
    							transform: "rotate(" + $now + "deg)"
    						});
    						$(".rotate_block, .ssilka").css(
    						{
    							transform: "rotate(" + (-1 * $now) + "deg)"
    						});
    					}
    				}); 				
    				$skrolmemory = $skrolmemory - $speed_srotate;			
    			}
    		}, 2);

    И так: Скрипт крутит картинки постоянно. вопрос: как? Какого Х*ена здесь происходит? если чет поменять, не работает (предыдущий пост не правелен, как удалять не нашел)

    BregoCrash, 20 Ноября 2015

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

    −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
    16. 16
    17. 17
    18. 18
    19. 19
    var $skrolmemory = -1 * $(document).scrollTop() * $speed_rotate;
    $ass_skrolmemory =   $(document).scrollTop() * $speed_rotate;
    
    
    $({deg: $skrolmemory}).animate({deg: $skrolmemory - $ass_skrolmemory },
    {
     duration: 0,
     step: function ($now) 
    	{
    		$(".krug, .img_derzatel_vrashaushiysa, .center_img").css(
    		{
    			transform: "rotate(" + $now + "deg)"
    		});
    		$(".rotate_block, .ssilka").css(
    		{
    			transform: "rotate(" + (-1 * $now) + "deg)"
    		});
    	}
    });

    И так: Скрипт крутит картинки постоянно. вопрос: как? Какого Х*ена здесь происходит? если чет поменять, не работает

    BregoCrash, 20 Ноября 2015

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

    +2

    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
    85. 85
    using Microsoft.VisualBasic;
    
            public string ConvertEnoviaNameForDB1(string name, char Separ = '%')
            {
                string functionReturnValue = null;
                functionReturnValue = name;
                //input filename
                //check ENOVIA filenames (example c0234244 --.catpart or c0234244--.catpart)
                //output filename in DB format for operator LIKE(c0234244 --.catpart -> c0234244%.catpart)
                int i = 0;
                int loc1 = Strings.InStr(name, ".CATP", CompareMethod.Text);
                bool NeedToConvert = false;
                char Chr1 = '1';
                char ChrBefore1 = '1';
                //check catparts and catproducts ONLY
                if (loc1 > 0)
                {
                    int NumSymbols = loc1 - 2;
                    if (NumSymbols > 6)
                        NumSymbols = 6;
                    string tmpstr1 = Strings.Mid(name, loc1 - NumSymbols - 1, NumSymbols);
                    //analyse 4 chars max
                    for (i = 0; i <= loc1 - 2; i++)
                    {
                        Chr1 = name[loc1 - 2 - i];
                        //3-string array start from 0(position = count-1)
                        if ((Strings.Asc(ChrBefore1) >= 65 & Strings.Asc(ChrBefore1) <= 90))
                        {
                            if (Chr1 == ' ')
                            {
                                i = i + 2;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                            else if (Chr1 == '-')
                            {
                                ChrBefore1 = Chr1;
                                //means can be  two chars (ex. "AA") max
                            }
                            else if ((Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90) & i < 2)
                            {
                                ChrBefore1 = Chr1;
                            }
                            else
                            {
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                        else if (ChrBefore1 == '-')
                        {
                            if (Chr1 == ' ')
                            {
                                i = i + 2;
                                break; // TODO: might not be correct. Was : Exit For
                                // And i < 3 Then 'means can be "---" - not more
                            }
                            else if (Chr1 == '-')
                            {
                                //ChrBefore1 = Chr1
                            }
                            else
                            {
                                i = i + 1;
                                break; // TODO: might not be correct. Was : Exit For
                            }
                            //ChrBefore1 = Chr1
                            // means start
                        }
                        else if (ChrBefore1 == '1')
                        {
                            if (Chr1 == '-' | (Strings.Asc(Chr1) >= 65 & Strings.Asc(Chr1) <= 90))
                            {
                                ChrBefore1 = Chr1;
                            }
                            else
                            {
                                i = i + 1;
                                break; // TODO: might not be correct. Was : Exit For
                            }
    
                        }
                    }
                    functionReturnValue = Strings.Left(name, loc1 - i) + Separ + Strings.Right(name, Strings.Len(name) - loc1 + 1);
                }
                return functionReturnValue;
            }

    Наличие комментария в 7ой строчке приводит в неописуемый восторг.
    Без него понимать поведение функции пришлось бы с болью.
    И да, в RegExp могут не только лишь все. Мало кто может.

    Szer, 20 Ноября 2015

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

    +2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    for(int c = 0; c < 2; ++c) 
    {
        if(c) 
        {
            // do something 
        }
        else 
        {
            // do something else
        }
    }

    Одна из причин необходимости разворачивания циклов.

    absolut, 19 Ноября 2015

    Комментарии (64)
  8. Куча / Говнокод #19049

    +2

    1. 1
    2. 2
    А что Рутубом кто то пользуется ? 
    http://habrahabr.ru/company/rutube/blog/271143/

    Vasiliy, 19 Ноября 2015

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

    +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
    Date& operator ++ (Date& date) //даже не хватило строк на говнокоде.ру, чтобы польностью скопировать функцию 
    {
    	if (date.mm == JAN)
    	{
    		if (date.dd == 31)
    		{
    			date.mm = FEB;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}
    	}
    	else if (date.mm == FEB)
    	{
    		if (isLeapYear(date))
    		{
    			if (date.dd == 29)
    			{
    				date.mm = MAR;
    				date.dd = 1;
    			}
    			else
    			{
    				++date.dd;
    			}
    		}
    		else
    		{
    			if (date.dd == 28)
    			{
    				date.mm = MAR;
    				date.dd = 1;
    			}
    			else
    			{
    				++date.dd;
    			}
    		}
    	}
    	else if (date.mm == MAR)
    	{
    		if (date.dd == 31)
    		{
    			date.mm = APR;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}
    	}
    	else if (date.mm == APR)
    	{
    		if (date.dd == 30)
    		{
    			date.mm = MAY;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}
    	}
    	else if (date.mm == MAY)
    	{
    		if (date.dd == 31)
    		{
    			date.mm = JUN;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}
    	}
    	else if (date.mm == JUN)
    	{
    		if (date.dd == 30)
    		{
    			date.mm = JUL;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}
    	}
    	else if (date.mm == JUL)
    	{
    		if (date.dd == 31)
    		{
    			date.mm = AUG;
    			date.dd = 1;
    		}
    		else
    		{
    			++date.dd;
    		}

    mrLaoChao, 19 Ноября 2015

    Комментарии (41)
  10. JavaScript / Говнокод #19047

    +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
    var _point={};
    
                if(point){
                    _point={
                        iconLayout: 'default#image',
                        iconImageHref: point,
                        iconImageSize: [124, 200],
                        iconImageOffset: [-62, -200]
                    };
                }
                else{
                    _point={};
                }

    кусок кода из инициализации карты НЯндекса =)

    StTv, 19 Ноября 2015

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