1. JavaScript / Говнокод #12298

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    findTariffPlans = function(setValue) {findTariffPlans(setValue, null)};
    
    findTariffPlans = function(setValue, closure) {
       // bla-bla-bla
    }

    "Я перегрузил"

    madhead, 16 Декабря 2012

    Комментарии (6)
  2. SQL / Говнокод #12297

    −163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    SELECT news_tbl.*, users_tbl.*,
    GROUP_CONCAT(comments_tbl.comments_id) AS commentsid,
    GROUP_CONCAT(CONCAT ('<hr><h6>Navn: ', comments_tbl.name,'</h6>','<p>',comments_tbl.comment, '</p>') SEPARATOR '<br><br>') AS comments, 
    COUNT(comments_tbl.comments_id) AS comments_count
    FROM news_tbl
    LEFT JOIN comments_tbl ON comments_tbl.news_id = news_tbl.news_id
    LEFT JOIN users_tbl ON news_tbl.user = users_tbl.username
    GROUP BY news_tbl.news_id
    ORDER BY news_tbl.news_id DESC LIMIT 5

    Наткнулся на SO.

    Lowezar, 15 Декабря 2012

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

    +55

    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
    function _bool($var){
      if(is_bool($var)){
        return $var;
      } else if($var === NULL || $var === 'NULL' || $var === 'null'){
        return false;
      } else if(is_string($var)){
        $var = trim($var);
        if($var=='false'){ return false;
        } else if($var=='true'){ return true;
        } else if($var=='no'){ return false;
        } else if($var=='yes'){ return true;
        } else if($var=='off'){ return false;
        } else if($var=='on'){ return true;
        } else if($var==''){ return false;
        } else if(ctype_digit($var)){
          if((int) $var)
            return true;
            else
            return false;
        } else { return true; }
      } else if(ctype_digit((string) $var)){
          if((int) $var)
            return true;
            else
            return false;
      } else if(is_array($var)){
        if(count($var))
          return true;
          else
          return false;
      } else if(is_object($var)){
        return true;// No reason to (bool) an object, we assume OK for crazy logic
      } else {
        return true;// Whatever came though must be something,  OK for crazy logic
      }
    }

    Я, конечно, понимаю, не во всех школах учат использованию массивов...

    RaZeR, 15 Декабря 2012

    Комментарии (6)
  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 / Говнокод #12293

    +43

    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
    <?php
    session_start();
    if(empty($_SESSION['UserLogin']) or empty($_SESSION['UserId']))
    {
      header('Location: /');
    }
    else
    {
      if($_GET['mess_id'] == "")
      { 
         header('Location: /'); 
      }
      else
      {
        include("application/db.config.php");
        $GetUserIdQuery = mysql_query("SELECT id FROM Users WHERE id=".$_SESSION['UserId'], $db);
        $UserIdArr = mysql_fetch_array($GetUserIdQuery);
        
        $GetMessInfoQuery = mysql_query("SELECT * FROM Messages WHERE DialogId=".$_GET['mess_id'], $db);
        $MessageInfoArr = mysql_fetch_array($GetMessInfoQuery);
        if($UserIdArr['id'] != $MessageInfoArr['UserTo'])
        {
          header('Location: /');  
        }
        else
        {
            mysql_close($db);  
           ......................................................... и так далее...
        }
      } 
    }

    В довесок к этому(http://govnokod.ru/12268), БЛ*АТЬ!

    Govnisti_Diavol, 14 Декабря 2012

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

    −113

    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
    -(void) reloadHelpMessage:(BOOL) _isPortrait
    {
        //ignoreDisappear = NO;
        //ingnoreWillAppear  = NO;
        if (_isPortrait)
        {
            helpMessage.frame = CGRectMake(helpMessage.frame.origin.x, helpMessage.frame.origin.y, self.view.bounds.size.width, 175);
            for (UIView* sub in [helpMessage subviews])
            {
                NSLog(@"__%@",[sub description]);
                switch (sub.tag) 
                {
                    case 1:
                        sub.frame = CGRectMake(68, 17, 200, 18);
                        break;
                    case 2:   
                        sub.frame = CGRectMake(68, 40, self.view.bounds.size.width - 70, 80);
                        break;
                    case 3:
                        sub.frame = CGRectMake(267, 3, 35, 29);
                        break;
                    case 4:
                        sub.frame = CGRectMake(10, 8, 48, 53);
                        break;
                    case 5:
                        sub.frame = CGRectMake(11, 128, roundf((self.view.bounds.size.width - 32)/2), 36);
                        break;
                    case 6:
                        sub.frame = CGRectMake(roundf((self.view.bounds.size.width/2) + 5), 128, roundf((self.view.bounds.size.width - 32)/2), 36);
                        break;
                   
                    default:
                        break;
                }   
            }
        }
        else
        {
            helpMessage.frame = CGRectMake(helpMessage.frame.origin.x, helpMessage.frame.origin.y, self.view.frame.size.width, 138);
            for (UIView* sub in [helpMessage subviews])
            {
                NSLog(@"__%@",[sub description]);
                switch (sub.tag) 
                {
                    case 1:
                        sub.frame = CGRectMake(68, 17, 200, 18);
                        break;
                    case 2:   
                        sub.frame = CGRectMake(68, 40, self.view.bounds.size.width - 80, 40);
                        break;
                    case 3:
                        sub.frame = CGRectMake(400, 3, 35, 29);
                        break;
                    case 4:
                        sub.frame = CGRectMake(10, 8, 48, 53);
                        break;
                    case 5:
                        sub.frame = CGRectMake(11, 91, roundf((self.view.bounds.size.width - 32)/2), 36);
                        break;
                    case 6:
                        sub.frame = CGRectMake(roundf((self.view.bounds.size.width/2) + 5), 91, roundf((self.view.bounds.size.width - 32)/2), 36);
                        break;
                    default:
                        break;
                }   
            }
        }
    }

    QuickNick, 14 Декабря 2012

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

    +41

    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
    # POST /register
    Public Function Register(){
        foreach((array)$_POST as $k=>$v)
            $_POST[$k] = addslashes(strip_tags($v));
        $login = $_POST['Login'];
        $password = $_POST['Password'];
        $email = $_POST['Email'];
        $firstname = $_POST['FirstName'];
        $lastname = $_POST['LastName'];
        $errors = array();
    
        IF(!Session::Restore()){
            Driver::Init();
            IF(String::is_valid_email_address($email)){
                IF(strlen($login) > 3 && strlen($login) <= 12 && String::Check('([a-zA-Z0-9_]+)', $login) ){
                    IF(strlen($password) > 5 && $password == $_POST['RePassword']){
                        $users = Collection::Get('users')->Select(Query::Equal('login', $login));
                        IF(!sizeof($users)){
                            $user = new User;
                            $user->login = strtolower($login);
                            $user->password = md5($password);
                            $user->regtime = time();
                            $photo = UploadedFiles::Get('Photo');
                            IF($photo)
                                IF($photo->exists){
                                    $photoHash = md5('photo_'.$user->login);
                                    $photosPath = APPLICATION_DIR.'/assets/uploads/photos';
                                    $photo->Path = $photosPath.'/tmp/'.$photoHash;
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/300/'.$photoHash.'.jpg', 100, 300, 500);
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/100/'.$photoHash.'.jpg', 100, 100);
                                    ImageProcessing::MakeThumb($photo->Path, $photosPath.'/50/'.$photoHash.'.jpg', 100, 50);
                                    @unlink($photo->Path);
                                    $user->photo = $photoHash;
                                }
                            $user->save();
                            Session::Link($login, $password);
                            return Router::Redirect('/profile');
                        }
                        else $errors[] = l('This username is already taken');
                    }
                    else $errors[] = l('Password length must be more than 3');
                }
                else $errors[] = l('Login length must be more than 3, and less than 13 characters and contain only Latin characters');
            }
            else $errors[] = l('Your email address must be in the format of [email protected]');
        }
        else $errors[] = l("You are already registered");
        $view = new View('main.php');
        return $view->Set('Content', 'registration.php')->Set('login', $login)->Set('email', $email)->Set('firstname', $firstname)->Set('lastname', $lastname)->Set('errors', $errors);
    }

    Ну так.

    d3n4, 14 Декабря 2012

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

    +57

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // Просто удаляет элемент из массива
      function delElement($arr, $index)
      {
        $result = Array();
        for($i=0;$i<count($arr);$i++)
          if($index != $i) $result[] = $arr[$i];
        
        return $result;
      }

    - Ваше мнение, коллега?
    - Кал молодой особи пыхаписта, коллега. Очень ярко выражены типичные признаки.

    clauclauclau, 14 Декабря 2012

    Комментарии (26)
  9. JavaScript / Говнокод #12287

    +161

    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
    function setOptionText(the_select1, the_array1, the_select2, the_array2)
    {
        the_select1.options.length=the_array1.length;
        for (loop=0; loop < the_array1.length; loop++)
        {
            the_select1.options[loop].text = the_array1[loop];
            the_select1.options[loop].value = the_array1[loop];
            if (loop==0){
                the_select1.options[loop].selected=true;
            }    
        }
    
        the_select2.options.length=the_array2.length;
        for (loop=0; loop < the_array2.length; loop++)
        {
            the_select2.options[loop].text = the_array2[loop];
            the_select2.options[loop].value = the_array2[loop];
            if (loop==0){
                the_select2.options[loop].selected=true;
            }
        }
    }

    Моему предшественнику, видимо, было лень вызывать два раза одну и ту же функцию, и потому он добавил в неё ещё два параметра и ещё девять строк кода.

    wissenstein, 14 Декабря 2012

    Комментарии (2)
  10. Java / Говнокод #12286

    +83

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    try{
        name.toLowerCase();
      }catch (NullPointerException e) {
       report().error("java.lang.NullPointerException", e);
       name = "";
      }

    Перспективная проверка на null

    nafania217518, 13 Декабря 2012

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