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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    #define private public
    #include <vector>
    #include <iostream>
    
    int main()
    {
       // . . .
    }

    Вот так вот просто обращаться к приватным полям чужих классов))

    k06a, 02 Марта 2011

    Комментарии (4)
  2. Си / Говнокод #5839

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    #define v putchar
    #define print(x) main(){v(4+v(v(52)-4));return 0;} /*
    #>++++++4[>++++++<-]>++++.----.++++.**/
    print(202*2);exit();
    #define/*>.@*/exit()

    Для кого-то покажется бояном, но меня улыбнуло. Явно искусственный код взятый со stackoverflow.com

    xaionaro, 01 Марта 2011

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

    +123

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    private bool IsInt(object ValueToCheck)
    {
    	int Dummy = new int();
    	string InputValue = Convert.ToString(ValueToCheck);
    
    	//If user enters 45.00 This should not be allowed
    	//User must enter numbers without .00
    	if(InputValue.Contains("."))
    		return false;
    	bool Int = int.TryParse(InputValue, System.Globalization.NumberStyles.Any, null, out Dummy);
    	return Int;
    }

    Уже другой индусский автор наговнокодил. Орфография сохранена. Причем он сам себе в ногу выстрелил используя NumberStyles.Any...

    Вот как надо:

    private static bool IsInt(string valueToCheck) 
    {
    int dummy;
    return int.TryParse(valueToCheck, System.Globalization.NumberStyles.None, null, out dummy);
    }

    piocsic, 01 Марта 2011

    Комментарии (14)
  4. C# / Говнокод #5837

    +115

    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
    char[] splitter = { ',' };
    string types = hashtable[FlagsEnumValue].ToString();
    string[] typesStringArray = types.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
    ArrayList typesArray = new ArrayList();
    
    foreach (string str in typesStringArray)
    {
       foreach (string type in Enum.GetNames(typeof(FlagsEnum)))
       {
          if (type == str.Trim())
          {
             typesArray.Add((FlagsEnum)Enum.Parse(typeof(FlagsEnum), str, true));
             break;
          }
       }
    }
    
    
    foreach (FlagsEnum type in typesArray)
    {
       if ((someObject.field & type) > 0)
       {
          typeFound = true;
       }
       else
       {
          typeFound = false;
          break;
       }
    }

    Автор хотел чтобы его любили. Точнее он хотел сконвертировать строковое представление битового енама в инам и сравнить по маске с проперти обьекта. Если бы автор прочел документацию то написал бы так:
    string types = hashtable[FlagsEnumValue].ToString();
    if (types != "")
    {
    FlagsEnum enum = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), types, ignoreCase: true);
    if ((enum & someObject.field) == enum)
    typeFound = true;
    }

    piocsic, 01 Марта 2011

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

    +154

    1. 1
    function(&(*(--Iter)++);

    Вот как надо использовать итератор...

    Tirect, 01 Марта 2011

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

    −80

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    String period_name[][] = {
         {"Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"},
         {"Январь-Февраль","Март-Апрель","Май-Июнь","Июль-Август","Сентябрь-Октябрь","Ноябрь-Декабрь"},
         {"1 Квартал","2 Квартал","3 Квартал","4 Квартал"},
         {"Январь-Апрель","Май-Август","Сентябрь-Декабрь"},
         {"1 Полугодие","2 Полугодие"}
    }

    3.14159265, 01 Марта 2011

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

    +166

    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
    $url=$_SERVER['REQUEST_URI'];
    $url9=substr($url,0,9);
    $url8=substr($url,0,8);
    $url14=substr($url,0,14);
    $url10=substr($url,0,10);
    $url5=substr($url,0,5);
    if ($url9=='/calendar') {
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Calendar -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }elseif ($url8=='/content'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Content -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url14=='/forum_arch'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Forum archiv -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url10=='/forum/'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Forum pages -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    elseif ($url5=='/news'){
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / News -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }
    else {
    printf('<!-- (C)2000-2010 Gemius SA - gemiusAudience / sitecom / Glavnaja stranitsa sajta -->
    <script type="text/javascript">
    <!--//--><![CDATA[//><!--
    var pp_gemius_identifier = new String(\'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\');
    //--><!]]>
    </script>
    <script type="text/javascript" src=" http://site.com/gemius/xgemius.js"></script>');
    }

    Вместо xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxx в коде оригинальные id счетчиков. Это всё чудо лежит в базе и выполняется через eval()

    nergalic, 01 Марта 2011

    Комментарии (3)
  8. SQL / Говнокод #5833

    −183

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    CREATE TABLE `log_event` (
      `id` bigint(20) NOT NULL auto_increment,
      `logtime` datetime default NULL,
      `etype` text,
      `module` text,
      `edata` text,
      `session` text,
      PRIMARY KEY  (`id`),
      UNIQUE KEY `id` (`id`),
      KEY `id_2` (`id`)
    )

    чтобы наверняка

    elw00d, 01 Марта 2011

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

    +127

    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
    static void jz_update_dram_prev(unsigned int cur_mclk, unsigned int new_mclk)
    {
            /* No risk, no fun: run with interrupts on! */
            if (new_mclk > cur_mclk) {
                    /* We're going FASTER, so first update TRAS, RCD, TPC, TRWL
                     * and TRC of DMCR before changing the frequency.
                     */
                    jz_update_dram_dmcr(new_mclk);
            } else {
                    /* We're going SLOWER: first update RTCOR value
                     * before changing the frequency.
                     */
                    jz_update_dram_rtcor(new_mclk);
            }
    }

    Кусок кода из официального™ китайского дерева исходников Линукса для одного System-on-Chip.

    Реализует поддержку динамического изменения частоты процессора, а приведенная функция меняет тайминги для памяти (как обычно, весьма альтернативным способом). Что характерно, это вполне себе работает на реальном железе, и вроде бы оно у меня в этом куске ни разу не падало.

    whitequark, 01 Марта 2011

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

    +159

    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 _getConditionWithCategoryConj( $condition, $categoryID ) //fetch products from current category
    {
      $category_condition = "";
      $q = db_query("select productID from ".
                CATEGORIY_PRODUCT_TABLE." where categoryID=".(int)$categoryID);
      $icounter = 0;
      while( $product = db_fetch_row( $q ) )
      {
        if ( $icounter == 0 )
          $category_condition .= " productID IN ('";
        if ( $icounter > 0 )
          $category_condition .= ", ";
        $category_condition .= (int)$product[0];
        $icounter++;
      }
      if ( $icounter>0 ) {
        $category_condition .= "')";
      }

    shopcms.
    нет слов больше.

    zealotous, 01 Марта 2011

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