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

    В номинации:
    За время:
  2. Куча / Говнокод #12527

    +126

    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
    ZipWith[f_, vector1_, vector2_] := Table[ f[ vector1[[i]], vector2[[i]] ], {i, Min[Length[vector1], Length[vector2]] } ]
    
    UnZip[list_] := {Map[First, list], Map[Rest, list]}
    
    Zip[vector1_, vector2_] :=  ZipWith[{#1, #2} &, vector1, vector2]
    ZipWithIndex[vector_] := Zip[vector, Range[1, Length[vector]]]
    ZipWithIndexed[f_, vector1_, vector2_] := Map[f @@ # &, Map[Flatten, Zip[vector1, ZipWithIndex[vector2]]]] 
    
    Fold2[f_, initialState_, list1_ , list2_ ] := Fold[f @@ Prepend[#2, #1] &, initialState, Zip[list1, list2]]
    
    ZipWith1[f_, {}, any_] := {}
    ZipWith1[f_, any_, {}] := {}
    ZipWith1[f_, {h1_, t1___}, {h2_, t2___}] := Prepend[ZipWith1[f, {t1}, {t2}], f[h1, h2]]; (*Extremal version, but recursion depth is 256 *)
     
    GroupByIndex[list_, indexesOfGroup_] := (UnZip[#][[1]]) & /@ Gather[ZipWithIndex[list], (And @@ Map[(MemberQ[indexesOfGroup, #]) &, {#1[[2]], #2[[2]]}]) &]

    Wolfram Mathematica

    Говногость, 01 Февраля 2013

    Комментарии (19)
  3. JavaScript / Говнокод #12491

    +149

    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
    Wreqr.Commands = (function(Wreqr){
      "use strict";
    
      return Wreqr.Handlers.extend({
        execute: function(){
          var name = arguments[0];
          var args = Array.prototype.slice.call(arguments, 1);
    
          this.getHandler(name).apply(this, args);
        }
      });
    
    })(Wreqr);

    из библиотеки которая претендует на популярность, шаблонность (в модном нынче смысле слова) и стэйт-оф-зэ-артность
    вопрос - НАХ8Я СТРОКА 6???????

    dimalev, 29 Января 2013

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

    +67

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    class IntegerUtils
    {
        public static function isInteger($value)
        {
            return preg_match('/[0-9]+/', $value);
        }
    }

    Must have класс, который должен быть у каждого в его библиотеке "велоприседов". Поистине краткий, лаконичный, гениальный. Даешь 100% говнокод!

    SunnyMagadan, 22 Января 2013

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

    −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
    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
    - (void)movementScreenUp
    {
        int shift;
        switch (_numberCell) {
            case 3:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 50;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 90;
                    break;
                }
                
            case 4:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 25;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 90;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 90;
                    break;
                }
                
            case 5:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = - 1;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 40;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 86;
                    break;
                }
                if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
                    shift = - 86;
                    break;
                }
            
            case 6:
                if (clickButtonGameCells.tag == 1 || clickButtonGameCells.tag == 10) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 2 || clickButtonGameCells.tag == 20) {
                    shift = startPosition.y;
                    break;
                }
                if (clickButtonGameCells.tag == 3 || clickButtonGameCells.tag == 30) {
                    shift = - 2;
                    break;
                }
                if (clickButtonGameCells.tag == 4 || clickButtonGameCells.tag == 40) {
                    shift = - 52;
                    break;
                }
                if (clickButtonGameCells.tag == 5 || clickButtonGameCells.tag == 50) {
                    shift = - 105;
                    break;
                }
                if (clickButtonGameCells.tag == 6 || clickButtonGameCells.tag == 60) {
                    shift = - 105;
                    break;
                }
                
            default:
                break;
                 
        }
    
        [UIView animateWithDuration:0.25 animations:^{
            CGRect view_frame = self.frame;
            view_frame.origin = CGPointMake(self.frame.origin.x, shift);
            self.frame = view_frame;
        }];
    }

    Магия цифр

    tyler, 20 Января 2013

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

    +46

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $week['monday'] = date("d.m.Y", $week_start);
    $week['tuesday'] = date("d.m.Y", $week_start + 1 * 86400);
    $week['wednesday'] = date("d.m.Y", $week_start + 2 * 86400);
    $week['thursday'] = date("d.m.Y", $week_start + 3 * 86400);
    $week['friday'] = date("d.m.Y", $week_start + 4 * 86400);
    $week['saturday'] = date("d.m.Y", $week_start + 5 * 86400);
    $week['sunday'] = date("d.m.Y", $week_start + 6 * 86400);

    1allen, 20 Декабря 2012

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

    +37

    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
    <?php
    session_start();
    if(!empty($_SESSION['UserLogin']) or !empty($_SESSION['UserId']))
    {
      header('Location: user');
    }
    if(isset($_POST['UserName'])) 
    { 
      $UserName = $_POST['UserName']; 
      if($UserName == '') 
      {
       unset($UserName);
      } 
    }
    if(isset($_POST['UserEmail'])) 
    { 
      $UserEmail = $_POST['UserEmail']; 
      if($UserEmail == '') 
      {
       unset($UserEmail);
      } 
    } 
    if(isset($_POST['UserLogin'])) 
    { 
      $UserLogin = $_POST['UserLogin']; 
      if($UserLogin == '') 
      {
       unset($UserLogin);
      } 
    }
    if(isset($_POST['UserPassword'])) 
    { 
      $UserPassword = $_POST['UserPassword']; 
      if($UserPassword == '') 
      {
       unset($UserPassword);
      } 
    }
    if (empty($UserName) or empty($UserEmail) or empty($UserLogin) or empty($UserPassword))
    {
     header('Location: registration?error_code=1');
    }
    else
    {
      include("application/db.config.php");
      $UserLogin = stripslashes($UserLogin);
      $UserLogin = htmlspecialchars($UserLogin);
      $UserLogin = trim($UserLogin);
      $UserPassword = stripslashes($UserPassword);
      $UserPassword = htmlspecialchars($UserPassword);
      $UserPassword = trim($UserPassword);
      $SelectQuery = mysql_query("SELECT id FROM Users WHERE UserLogin ='$UserLogin'", $db);
      $QueryResult = mysql_fetch_array($SelectQuery);
      if(!empty($QueryResult['id']))
      {
        header('Location: registration?error_code=2');
      }
      else
      {
        $InsertQuery = mysql_query("INSERT INTO Users(UserName, UserSName, UserLogin, UserPassword, UserEmail, 
        UserPhone, UserStatus) VALUES('$UserName', 'Фамилия не указана', '$UserLogin', '$UserPassword', '$UserEmail', 'Телефон не указан', 'Статус не указан')");
        if($InsertQuery == true)
        {
          header("Location: action_status?reg_code=good&UserLogin=$UserLogin&UserPassword=$UserPassword");
        }
        else
        {
          header('Location: registration?error_code=3'); 
        }
      }
      
    }
    ?>

    Извержение.

    Govnisti_Diavol, 04 Декабря 2012

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

    +119

    1. 1
    2. 2
    3. 3
    4. 4
    data Fuuu = Fuuu
    instance Eq Fuuu
     
    main = print $ if Fuuu == Fuuu then "I dosen't seen this" else "and this"

    Вот за что мне нравится сверх надежный высокоуровневый хаскель, так за то, что если забыл переопределить какой-то метод или оператор из класа типов (в нормальных языках это интерфейс или один из базовых класов) стандартной библиотеки языка или неподходящим образом от него отнаследовался, то мы получаем надежное поведение:
    http://ideone.com/6faPct
    результат: Ошибка выполнения время: 0.01s память: 3580 kB сигнал: -1
    ввод: нет
    вывод: нет
    stderr:
    prog: <<loop>>

    HaskellGovno, 07 Ноября 2012

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

    +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
    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
    if(!$category = $this->EE->product_model->get_category_by_key($key)){
        $this->EE->functions->redirect($this->EE->functions->create_url($this->EE->config->item('site_404')));
        exit();
    }
    // Эти 4 строчки достают все продукт которые относятся к выбранной категории. Дальше веселее .. 
    
    // Build our variable data
    				$vars[0] = array(
    									'site_id' =>  $category[0]['site_id'],
    									'category_id' => $category[0]['category_id'],
    									'category_image' => $img,
    									'category_detail' => $category[0]['detail'],
    									'parent_id' =>  $category[0]['parent_id'],
    									'category_title' =>  $category[0]['title'],
    									'url_title' =>  $category[0]['url_title'],
    									'meta_title' =>  $category[0]['meta_title'],
    									'meta_keyword' =>  $category[0]['meta_keyword'],
    									'meta_descr' =>  $category[0]['meta_descr'],
    									'total_results' => count($category[0]["products"]),
    									'results' => $category[0]["products"],
    									'no_results' => array(),
    									'result_filter_set' => '', 
                                                                            'breadcrumb_parent_categories' => $breadcrumb_parent_categories,
                                                                            'catalog_guest_flag' => $flag_catalog,
                                                                            'catalog_price_visible' => $catalog_visible
    								);
    
    // Filter the results
    if(count($category[0]["products"]) != 0)
         $vars = $this->_filter_results($vars,$key,true);
    
    // А теперь count($vars['results']) == $this->EE->config->products_per_page;
    // И самое веселое - 
    
    foreach($vars[0]['results'] as $rst){
    				$tmp = $this->_get_product($rst["product_id"]);
    				$results[] = $tmp[0];
    			}
    			$vars[0]['results'] = $results;
    
    // Функция _get_product() получает все данные о продукте: отзывы, описание, цена, куча опций. Пара строчек оттуда:
    
                         if($product_id == ''){
    				// Get product by param or dynamically
    				$product_id = $this->EE->TMPL->fetch_param('product_id');
    				$url_title = $this->EE->TMPL->fetch_param('url_title');
    				if($product_id != ''){
    					$products = $this->EE->product_model->get_products($product_id);
    				}else{
    					// get by url key
    					$key = ($url_title == '') ? $this->EE->uri->segment(2) : $url_title;
    					if(!$products = $this->EE->product_model->get_product_by_key($key)){
    						 // Not a product page
    						 return false;
    					}
    				}
    			}else{
    				if(!$products = $this->EE->product_model->get_products($product_id)){
    					return false;
    				}
    			}
    
    // Очень интересен вызов функции get_products(), эта ф-ция вызывается и для продуктов в каталоге и на странице продукта.
    // Каждый вызов тянет за собой 25 запросов в базу, если на странице 40 продуктов * 25 = 1000 запросов = ~ 20 секунд на загрузку страницы

    кусочек кода который выводит продукты в каталог, взят из eCommerce плагина BrilliantRetail для ExpressionEngine. Плагин кстати говоря стоит 150 баксов, мда )

    Archont12, 27 Октября 2012

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

    +139

    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
    public string WorkerSexWord
            {
                get
                {
                  if(WorkerSex == true)
                  {
                      return "м";
                  }
                  if(WorkerSex == false)
                  {
                      return "ж";
                  }
                    return "";
                }
            }

    "м" или "ж" выбор с булевого поля

    bercerker, 25 Октября 2012

    Комментарии (19)
  11. Куча / Говнокод #12004

    +142

    1. 1
    http://habrahabr.ru/post/155131/

    dos_, 25 Октября 2012

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