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

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

    +170

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function onKeyDown() {
            var key_f5 = 116; // 116 = F5 
    
            if (key_f5 == event.keyCode) {
              event.keyCode = 27;
    
              return false;
            }
          }

    Запрещаем обновление страницы по F5.

    Ccik, 10 Января 2013

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

    +23

    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
    struct S* gpS;
    
    struct S
    {
       // this class has no user-defined default ctor
       void *operator new (size_t size, void*p, int i)
       {
          ((S*)p)->i = i;   // ordinarily, should not initialize
                            // memory contents inside placement new
          return p;
       }
       int i;
    };

    Код с сайта майкрософт.

    LispGovno, 09 Января 2013

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

    +58

    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
    // Released Under Affero General Public License, Version 3 (AGPL3)
    // Author: [email protected]
    
    $result = "TRUE";
    
    $testable_string = strtolower($string_to_test);
    $testable_string_length = strlen($string_to_test);
    
    for($i_string = 0; $i_string < $testable_string_length; $i_string++)
    {
        $current_value_to_test = $testable_string[$i_string];
       
        if(    ($current_value_to_test != "0")        &&
            ($current_value_to_test != "1")        &&
            ($current_value_to_test != "2")        &&
            ($current_value_to_test != "3")        &&
            ($current_value_to_test != "4")        &&
            ($current_value_to_test != "5")        &&
            ($current_value_to_test != "6")        &&
            ($current_value_to_test != "7")        &&
            ($current_value_to_test != "8")        &&
            ($current_value_to_test != "9")        &&
            ($current_value_to_test != "a")        &&
            ($current_value_to_test != "b")        &&
            ($current_value_to_test != "c")        &&
            ($current_value_to_test != "d")        &&
            ($current_value_to_test != "e")        &&
            ($current_value_to_test != "f")        )
        {
            $result = "FALSE";
            $i_string = $testable_string_length;
        }
    }

    Смахивает на баян, но тем не менее.
    http://php.net/manual/ru/function.is-numeric.php, из комментов.

    RaZeR, 14 Декабря 2012

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

    +50

    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
    function StringForCountryInt($countryInt)
    	{
    		switch ($countryInt)
    		{
    			case "1" : return 'Afghanistan'; break;
                case "2" : return 'Albania'; break;
                case "3" : return 'Algeria'; break;
                case "4" : return 'American Samoa'; break;
                case "5" : return 'Andorra'; break;
                case "6" : return 'Angola'; break;
                case "7" : return 'Anguilla'; break;
                case "8" : return 'Antarctica'; break;
    //          ....
    //          ....
    //          ....
                 case "239" : return 'Zimbabwe'; break;
    		}
    	}

    MODx, evolution. Сниппет WebLoginPE.
    В базе сохраняет ID страну, в классе вот такой метод для обратного преобразования :)

    MaXL, 04 Декабря 2012

    Комментарии (17)
  6. PHP / Говнокод #12210

    +51

    1. 1
    2. 2
    3. 3
    4. 4
    $needMoreDataWM = ($exchange->getSumTo()->getCurrency()->getSystem()->getModule() == 'WebMoney' || $exchange->getSumFrom()->getCurrency()->getSystem()->getModule() == 'WebMoney') || $this->getRequest()->request->get('user_wmid');
    $needMoreDataWM = $needMoreDataWM && !$user->getWmid();
    $needMoreDataBank = ($exchange->getSumTo()->getCurrency()->getSystem()->getClass() == 'bank') && !$user->getVat() || $this->getRequest()->request->get('user_vat');
    $needMoreData = $needMoreDataBank || $needMoreDataWM || !($user->getFullname() && $user->getPassport()) || $this->getRequest()->request->get('user_fullname') || $this->getRequest()->request->get('user_passport');

    А что поделаешь, Doctrine принуждает

    nick4fake, 28 Ноября 2012

    Комментарии (17)
  7. Си / Говнокод #12197

    +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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    #include<stdio.h>
    #include<math.h>
     
    int main()
    {
    long long a1,a2,a3,a4,t,p,l,m1,m,d1,d2,d3,d4,c1,c2,c3,c4,n,r;
    double po;
     
    m=1000000006;
    scanf("%lld",&t);
    while(t--)
         {scanf("%lld",&n);
         a1=1;a2=1;a3=1;a4=0;
         d1=1;d2=0;d3=0;d4=1;
         
         p=n-2;
    while(p>0)
         {    if(p%2!=0)
            { c1=((d1*a1)%m+(d3*a3)%m);
              c2=((d1*a2)%m+(d2*a4)%m);
              c3=((d3*a1)%m+(d4*a3)%m);
              c4=((d3*a2)%m+(d4*a4)%m);
              d1=c1;d2=c2;d3=c3;d4=c4;
            }
              c1=((a1*a1)%m+(a2*a3)%m);
              c2=((a1*a2)%m+(a2*a4)%m);
              c3=((a3*a1)%m+(a4*a3)%m);
              c4=((a3*a2)%m+(a4*a4)%m);
              a1=c1;a2=c2;a3=c3;a4=c4;
              p=p/2;
         }
     l=((d1*1)%m+(d2*1)%m)%m;m1=((d3*1)%m+(d4*1)%m)%m;
     
    po=pow(2,l);
    r=llrintl(po)%(m+1);
     
     
    printf("%lld\n",r);
    }
    return 0;
       }

    Fai, 26 Ноября 2012

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

    +124

    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
    Сайт ЦИК Украины, нынешние выборы народных депутатов. 
    http://cvk.gov.ua/vnd2012/wp300pt001f01=900.html
    Говно везде - html, css, дизайн, юзабилити. 
    
    Для начала цитаты из html-кода страницы. В шапке мы видим 
    заголовок "XHTML 1.0 Transitional", а в коде - конструкции 
    в стиле 90-х годов, например:
    
    <IMG src="img2012/bar-blue1.jpg" WIDTH=" 1" HEIGHT=20>
    
    <table class=t1 cellspacing=0><tr>
        <td width="50%" class="td2"><font class="f3"> © WWW ІАС "Вибори 
            народних депутатів України"
        <td align="right" class="td2"> 
    </table>
    
    <td class=td10 align=center><font color="maroon">2</font>
    <td class=td2><A class=a1 href="wp302pt001f01=900pf7171=52.html">
    політична партія Всеукраїнське об’єднання "Батьківщина"</A></td>
    
    В стилях тоже все в порядке, товарищи проявили 
    отличное знание спецификаций:
    ... height=14px; ...
    ... background-color: 666699; ...
    ... text-decoration: non ...
    ... background-color : none; ...
    ... valign: center; ...
    
    Про отсутствие смысла я даже не говорю. 
    Вот, например, такой перл:
    FONT.F1 {color: black; font-family:Arial;font-size: 14pt}

    Сайт ЦИК Украины. Не сомневаюсь, что ООО "НПП "Медирент"" и ООО "НПП "Проком" получили за свою работу сотни нефти.

    P.S. Плохо, что в самом говнокоде нельзя применять форматирование bb-тегами, для кучи было бы полезно.

    ZX_Spectrum, 31 Октября 2012

    Комментарии (17)
  9. Java / Говнокод #11985

    +74

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public void aMethod() {
        try {
            int t = 0;
            t = t / t;
        } catch (Exception e) {
            System.out.println("aMethod");
            for (StackTraceElement element : e.getStackTrace()) {
                System.out.println("aMethod" + element.getClassName() + " " + element.getMethodName() + " " + element.getLineNumber() );
            }
        }
    ...//дополнительная "логика"
    }

    оригинальный способ узнать кто же вызвал aMethod

    Cat4eg, 24 Октября 2012

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

    +141

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    var x = new { Items = new List<int> { 1, 2, 3 }.GetEnumerator() };
    while (x.Items.MoveNext())
    {
        Console.WriteLine(x.Items.Current);
    }

    http://ideone.com/Qzdki

    LispGovno, 16 Октября 2012

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

    +19

    1. 1
    Lennart lennart=new Lennart;

    Надпись жёлтым цветом на гпавном меню minecraft.

    dos_, 17 Сентября 2012

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