1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. Java / Говнокод #12242

    +75

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

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

    Dummy00001, 03 Декабря 2012

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

    +135

    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
    if (parameter == null)//если ведомость доков...
                    {
                        cmd.Connection = dbc;
                        cmd.CommandText =
                            "SELECT RTRIM(n.Element) + ' '+ RTRIM(e.Naim) " +
                            "FROM tb_Element e, tb_ElementName n " +
                            "WHERE n.id = e.id " +
                            "AND e.GostTU ='" + head.Text.Substring(0, head.Text.IndexOf(" ")) + "'";
                        dbc.Open();
                        naim = cmd.ExecuteScalar().ToString();
                        dbc.Close();
                        cmd.CommandText =
                        "SELECT " +
                        " LTRIM(RTRIM(s.NameProject)) " +
                        ",LTRIM(RTRIM(n.Element)) + ' '+ LTRIM(RTRIM(e.Naim)) " +
                        ",LTRIM(RTRIM(d.Obozn)) " +
                        "FROM " +
                        " tb_document d " +
                        ",tb_specificationproject s " +
                        ",tb_element e " +
                        ",tb_elementname n " +
                        "WHERE " +
                        "d.pinsp = s.pinsp " +
                        "AND e.pin = s.pinsp " +
                        "AND n.id = e.id " +
                        "AND s.NameProject IN  " +
                        "( " +
                        namelist +
                        ") " +
                        "ORDER BY d.Pinsp ";
                        dbc.Open();
                        dbr = cmd.ExecuteReader();
                        counter = 0;
                        template = File.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\doclist.xml");
                        while (template[counter].Trim() != "</Table>")
                        {
                            if (template[counter].Trim() != "<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">%name%</Data></Cell>")
                            {
                                filedata.Add(template[counter]);
                            }
                            else
                            {
                                filedata.Add("<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">" + naim + "</Data></Cell>");
                            }
                            counter++;
    
                        }
                        tail_start = counter;
                        counter = 8;
                        tmp = "";
                        while (dbr.Read())
                        {
                            if (tmp != dbr[0].ToString())
                            {
                                tmp = dbr[0].ToString();
                                //Определяю высоту строки
                                CalcHeight = " ss:Height = " + '"' + Convert.ToString(rowHeight * (1 + dbr[1].ToString().Length / 10)) + '"';
                                filedata.Add("<Row" + CalcHeight.Replace(',', '.') + ">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[1].ToString().TrimEnd() + "</Data></Cell>");
                            }
                            else
                            {
                                filedata.Add("<Row ss:Height = \"" + Convert.ToString(rowHeight).Replace(',', '.') + "\">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            }
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[2].ToString().TrimEnd() + "</Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("</Row>");
                            counter++;
                        }
                        counter = tail_start;
                        while (counter < template.GetLength(0))
                        {
                            filedata.Add(template[counter]);
                            counter++;
                        }
                    }

    Суровый промышленный код. Выгружаем в эксель данные из БД.

    Grover, 03 Декабря 2012

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

    −120

    1. 1
    Мутабелен ли 1С.Овощи.Банан?

    Коллега считает что мутабелен.

    serpinski, 03 Декабря 2012

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

    +141

    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
    <?php
    
    function createOperator($a = [])
    {
    	$IOperator = [
    		'index' => 1,
    		'iteration' => "",
    		'f' => 'print_r($a);if(++$a["index"] < $a["count"])
    				return eval($a["iteration"]);
    			else
    				return $a["result"];',
    		'run' => 'return eval',
    	];
    	if(!empty($a))
    	{
    		$IOperator['run'] = '$a = $'.$a['title'] . '; ' . $IOperator['run'] . '($a["iteration"]);';
    		$IOperator['iteration'] = '$a = array_merge($a, ' . $a['operation'] . ');' . "\n" . $IOperator['f'];
    		$IOperator = array_merge($a, $IOperator);
    	}
    	return $IOperator;
    }
    
    $fib = createOperator([
    	'first' => 1,
    	'result' => 1,
    	'count' => 5,
    	'title' => 'fib',
    	'operation' => '["first" => $a["result"], "result" => $a["first"]+$a["result"]]'
    ]);
    echo eval($fib['run']);
    
    
    $fac = createOperator([
    	'result' => 1,
    	'count' => 5,
    	'title' => 'fac',
    	'operation' => '["result" => $a["result"]*$a["index"]]',
    ]);
    echo eval($fac['run']);

    Меня потянуло сделать какую-то фигню. Встречайте, рефлексивное программирование.

    mkusher, 02 Декабря 2012

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

    +141

    1. 1
    1/-0 == 42

    Внезапно.

    serpinski, 02 Декабря 2012

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

    +121

    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
    This awesome yet simple and pragmatic PHP library performs an addition of two numbers.
    
    In early stages of Internet, developers were forced to work with poor, dry, functional, horrific languages. Everything had to be done through austere functions and operators. There was no objects. No interfaces. No dependency injection.
    
    For example, to make something as simple as an addition, our dads had to write: 1+1. Yeah, really.
    
    Hopefuly now, we have PHP 5.3 and its solid OOP implementation. SimplePHPEasyPlus lets you make this addition in a more fashionable way, using real OOP. It is fast, simple, flexible and tested. To add 1 to 1, all you have to do is:
    
    use SimplePHPEasyPlus\Number\NumberCollection;
    use SimplePHPEasyPlus\Number\SimpleNumber;
    use SimplePHPEasyPlus\Number\CollectionItemNumberProxy;
    use SimplePHPEasyPlus\Parser\SimpleNumberStringParser;
    use SimplePHPEasyPlus\Iterator\CallbackIterator;
    use SimplePHPEasyPlus\Operator\AdditionOperator;
    use SimplePHPEasyPlus\Operation\ArithmeticOperation;
    use SimplePHPEasyPlus\Operation\OperationStream;
    use SimplePHPEasyPlus\Engine;
    use SimplePHPEasyPlus\Calcul\Calcul;
    use SimplePHPEasyPlus\Calcul\CalculRunner;
    
    
    $numberCollection = new NumberCollection();
    
    $numberParser = new SimpleNumberStringParser();
    
    $firstParsedNumber = $numberParser->parse('1');
    $firstNumber = new SimpleNumber($firstParsedNumber);
    $firstNumberProxy = new CollectionItemNumberProxy($firstNumber);
    
    $numberCollection->add($firstNumberProxy);
    
    $secondParsedNumber = $numberParser->parse('1');
    $secondNumber = new SimpleNumber($secondParsedNumber);
    $secondNumberProxy = new CollectionItemNumberProxy($secondNumber);
    
    $numberCollection->add($secondNumberProxy);
    
    $addition = new AdditionOperator('SimplePHPEasyPlus\Number\SimpleNumber');
    
    $operation = new ArithmeticOperation($addition);
    
    $engine = new Engine($operation);
    
    $calcul = new Calcul($engine, $numberCollection);
    
    $runner = new CalculRunner();
    
    $runner->run($calcul);
    
    $result = $calcul->getResult();
    $numericResult = $result->getValue(); // 2
    This library is now available for production purposes. Enjoy!

    [КО]Складывает 2 числа[/КО]

    Vasiliy, 01 Декабря 2012

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