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

    +160

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    for(var i = 0, l = requestParams.length; i < l; i++) {
        var param_pair = requestParams[i];
    
        key = encodeURIComponent(param_pair[0]);
        val = param_pair[1];
        if ( val && val.constructor.toString().match(/array/i) ) {
            val = val.join('+');
        }
        // ...
    }

    Кусочек велосипеда, который заменяет функционал jQuery.ajax

    Если вдруг наш параметр оказался массивом ... ну что ж еще с ним сделать кроме как соединить через "+". Обратите внимание на саму проверку.

    Elvenfighter, 05 Декабря 2012

    Комментарии (128)
  2. PHP / Говнокод #12250

    +142

    1. 1
    $model->date = date('Y-m-d H:i:s',mktime(date('H'),date('i'),date('s'),date('m'),date('d'),date('Y')));

    берём текущую дату...

    blackray, 05 Декабря 2012

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

    +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
    $sw = false;
    if($valid_from && $valid_to)
    	if( ($valid_from<=date('U')) && ($valid_to>=mktime(0,0,0,date('m'),date('d'),date('Y'))) )
    		$sw = true;
    	else
    		{
    			//Nimic
    		}
    elseif($valid_form)
    	if($valid_form<=date('U'))
    		$sw = true;
    	else
    		{
    			//Nimic
    		}
    elseif($valid_to)
    	if($valid_to>=mktime(0,0,0,date('m'),date('d'),date('Y')))
    		$sw = true;
    	else
    		{
    			//Nimic
    		}
    else
    	$sw = true;

    Edd, 04 Декабря 2012

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

    −105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (resetPasswordAlert != nil)
    {
        resetPasswordAlert = nil, [resetPasswordAlert release];
    }
    [resetPasswordAlert release];
    resetPasswordAlert = [[ResetPasswordAlert alloc] init];

    Memory management по-белорусски...

    ZaR, 04 Декабря 2012

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

    +109

    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
    string New_naim = E.Remove(0, (NameGR(E.Trim()).Length)).Trim() + " " + Na;
                                    New_naim = New_naim.Trim();
                                    string check_naim =
                                        (E+Na).ToUpper().Replace(" ", "").Replace(",", ".").Replace("-", "").Replace("Е", "E")
                                        .Replace(";", "").Replace("*", "").Replace("Х", "X").Replace("О", "O").Replace("А", "A")
                                        .Replace("В", "B").Replace("М", "M").Replace("Н", "H").Replace("С", "C").Replace("Т", "T").Replace("З", "3")
                                        .Replace("Р", "P").Replace("Q", "G").Replace("К", "K").Replace("О", "O").Replace("0", "O").Replace("%", "").Replace("И", "U");
                                    string check_gosttu = GU.ToUpper().Replace(" ", "").Replace(",", ".").Replace("Е", "E").Replace(".", "")
                                        .Replace("З", "3").Replace(";", "").Replace("*", "").Replace("Х", "X").Replace("О", "O").Replace("А", "A")
                                        .Replace("И", "U").Replace("В", "B").Replace("М", "M").Replace("Н", "H").Replace("С", "C").Replace("Т", "T").Replace("-", "")
                                        .Replace("Р", "P").Replace("Q", "G").Replace("К", "K").Replace("О", "O").Replace("0", "O").Replace("+", "");
                                    /*quer = "SELECT PIN From dbo.Tb_Element Where (Id = '" + Id_el + "') AND "+
                                        "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(GOSTTU)" +
                                        ",' ',''),',','.') ,'Е','E'),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'.','') = '"+ check_gosttu+   
                                        "' AND replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(naim)" +
                                        ",' ',''),',','.') ,'Е','E'),'-',''),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O') = '" + check_naim + "'";*/
                                    quer = "SELECT e.PIN From dbo.Tb_Element e, dbo.tb_elementname n Where e.id = n.id AND "+
                                        "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(GOSTTU)" +
                                        ",' ',''),',','.') ,'Е','E'),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'.',''),'И','U'),'З','3'),'+',''),'-','') = '" + check_gosttu +
                                        "' AND replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(LTRIM(RTRIM(n.element))+RTRIM(LTRIM(e.naim)))" +
                                        ",' ',''),',','.') ,'Е','E'),'-',''),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'%',''),'З','3'),'И','U') = '" + check_naim + "'";

    Читаю старый код и радуюсь, что больше с ним не работаю. Правим результаты кривых рук операторов, заводящих данные.

    Grover, 04 Декабря 2012

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

    +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
    function StringForCountryInt($countryInt)
    	{
    		switch ($countryInt)
    		{
    			case "1" : return 'Afghanistan'; break;
                case "2" : return 'Albania'; break;
                case "3" : return 'Algeria'; break;
                case "4" : return 'American Samoa'; break;
                case "5" : return 'Andorra'; break;
                case "6" : return 'Angola'; break;
                case "7" : return 'Anguilla'; break;
                case "8" : return 'Antarctica'; break;
    //          ....
    //          ....
    //          ....
                 case "239" : return 'Zimbabwe'; break;
    		}
    	}

    MODx, evolution. Сниппет WebLoginPE.
    В базе сохраняет ID страну, в классе вот такой метод для обратного преобразования :)

    MaXL, 04 Декабря 2012

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

    +1

    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
    #include "stdafx.h"
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    class radian
    {protected:
        double x;
        public:
        radian();//конструктор без параметров, возвращает дежурное значение
        radian(double x1);//конструктор с параметрами
        radian sum_rad(radian a );
        radian unsum_rad(radian a);//разность 2-х радиан
        double get_r(){return x;}//нужный геттр
        void set_r(double x1);//бесполезный сеттрер
        double radian::quarter(radian a);//определение четверти угла заданного в радианах
        double operator *();//перегрузка операции. возводит во вторую степень
        double radian::rad_to_grad();//перевод из радиан в градусы
        ~radian();//деструкторуу
    };
    class namerad:public radian
    {
        private:
        string name;
        public:
        namerad::namerad(double corner,string name)
        {set_name(name);}
        void namerad::set_name(string newname)
        {name=newname;}
        void namerad::get_name(string currentname)
        {currentname=name;}
    };
    radian::radian()//конструктор по умолчанию
    {
        x=0;
    }
    radian::radian(double x1)//конструктор с 1 параметром
    {
        x=x1;
    }
    radian radian::sum_rad(radian a)//сумма 2-х радиан
    {radian n(x+a.x);
        return n;
    }
    void radian::set_r( double x1)//сеттер
    { x=x1;}
    radian::~radian() {x=0;}//деструктор
    radian radian::unsum_rad(radian a)//разность 2-х радиан
    {radian n(x-a.x);
        return n;
    }
    double radian::rad_to_grad() //перевод из радиан в градусы
    {
        return(x*(180/3.14));
    }
    double radian ::operator *()//перегрузка операции
    {
        return x*x;
    }
    double radian::quarter(radian a)//определение четверти угла заданного в радианах
    {while(a.x>6.28){a.x-=6.28;}
            if ((a.x >=0)&&(a.x<=1.57)) return 1;
            if ((a.x>=1.57)&&(a.x<=3.14)) return 2;
            if ((a.x>=3.14)&&(a.x<=4.71)) return 3;
            return 4;
        }
        int main()
        {
            radian a,b,c(5.0),d(6.20);
            cout<<"summa=";b=c.sum_rad(d);cout<<b.get_r() << endl;//сумма
            cout<<"raznost=";b=d.unsum_rad(c);cout<<b.get_r() << endl; //разность
            cout<<"chetvert: ";cout<< d.quarter(d) << endl;//четверть
            cout<<"iz radian v gradusi: ";cout<<d.rad_to_grad() << endl;//перевод из радиан в градусы
            cout<<"peregruz sqr "<<*c;//возведение в квадрат. перегруженная операция
            system ("PAUSE");
            return 0;
        }

    vovkalamer, 03 Декабря 2012

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

    +12

    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
    #include <iostream>
    #include <functional>
     
    using namespace std;
     
    struct  T
    {
        int a;
        T(const T&):a(1){cout<<"copy_construct T"<<endl;}
        T():a(1){cout<<"construct T"<<endl;}
        ~T(){a=0;cout<<"destruct T"<<endl;}
        const T& operator=(const T&){cout<<"copy_ass T"<<endl;return *this;}    
    };
     
    struct M: public T{};
     
    void f(const T& fa)
    {
        cout<<"fa.a= "<<fa.a<<endl;    
    }
     
    int main() {
        f(std::cref(T()));
        cout<<endl;
        const T& b = T();
        cout<<"b.a= "<<b.a<<endl;
        cout<<endl;
        const T& a = std::cref(T());
        cout<<"a.a= "<<a.a<<endl;
        return 0;
    }

    http://ideone.com/BmHo9w
    Есть на этом ресурсе великий знаватель крестов и вот он меня уверял, что объект, на который ссылается ссылка - должен дожить до конца выхода ссылки из скоупа. Почему мы этого не наблюдаем? А знаватель? Ты меня прямо даже убедил, и тут такая подстава от тебя. a - не дожил до конца.

    LispGovno, 03 Декабря 2012

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

    +75

    1. 1
    Long value = Long.valueOf(String.valueOf(avpValue));

    не специалист по жабе, но пахнет: сначала по всему коду нагородить огородов с Byte/Short/Integer/Long что бы потом в самом важном месте вот так в лоб все в Long конвертить...

    Dummy00001, 03 Декабря 2012

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