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

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

    +154

    1. 1
    var coutryOption = commonSettings.parent().parent().parent().find("tr:contains('Country')");

    очень поиск...

    fess, 29 Ноября 2014

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

    +154

    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 updateClock()
    {
        var date = new Date();
        var day = date.getDate();
        var month = date.getMonth() + 1;
        var year = date.getFullYear();
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds = date.getSeconds();
        var dateTimeString = day + "." + month + "." + year + " " + hours + ":" + minutes + ":" + seconds;
        $('#clock').html("Сейчас " + dateTimeString);
    }

    Трибьют классике.

    pushistayapodmyshka, 24 Ноября 2014

    Комментарии (45)
  4. JavaScript / Говнокод #17148

    +154

    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
    if ((new Date(2014, 0, 1)).getHours() != 0 || new Date(2015, 0, 7).getHours() != 0) {
      // Переопределяем конструктор
      Date = (function (NativeDate) {
        var NewDate = function (Y, M, D, h, m, s, ms) {
          var length = arguments.length;
          var date = length === 1 && String(Y) === Y ? // isString(Y)
              new NativeDate(NewDate.parse(Y)) :
                  length >= 7 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m, s, ms)) :
                  length >= 6 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m, s)) :
                  length >= 5 ? new NativeDate(NativeDate.UTC(Y, M, D, h, m)) :
                  length >= 4 ? new NativeDate(NativeDate.UTC(Y, M, D, h)) :
                  length >= 3 ? new NativeDate(NativeDate.UTC(Y, M, D)) :
                  length >= 2 ? new NativeDate(NativeDate.UTC(Y, M)) :
                  length >= 1 ? new NativeDate(Y) :
              new NativeDate();
          if (length == 0) {
            date = new NativeDate(+date - date.getTimezoneOffset() * 60000);
          }
          date.constructor = NewDate;
          return this instanceof NativeDate ? date : date.toString();
        };
    
        if (NativeDate.now) {
          NewDate.now = function () {
            return new NewDate().getTime();
          };
        }
        if (NativeDate.UTC) {
          NewDate._UTC = NativeDate.UTC;
          NewDate.UTC = function (Y, M, D, h, m, s, ms) {
            var _date = new NewDate(NewDate._UTC.apply(this, arguments));
            return +_date - _date.getTimezoneOffset() * 60000;
          };
        }
        NewDate.prototype = NativeDate.prototype;
        NewDate.prototype.constructor = NewDate;

    И так далее, "фикс" для кривых таймзон в JS на винде http://habrahabr.ru/post/243685/

    asavartsov, 21 Ноября 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $this->template_model = BaseCommunicationType::model()->findByAttributes(array('template' => $this->template));
    if(!$this->template_model === NULL) {
    		throw new Exception("Template name is wrong", 1);	
    }

    Угадайте, что будет из исключением?

    boddicheg, 06 Ноября 2014

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

    +154

    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
    <?php if( !empty($documents[4]) ):?>
                    <hr>
                    <h3>Выполняемые работы</h3>
                    <table class="b-transparent-table">
    
                        <?php foreach ($documents[4] as  $file_name => $text): ?>
    
                            <tr>
                                <td class ="td_big">
                                    <h6><?= $text;?></h6>
                                </td>
                                <td>
                                    <a href="<?= $dir.$passport['reforma_id'].DIRECTORY_SEPARATOR."4".DIRECTORY_SEPARATOR.$file_name;?>">скачать</a>
                                </td>
                            </tr>
    
                        <?php endforeach; ?>
                    </table>
                <?php endif;?>

    магический документ 4. В файле откуда взят код есть также документ 5.

    memclutter, 20 Октября 2014

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

    +154

    1. 1
    $_params[] = sTools::convert2cp1251(preg_replace('|\s+|', ' ', str_replace('"', '""', htmlspecialchars_decode($_param['title'])))) . ':' . sTools::convert2cp1251(preg_replace('|\s+|', ' ', str_replace('"', '""', htmlspecialchars_decode($_param['unit'])))) . '|' . implode(',', $_param['value']);

    sautchenkov, 16 Сентября 2014

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

    +154

    1. 1
    2. 2
    3. 3
    4. 4
    $a = null;
    var_dump($a, $a[0], $a); // NULL, NULL, NULL // what the fuck?
    $a[0] = null;
    var_dump($a); // array(0 => NULL)

    "PHP и type juggling", том третий. При этом на первый вызов $a[0] не ругается, будто при приведении NULL к пустому массиву в нем появляется нулевой элемент.

    Fike, 09 Сентября 2014

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

    +154

    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
    class Session {
    .....
        public function getIdUser()
        {
            if ($this->isAnonymous()) {
                return null;
            }
            return (int)$this->attributes[self::ATTR_ID_USER];
        }
    
        public function isAnonymous()
        {
            return empty($this->attributes[self::ATTR_ID_USER]);
        }
    ....
    }
    
    ............
    
     $userId = $session->isAnonymous() ? null : (int)$session->getIdUser();

    dimkich, 09 Сентября 2014

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

    +154

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    class Registration{
    	protected $data;
            protected $linc = "reg.php";
            protected $v_log;
            protected $query_login;
            protected $v_pass;
            protected $v_r_pass;
            protected $v_pass_r_pass;
            protected $v_mail;
        public function __construct() {
    		$this->data = array('login'=> NULL, 'password'=> NULL, 'r_password'=> NULL, 'mail'=> NULL);
                    foreach($this->data as $key => $val) {
                    $this->data[$key] = $_POST[$key];
    				}
                    $this->v_log = $this->ver_login($this->data['login']);
                    $this->v_pass = $this->ver_pass($this->data['password']);
                    $this->v_r_pass = $this->ver_r_pass($this->data['r_password']);
                    $this->v_pass_r_pass = $this->ver_pass_r_pass($this->data['password'],$this->data['r_password']);
                    $this->v_mail = $this->ver_mail($this->data['mail']);
                    $this->error_reporting($this->v_log,$this->v_pass,$this->v_r_pass,$this->v_pass_r_pass,$this->v_mail,  $this->error_log($this->linc));
    	}
    	    protected function error_log($linc){
                return("<p>В поле  введены неверные данные!</p></br>"
                        . "<form action='$linc' metod='get'>"
                        . "<p>Вернуться и проверить<input type = 'submit' value = 'вернуться'></p>"
                        . "</form>");
            }
            protected function ver_login($login) {
                if(empty($login) or (!preg_match("/^\A(\w){6,20}\Z/", $login))) {
                    $login = FALSE;
                    unset($login);
                }else{
                    $login == TRUE;
                    $this->ver_db($login);
                    return($login);
                }
            }
            protected function ver_db($log) {
                $q = mysql_query("SELECT id FROM users WHERE login = '$log'");
                $f = mysql_fetch_array($q);
                if(empty($f['id']) or $f['id'] == '') {
                    return($log);
                }else{
                echo('Есть такой');
                }
            }
            protected function ver_pass($pass) {
                if(empty($pass) or (!preg_match("/^\A(\w){6,20}\Z/", $pass))) {
                    $pass == FALSE;
                    unset($pass);
                }else {
                    $pass == TRUE;
                    $pass = md5($pass);
                    return($pass);
                }
            }
            protected function ver_r_pass($r_pass) {
                if(empty($r_pass) or (!preg_match("/^\A(\w){6,20}\Z/", $r_pass))) {
                    $r_pass == FALSE;
                    unset($r_pass);
                }else {
                    $r_pass == TRUE;
                    $r_pass = md5($r_pass);
                    return($r_pass);
                }
            }
            protected function ver_pass_r_pass($pass,$r_pass) {
                if($pass != $r_pass) {
                    return(FALSE);
                }else {
                    return (TRUE);
                }
            }
            protected function ver_mail($mail) {
                if(empty($mail) or (!preg_match("/^[a-zA-Z0-9_\.\-]+@([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,6}$/", $mail))) {
                    $mail == FALSE;
                    unset($mail);
                }else {
                    $mail == TRUE;
                    return($mail);
                }
            }
            protected function reg_ins($log,$pass,$mail) {
                $date = date("d.m.y");
                $const = ACCES_KEY_DEFAULT;
                $ins_query = "INSERT INTO users(login,password,mail,date,acces) VALUES ('$log','$pass','$mail','$date','$const')";
                $insert = mysql_query($ins_query);
                if(!$insert){
                        echo('error');
                    } else {
                        echo('ok');
                    }
            }
            protected function error_reporting($log,$pass,$r_pass,$pass_r_pass,$mail,$error) {
                if($log == FALSE or $pass == FALSE or $r_pass == FALSE or $pass_r_pass == FALSE or $mail == FALSE){
                    echo($error);
                } else {
                    //выполняем если все данные введены верно
                    $this->reg_ins($log, $pass, $mail);
                }

    :)

    Vampqwe, 08 Сентября 2014

    Комментарии (2)
  11. JavaScript / Говнокод #16651

    +154

    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
    // Цитата №1: массив регулярных выражений из введённых пользователем строк
    var strings = what.filter(function(e){ return e.replace(/s+/g,'').length; }).map(function(e){ var re = new RegExp(e, 'g' + (ignoreCase ? 'i' : '')); return re; });
    
    // Цитата №2: проверяется наличие введённых строк в тексте и выводит результаты
    function processText(pid, cid, text){
      if(strings.every(function(re){
        return re.test(text);
      })){
      
        // совпало
        // тут выводится информация о совпадении для поста/комментария
        // кроме вывода в консоль побочных эффектов нет
        ....
        
      }
    }
    
    // Цитата №3: запуск поиска
    posts.forEach(function(post){
      processText(post.id, null, post.author.name + ' ' + post.text);
      processText(post.id, null, post.author.name + ' ' + post.description);
      post.comments.forEach(function(comment){
        processText(post.id, comment.id, comment.author.name + ' ' + comment.text);
      });
    });

    Цитаты из скрипта поиска по ГК.
    Казалось бы, write-only питушня, работает - не трогать. Но, прочитав, http://govnokod.ru/16577#comment246821, решил поискать упоминания доктора по званию. Открываю найденный пост X, а там не все упоминания найдены. Меняю список постов, в которых искать - для X меняется список найденных комментариев.
    Откуда такая питушня? processText почти чистая, strings, posts не меняется. Может, вывод на консоль как-то влияет?

    Все волосы на жопе вырвал пока нашел в чем ошибка.
    Внимание, вопрос. В чем гавно?
    (c) ursus

    1024--, 05 Сентября 2014

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