1. PHP / Говнокод #11530

    +59

    1. 1
    if ( (is_file($filename) == true) == true)

    MaxSvargal, 04 Августа 2012

    Комментарии (14)
  2. Куча / Говнокод #11529

    +125

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

    http://anidream.net/

    zim, 04 Августа 2012

    Комментарии (47)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)