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

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

    +158

    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
    $GLOBALS['_utf8win1251'] = array(
    "\xD0\x90"=>"\xC0","\xD0\x91"=>"\xC1","\xD0\x92"=>"\xC2","\xD0\x93"=>"\xC3","\xD0\x94"=>"\xC4",
    ............
    "\xD1\x96"=>"\xB3","\xD1\x97"=>"\xBF","\xD1\x94"=>"\xBA","\xD1\x9E"=>"\xA2");
    $GLOBALS['_win1251utf8'] = array(
    "\xC0"=>"\xD0\x90","\xC1"=>"\xD0\x91","\xC2"=>"\xD0\x92","\xC3"=>"\xD0\x93","\xC4"=>"\xD0\x94",
    ............
    "\xB3"=>"\xD1\x96","\xBF"=>"\xD1\x97","\xBA"=>"\xD1\x94","\xA2"=>"\xD1\x9E");
    
    function utf8_win1251($a) {
    //    global $_utf8win1251;
        if (is_array($a)){
            foreach ($a as $k => $v) {
                if (is_array($v)) {
                    $a[$k] = utf8_win1251($v);
                } else {
                    $a[$k] = strtr($v, $GLOBALS['_utf8win1251']);
                }
            }
            return $a;
        } else {
            return strtr($a, $GLOBALS['_utf8win1251']);
        }
    }
    
    function win1251_utf8($a) {
    //    global $_win1251utf8;
        if (is_array($a)){
            foreach ($a as $k=>$v) {
                if (is_array($v)) {
                    $a[$k] = win1251_utf8($v);
                } else {
                    $a[$k] = strtr($v, $GLOBALS['_win1251utf8']);
                }
            }
            return $a;
        } else {
            return strtr($a, $GLOBALS['_win1251utf8']);
        }
    }

    а сколько всего...
    mb_convert_encoding и array_walk_recursive отменили...
    ну или хотя-бы от вложенных if избавиться можно

    ivan.borzenkov, 26 Ноября 2009

    Комментарии (4)
  3. Pascal / Говнокод #2169

    +92.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
    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
    program krestiki_noliki;
    var a,b,c,
        d,e,f,
        g,h,i,
        click:char;
        cl,cr,count:smallint;
    
    procedure move; forward;
    
    procedure clickproc;
    begin
     If cr=0
      then
       begin
        cr:=1;
        click:='X';
       end
      else
       begin
        cr:=0;
        click:='O';
       end;
    end;
    
    procedure restart;
    begin
    if count<9
       then move
       else
        begin
         count:=0;
         cr:=0;
         cl:=0;
         click:='X';
         a:='_';
         b:='_';
         c:='_';
         d:='_';
         e:='_';
         f:='_';
         g:='_';
         h:='_';
         i:='_';
        end;
    end;
    
    procedure move;
    begin
      readln(cl);
      clickproc;
      if (cl=1) and (a='_') then a:=click;
      if (cl=2) and (b='_') then b:=click;
      if (cl=3) and (c='_') then c:=click;
      if (cl=4) and (d='_') then d:=click;
      if (cl=5) and (e='_') then e:=click;
      if (cl=6) and (f='_') then f:=click;
      if (cl=7) and (g='_') then g:=click;
      if (cl=8) and (h='_') then h:=click;
      if (cl=9) and (i='_') then i:=click;
      count:=count+1;
      writeln(a,'|',b,'|',c);
      writeln(d,'|',e,'|',f);
      writeln(g,'|',h,'|',i);
      writeln('-----');
      restart;
    end;
    
    begin
    count:=0;
    cr:=0;
    writeln('1|2|3');
    writeln('4|5|6f');
    writeln('7|8|9');
    writeln('-----');
    restart;
    end.

    навеяло кодом на Visual Basic, подумал что смогу воплотить на Паскале. Зря, не стоило...
    (так и не понял, что именно не работает)

    Airbus, 23 Ноября 2009

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

    +129.7

    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
    public string GetHtmlElement(RepeaterItem Container)
            {
                string Result = string.Empty;
                string AClasses = HAS_CHILDREN_BASE_CSS_CLASS;
                SiteMapNode Node = (SiteMapNode)Container.DataItem;
                string Title = Node.Title;
                string EnabledAttrSign = CustomSiteMapNodeInfo.ENABLED_ATTR_NAME;
                string CssClassNameSign = CustomSiteMapNodeInfo.CSS_CLASS_ATTR_NAME;
    
                string SpanCssClasses = string.Empty;
    
                // checks for separator
                if (string.IsNullOrEmpty(Node.Title) || Node.Title == ShellModuleInitializer.SEPARATOR)
                {
                    SpanCssClasses = MENU_SEPARATOR_CSS_CLASS_NAME;
                    Title = EMPTY_TEXT;
                }
    
                bool HasImage = !string.IsNullOrEmpty(Node[CssClassNameSign]);
                if (HasImage)
                {
                    SpanCssClasses += HAS_IMAGE_CSS_CLASS_NAME;
                }
    
                Result = string.Format("<span class=\"{0}\">{1}</span>", SpanCssClasses, Title);
    
                if (HasImage)
                {
                    Result = string.Format("<span class=\"{0}\">{1}</span>{2}", Node[CssClassNameSign], EMPTY_TEXT, Result);
                }
    
                // checks for disabled item
                if (!string.IsNullOrEmpty(Node[EnabledAttrSign]) && string.Compare(Node[EnabledAttrSign], "false", true) == 0)
                {
                    AClasses += string.Format(" {0}", DISABLED_CSS_CLASS_NAME);
                }
    
                // checks for enabled item
                if (!string.IsNullOrEmpty(Node[EnabledAttrSign]) && string.Compare(Node[EnabledAttrSign], "true", true) == 0)
                {
                    Result = string.Format("<a href=\"{0}\" class=\"{1}\">{2}</a>", GetFullUrl(Container), AClasses, Result);
                }
                else
                {
                    // cheks for non-clickable item
                    Result = string.Format("<a class=\"{0}\">{1}</a>", AClasses, Result);
                }
    
                return Result;
            }

    Valera, 18 Ноября 2009

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

    +150.9

    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
    <?php
    
    ... 
    
    mysql_select_db($database_store, $store);
    $query_rsThisCategoryItems = sprintf("SELECT DISTINCT store_products.product_name, store_products.image_file, store_products.product_id, store_products.product_price, store_products_to_categories.category_id, store_products.sku FROM store_products_to_categories, store_products WHERE store_products_to_categories.category_id=%s AND store_products_to_categories.product_id=store_products.product_id GROUP BY store_products.product_name", GetSQLValueString($cat_rsThisCategoryItems, "int"));
    $rsThisCategoryItems = mysql_query($query_rsThisCategoryItems, $store) or die(mysql_error());
    $row_rsThisCategoryItems = mysql_fetch_assoc($rsThisCategoryItems);
    $totalRows_rsThisCategoryItems = mysql_num_rows($rsThisCategoryItems);
    
    //product query
    
    $colname_rsThisProduct = "1";
    if (isset($_GET['p_id'])) {
      $colname_rsThisProduct = $_GET['p_id'];
    }
    mysql_select_db($database_store, $store);
    $query_rsThisProduct = sprintf("SELECT * FROM store_products WHERE product_id=%s", GetSQLValueString($colname_rsThisProduct, "int"));
    $rsThisProduct = mysql_query($query_rsThisProduct, $store) or die(mysql_error());
    $row_rsThisProduct = mysql_fetch_assoc($rsThisProduct);
    $totalRows_rsThisProduct = mysql_num_rows($rsThisProduct);
    
    
    //cart contents for header summary
    $colname_rsQuickCart = "-1";
    if (isset($_SESSION['sessionid'])) {
      $colname_rsQuickCart = $_SESSION['sessionid'];
    }
    mysql_select_db($database_store, $store);
    $query_rsQuickCart = sprintf("SELECT * FROM store_cart, store_products WHERE store_cart.session_id = %s  AND store_cart.product_id=store_products.product_id", GetSQLValueString($colname_rsQuickCart, "text"));
    $rsQuickCart = mysql_query($query_rsQuickCart, $store) or die(mysql_error());
    $row_rsQuickCart = mysql_fetch_assoc($rsQuickCart);
    $totalRows_rsQuickCart = mysql_num_rows($rsQuickCart);
    
    $colname_rsCartTotal = "-1";
    if (isset($_SESSION['sessionid'])) {
      $colname_rsCartTotal = $_SESSION['sessionid'];
    }
    mysql_select_db($database_store, $store);
    $query_rsCartTotal = sprintf("SELECT SUM(total_price) FROM store_cart WHERE session_id = %s", GetSQLValueString($colname_rsCartTotal, "text"));
    $rsCartTotal = mysql_query($query_rsCartTotal, $store) or die(mysql_error());
    $row_rsCartTotal = mysql_fetch_assoc($rsCartTotal);
    $totalRows_rsCartTotal = mysql_num_rows($rsCartTotal);
    
    ...
    
    ?>

    пришёл на работу.
    Дали до делать вебсайт
    увидел ЭТО....и обиделся на аФФтара О_о

    Senya, 11 Ноября 2009

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

    +126.4

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (object item in this.cbFind.Properties.Items)
                    {
                        int a = -1;
                    }

    Behemoth, 06 Ноября 2009

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

    +136.7

    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
    void parseDate(String str, ref int day, ref int month, ref int year)
            {
                String[] strings = str.Split('/');
                day = Int32.Parse(strings[0]);
                month = Int32.Parse(strings[1]);
                year = Int32.Parse(strings[2]);
            }
    
    bool validateDate(String s)
            {
                //let the data be null
                if (s == null || s == "")
                    return true;
                try
                {
                    String[] strings = s.Split('/');
                    if (strings.Length != 3)
                        return false;
    
                    String day = strings[0];
                    if (Int32.Parse(day) > 31)
                    {
                        return false;
                    }
                    String month = strings[1];
                    if (Int32.Parse(month) > 12)
                    {
                        return false;
                    }
                    String year = strings[2];
                    if (year.Length != 4)
                    {
                        return false;
                    }
                }
                catch (SystemException)
                {
                    return false;
                }
                return true;
            }
    
    int compareDates(String s1, String s2)
            {
                if (s1 == "" && s2 != "")
                    return -1;
                if (s1 == s2)
                    return 0;
                if (s1 != "" && s2 == "")
                    return 1;
    
                int day1 = 0, month1 = 0, year1 = 0, day2 = 0, month2 = 0, year2 = 0;
                parseDate(s1, ref day1, ref month1, ref year1);
                parseDate(s2, ref day2, ref month2, ref year2);
                if (year1 > year2)
                    return -1;
                if (year1 < year2)
                    return 1;
    
                if (month1 > month2)
                    return -1;
                if (month2 < month1)
                    return 1;
    
                if (day1 > day2)
                    return -1;
                if (day2 > day1)
                    return 1;
    
                return 0;
            }

    no comments

    alex, 06 Ноября 2009

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

    +161.8

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function casecyr($eng) {
    $rus = $eng;
    if ($eng=="д") $rus = "Д";
    if ($eng=="ш") $rus = "Ш";
    if ($eng=="п") $rus = "П";
    if ($eng=="с") $rus = "С";
    if ($eng=="т") $rus = "Т";
    if ($eng=="ч") $rus = "Ч";
    if ($eng=="в") $rus = "В";
    if ($eng=="о") $rus = "О";
       return $rus;
    }

    Без комментариев

    Werdn, 02 Ноября 2009

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

    +160.5

    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
    echo "Ваша корзина:";
    foreach ($_REQUEST as $name => $value)
    switch ($value)
    {
    case "ras1":
    echo "<p> $name";
    break;
    case "ras2":
    echo "<p> $name";
    break;
    case "ras3":
    echo "<p> $name";
    break;
    case "ras4":
    echo "<p> $name";
    break;
    case "ras5":
    echo "<p> $name";
    break;
    case "ras6":
    echo "<p> $name";
    break;
    case "ras7":
    echo "<p> $name";
    break;
    case "ras8":
    echo "<p> $name";
    break;
    }
    $filename= 'zakaz.txt';
    $somecontent = "$name\n";
    
    if (is_writable($filename)) {
    fwrite().
    if (!$handle = fopen($filename, 'w')) {
    echo "Не могу открыть файл ($filename)";
    exit;
    }
    if (fwrite($handle, $somecontent) === FALSE) {
    
    exit;
    }
    fclose($handle);
    
    }

    чувак спросил на форуме, почему его скрипт все время выводит строку 'vc' вместо страницы. Потом привел аццкий код :)

    varan, 01 Ноября 2009

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

    +164.6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <?php 
    // ...
    $content = join('',file("".$main_server."site/".$links_path.""));
     if (strlen($content) >= 20000)$content = 'Ошибка!';
    echo $content;
    ?>

    Самая убойная проверка на ошибки, которую я только видел. Из предыстории, есть один один супер проект, который раздает данные какого-либо рода.
    Данные выхватываются с неге по http, что мы собственно и видим, и выводятся.
    Основной проект написан так, что если друг URL не верен, то выдает var_dump отладочной информации. В связи с этим автор этого кода выдал афигенную проверку на ошибки.
    Достойно индусов :D
    про загрузку я вообще молчу, это же просто изврат ( в общем, решение жутко плохое, но на половине клиентов оно крутится до сих пор, и исправлять это никто не собирается :(

    nicolay-punin, 01 Ноября 2009

    Комментарии (4)
  11. Perl / Говнокод #2071

    −115.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $oblom = 1;
    if ($pusto == 0) {#Если пусто, то сред никем не занят
    	$oblom = 0;
    } else {
    	$oblom = 0;
    .....

    Смотри на переменную $oblom
    В продолжение 2059

    Oleg_quadro, 29 Октября 2009

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