1. Куча / Говнокод #11529

    +125

    1. 1
    2. 2
    3. 3
    Сайт оптимизирован под 
    браузер GooGle Chrome
    Разрешение: 1280х1024

    http://anidream.net/

    zim, 04 Августа 2012

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

    +12

    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
    void EllipticPoint::Add(const EllipticPoint &b, const EllipticCoord &a, const EllipticCoord &p, EllipticPoint &res) {
        if (!x.IsNotZero() && !y.IsNotZero()) {
            res = b;
        } else if (!b.x.IsNotZero() && !b.y.IsNotZero()) {
            res = *this;
        } else if (x.Compare(b.x)!=0) {
            EllipticCoord tmp1, tmp2, lambda;
            b.x.Sub(x,p,tmp1); tmp1.Invert(p,tmp2);
            b.y.Sub(y,p,tmp1); tmp1.Mul(tmp2,p,lambda);
            lambda.Mul(lambda,p,tmp1);
            tmp1.Sub(x,p,tmp2); tmp2.Sub(b.x,p,res.x);
            x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp2); tmp2.Sub(y,p,res.y);
        } else if (y.Compare(b.y)==0) {
            EllipticCoord tmp1, tmp2, tmp3, lambda;
            x.Mul(x,p,tmp1); tmp1.Add(tmp1,p,tmp3); tmp1.Add(tmp3,p,tmp2); tmp2.Add(a,p,tmp1);
            y.Add(y,p,tmp2); tmp2.Invert(p,tmp3); tmp1.Mul(tmp3,p,lambda);
            lambda.Mul(lambda,p,tmp1); tmp1.Sub(x,p,tmp2); tmp2.Sub(x,p,res.x);
            x.Sub(res.x,p,tmp1); lambda.Mul(tmp1,p,tmp3); tmp3.Sub(y,p,res.y);
        } else {
            res.x.SetZero();
            res.y.SetZero();
        }
    }

    Из моего велосипеда четырехлетней давности.
    Кусочек реализации ГОСТ Р 34.10-2001.

    bormand, 03 Августа 2012

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

    +142

    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
    while (true)
    {
        try
        {
            ProductService.Invoke(method);
            return; 
        }
        catch(Exception ex)
        {
            if (ex is System.ServiceModel.CommunicationException)
            {
                if (currentRetryCount == RetryCount)
                        throw new CommunicationException(CommunicationFailureMessage, ex);
                    System.Threading.Thread.Sleep(RetryWait);
                    currentRetryCount++;
            }
        }
    }

    abatishchev, 03 Августа 2012

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

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    $("#select_id :selected").attr("selected", false);
    $("#select_id option[value='" + new_value + "']").attr("selected", true);
    вместо
    $("#select_id").val(new_value);

    splinter89, 03 Августа 2012

    Комментарии (4)
  5. PHP / Говнокод #11525

    +56

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    $cur_url=$_SERVER['REQUEST_URI'];
    if ($cur_url=='/') { 
    	$cur_url=$_SERVER['REQUEST_URI']; 
    	if ($cur_url=='/') { // Точно-точно адрес не равен слэшу
    		echo '';// После всех проверок можно с уверенностью вывести пустую строку
    	}
    }
    $cur_url2=$_SERVER['REQUEST_URI'];// И ещё разок
    if ($cur_url2!='/') { 
    	echo '';
    }

    Из движка одного московского портала, директор которого пытается нас убедить что там нормальный код

    RedMonkey, 03 Августа 2012

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

    +140

    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
    FileInfo file = new FileInfo(fileName);
    FileSecurity fSecurity = File.GetAccessControl(fileName);
    
    foreach (FileSystemAccessRule permissions in fSecurity.GetAccessRules(true, true, typeof(NTAccount)))
    {
         string login = permissions.IdentityReference.Translate(typeof(NTAccount)).Value.ToString();
         string permiss =  permissions.FileSystemRights.ToString();
    
         if ((login != "логин") && (login != "логин") && (login != "логин"))
         {
             fSecurity.SetAccessRuleProtection(true, false);
             fSecurity.RemoveAccessRule(new FileSystemAccessRule(login, permissions.FileSystemRights, AccessControlType.Allow));
         }
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
         fSecurity.AddAccessRule(new FileSystemAccessRule("логин", FileSystemRights.FullControl, AccessControlType.Allow));
    
    }
    File.SetAccessControl(fileName, fSecurity);

    vertu, 03 Августа 2012

    Комментарии (11)
  7. Java / Говнокод #11523

    +90

    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
    public enum TimeUnit {
       NANOSECONDS {
            public long toNanos(long d)   { return d; }
            public long toMicros(long d)  { return d/(C1/C0); }
            public long toMillis(long d)  { return d/(C2/C0); }
            public long toSeconds(long d) { return d/(C3/C0); }
            public long toMinutes(long d) { return d/(C4/C0); }
            public long toHours(long d)   { return d/(C5/C0); }
            public long toDays(long d)    { return d/(C6/C0); }
            public long convert(long d, TimeUnit u) { return u.toNanos(d); }
            int excessNanos(long d, long m) { return (int)(d - (m*C2)); }
        }
    ....
        public long convert(long sourceDuration, TimeUnit sourceUnit) {
            throw new AbstractMethodError();
        }
    
     
        public long toNanos(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toMicros(long duration) {
            throw new AbstractMethodError();
        }
    
        public long toMillis(long duration) {
            throw new AbstractMethodError();
        }
    
     
        public long toSeconds(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toMinutes(long duration) {
            throw new AbstractMethodError();
        }
    
      
        public long toHours(long duration) {
            throw new AbstractMethodError();
        }
    
     
        public long toDays(long duration) {
            throw new AbstractMethodError();
        }
    
      
        abstract int excessNanos(long d, long m);
    }

    Но зачем?

    3.14159265, 02 Августа 2012

    Комментарии (61)
  8. ActionScript / Говнокод #11522

    −92

    1. 1
    2. 2
    3. 3
    public function xor(lhs:Boolean, rhs:Boolean):Boolean {
     return !( lhs && rhs ) && ( lhs || rhs );
    }

    Из http://as3snippets.blogspot.com/2010/09/logical-xor.html

    Как известно, в AS3 есть численный оператор XOR ^, а вот для логических значений ^^ нет. Поэтому ребята придумали такую конструкцию (и ещё вариант return Boolean(int(a) ^ int(b)); в комментах), и только через год какой-то чувак догадался что XOR для логических значений всё-таки есть и называется !=

    makc3d, 02 Августа 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach (var item in text.Split(' ')) {
    	if (!string.IsNullOrEmpty(item)) {
    		text = item;
    		break;
    	}
    }

    переменная text всегда содержит несколько пробелов и затем идентификатор.

    paladin80, 02 Августа 2012

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

    +20

    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
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    class TCP1251ToUTF16StringConverter
    {
    public:
    	static WideChar convert(Char Source)
    	{
    		WideChar Result=static_cast<unsigned char>(Source);
    		const WideChar Russian_YO=static_cast<unsigned char>('Ё');
    		const WideChar Russian_yo=static_cast<unsigned char>('ё');
    		const WideChar RussianWide_YO=L'Ё';
    		const WideChar RussianWide_yo=L'ё';
    		const WideChar Russian_A=static_cast<unsigned char>('А');
    		const WideChar RussianWide_A=L'А';
    		const unsigned int AmountOfSymbols=0x40;
    		if(Result==Russian_YO)
    			return RussianWide_YO;
    		if(Result==Russian_yo)
    			return RussianWide_yo;
    		if(Result>=Russian_A&&Result<Russian_A+AmountOfSymbols)
    			return (Result-Russian_A+RussianWide_A);
    		return Result;
    	};
    	
    	static void convert(PwideChar UTF16StringDestination, PChar CP1251WinEngRusStringSource, const size_t TextLength)
    	{
    		assert(CP1251WinEngRusStringSource!=NULL);
    		size_t i=0;
    		for(;;)
    		{
    			if(i>=TextLength)
    				break;
    			assert(i<TextLength);
    			Char CP1251SourceChar=CP1251WinEngRusStringSource[i];
    			if(CP1251SourceChar=='\0')
    				break;
    			UTF16StringDestination[i]=convert(CP1251SourceChar);
    			++i;			
    		};
    		UTF16StringDestination[i]=L'\0';
    		assert(i<=TextLength);
    	};
    	
    	static std::wstring convert(const std::string& CP1251WinEngRusStringSource)
    	{
    		assert(CP1251WinEngRusStringSource.c_str()!=NULL);
    		std::wstring UTF16StringDestination;
    		std::transform(CP1251WinEngRusStringSource.begin(), CP1251WinEngRusStringSource.end(), std::inserter(UTF16StringDestination, UTF16StringDestination.end())/*std::back_inserter(UTF16StringDestination)*//*VC 6.0 compatible*/, makePointerToFunction(convertChar));
    		return UTF16StringDestination;
    	};
    	
    private:
    	static WideChar convertChar(char Source)
    	{
    		return convert(Source);
    	};
    };
    
    template<const size_t MaxAmountOfChar>
    class TCP1251ToUTF16StringInPlaceConverter
    {
    public:
    	TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource)
    	{
    		STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
    		TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
    	};
    	
    	TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource, const size_t TextLength)
    	{
    		STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
    		assert(TextLength<=MaxAmountOfChar);
    		TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
    	};
    	
    	void convert(PChar CP1251WinEngRusStringSource)
    	{
    		TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
    	};
    	
    	void convert(PChar CP1251WinEngRusStringSource, const size_t TextLength)
    	{
    		assert(TextLength<=MaxAmountOfChar);
    		TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
    	};
    	
    	PWideChar Get(void) const
    	{
    		return &(_buffer[0]);
    	};
    	
    	PwideChar Get(void)
    	{
    		return &(_buffer[0]);
    	};
    	
    	wideChar _buffer[MaxAmountOfChar+1];
    };

    USB, 02 Августа 2012

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