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

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

    +148

    1. 1
    2. 2
    //G++ now allows typename in a template template parameter.
        template<template<typename> typename X> struct D; // xzibit.jpeg

    Пятый gcc вышел. Больше крестоблядства за те же деньги.
    https://gcc.gnu.org/gcc-5/changes.html

    3.14159265, 02 Мая 2015

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

    +132

    1. 1
    2. 2
    $result = mysql_query("INSERT INTO `selled` (`user`, `ip`, `date`, `name`, `mail`, `company`, `phone`, `phone2`, `sum`, `country`, `state`, `town`, `indexcountry`, `allcountry`, `payment`, `dost`) VALUES 
    	('".mysql_real_escape_string($_COOKIE['user'])."', '$_SERVER[REMOTE_ADDR]', NOW(), '".mysql_real_escape_string($_POST['name'])."', '".mysql_real_escape_string($_POST['mail'])."', '".mysql_real_escape_string($_POST['company'])."', '".mysql_real_escape_string($_POST['phone'])."', '".mysql_real_escape_string($_POST['phone2'])."', '".mysql_real_escape_string($_GET['sum'])."', '".mysql_real_escape_string($_POST['country'])."', '".mysql_real_escape_string($_POST['state'])."', '".mysql_real_escape_string($_POST['town'])."', '".mysql_real_escape_string($_POST['indexcountry'])."', '".mysql_real_escape_string($_POST['allcountry'])."', '".mysql_real_escape_string($_POST['paymethod'])."', '".mysql_real_escape_string($_POST['dost'])."')");

    Добавление товара

    ponchic, 30 Апреля 2015

    Комментарии (2)
  4. Куча / Говнокод #18054

    +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
    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
    func (db *DB) CountResults(filial []int64, device []int64, workplace []int64, from time.Time, to time.Time, splits bool, skip int64) (res []*AvgResults, err error) {
    
    	var query string
    	var rows *pgx.Rows
    
    	_, err = db.Exec("SET LOCAL TIME ZONE 'Asia/Yekaterinburg';")
    	if err != nil {
    		return nil, err
    	}
    
    	switch {
    	case splits:
    		query = `WITH data AS (SELECT "IndicatorResultValue"."IndicatorId", "qm"."Session"."Blocked", "qm"."Result"."SessionId" AS "SessionId", "qm"."DeviceIPRangeType"."Number" AS "RangeType", "qm"."DeviceIPRangeType"."Id" AS "RangeTypeId", "qm"."BranchWorkPlace"."Id" AS "WorkPlaceId", "DeviceIPRange"."BranchId", date("Datetime") as "Date"
      			FROM qm."Result"
      			LEFT OUTER JOIN "qm"."Device" ON ("Result"."DeviceId" = "Device"."Id")
      			LEFT OUTER JOIN "qm"."BranchWorkPlace" ON ("BranchWorkPlace"."Id" = "Device"."WorkPlaceId")
      			LEFT OUTER JOIN "qm"."Session" ON ("Result"."SessionId" = "Session"."Id")
      			LEFT OUTER JOIN "qm"."IndicatorResultValue" ON ("Result"."IndicatorResultValueId" = "IndicatorResultValue"."Id")
      			LEFT OUTER JOIN "qm"."ResultValue" ON ("IndicatorResultValue"."ResultValueId" = "ResultValue"."Id")
      			LEFT OUTER JOIN "qm"."DeviceIPRangeType" ON ("DeviceIPRangeType"."Id" = "Session"."DeviceIPRangeTypeId")
      			LEFT OUTER JOIN "qm"."DeviceIPRange" ON ("Session"."DeviceIPRangeId" = "DeviceIPRange"."Id") 	
      			FULL OUTER JOIN "queue"."Branches" ON ("DeviceIPRange"."BranchId" = "Branches"."Id" AND (0 = any ($1::int8[]) OR "Branches"."Id" = any($1::int8[])))),
    			data1 AS (SELECT COUNT(DISTINCT(data."SessionId")) AS "Count", 
    	 		"BranchId", 
    	  		CASE WHEN "RangeTypeId" < 3 THEN 0
                	ELSE "RangeTypeId"
    	  		END,  
    	  		"Date"
    	  		FROM data
    	  		WHERE (0 = any($2::int8[]) OR "RangeType" = any($2::int8[]))
    	   		AND (0 = any ($1::int8[]) OR "BranchId" = any($1::int8[]))
    	   		AND (0 = any($3::int8[]) OR "WorkPlaceId" = any($3::int8[]))
    	   		AND "Date" BETWEEN $4::timestamptz AND $5::timestamptz
    	   		AND NOT "Blocked"
    	  		GROUP BY "BranchId", CASE WHEN "RangeTypeId" < 3 THEN 0 ELSE "RangeTypeId" END, "Date"),  
    			data2 AS (SELECT "Id", "Name", date("d") AS "Date" FROM
    			queue."Branches"
    			CROSS JOIN generate_series($4::timestamptz, $5::timestamptz, $6) as "d" 
    			WHERE (0 = any ($1::int8[]) OR "Id" = any($1::int8[])) ),	            
    			data3 AS (SELECT "Count" AS C, 0 AS Avg, data1."Date", data1."RangeTypeId", data1."BranchId"
    			FROM "data1" GROUP BY "data1"."Date", "Count", "data1"."BranchId", "data1"."RangeTypeId"),
    			data3_1 AS (SELECT "qm"."DeviceIPRangeType"."Id" FROM "qm"."DeviceIPRange"
    			RIGHT OUTER JOIN "qm"."DeviceIPRangeType" ON ("qm"."DeviceIPRange"."DeviceIPTypeId" = "qm"."DeviceIPRangeType"."Id")
    			WHERE (0 = any ($1::int8[]) OR "DeviceIPRange"."BranchId" = any($1::int8[]))
    			GROUP BY "qm"."DeviceIPRangeType"."Id"),
    			data4 AS (SELECT "Id", "Name", date("d") AS "Date" FROM
    			"qm"."DeviceIPRangeType"
    			CROSS JOIN generate_series($4::timestamptz, $5::timestamptz, $6) as "d"
    			WHERE "Id" > 2 AND (0 = any($2::int8[]) OR "Number" = any($2::int8[])) AND "Id" IN (SELECT "Id" FROM data3_1)),
    			data5 AS (SELECT coalesce(c, 0) AS C, coalesce(avg, 0) AS Avg, coalesce("data2"."Date", "data3"."Date") AS date, "data2"."Name", "data3"."RangeTypeId" FROM
    			data2
    			FULL OUTER JOIN data3 ON ("data3"."BranchId" = "data2"."Id" AND "data3"."Date" = "data2"."Date"))
    			SELECT array_agg(coalesce(c, 0) ORDER BY coalesce("data5"."date", "data4"."Date")) AS "Count",
           		array_agg(coalesce(avg::double precision, 0::double precision) ORDER BY coalesce("data5"."date", "data4"."Date")) AS "Avg",
           		array_agg(coalesce("data5"."date", "data4"."Date") ORDER BY coalesce("data5"."date", "data4"."Date"))::timestamptz[] AS "Date",
           		coalesce("data5"."Name", "data4"."Name") AS "Name" FROM data5
    			FULL OUTER JOIN data4 ON ("data4"."Id" = "data5"."RangeTypeId" AND "data5"."date" = "data4"."Date")
    			WHERE coalesce("data5"."Name", "data4"."Name") IS NOT NULL
    			GROUP BY coalesce("data5"."Name", "data4"."Name")
    			ORDER BY coalesce("data5"."Name", "data4"."Name")`
    	default:
    		query = `WITH data AS (SELECT "IndicatorResultValue"."IndicatorId", "qm"."Session"."Blocked", "qm"."Result"."SessionId" AS "SessionId", "qm"."DeviceIPRangeType"."Number" AS "RangeType", "qm"."DeviceIPRangeType"."Id" AS "RangeTypeId", "qm"."BranchWorkPlace"."Id" AS "WorkPlaceId", "DeviceIPRange"."BranchId", date("Datetime") as "Date"
    	 		FROM qm."Result"
    	 		LEFT OUTER JOIN "qm"."Device" ON ("Result"."DeviceId" = "Device"."Id")
    	 		LEFT OUTER JOIN "qm"."BranchWorkPlace" ON ("BranchWorkPlace"."Id" = "Device"."WorkPlaceId")
    	 		LEFT OUTER JOIN "qm"."Session" ON ("Result"."SessionId" = "Session"."Id")
    	 		LEFT OUTER JOIN "qm"."IndicatorResultValue" ON ("Result"."IndicatorResultValueId" = "IndicatorResultValue"."Id")
    	 		...

    Код для БД на go

    g2347933, 24 Апреля 2015

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

    +142

    1. 1
    2. 2
    3. 3
    function getPLpgSqlUpdateTimestampFuncTpl() {
    //
    }

    а не сильно ли информативно?

    artembegood, 23 Апреля 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    //Один протокол хранится в базе в виде трех записей для каждого из типов экзаменов
    //Чтобы 3 записи превратить в одну подменяем ключ из массива запроса ($result) на id заявки ($request_id)
    //Записи с одинаковыми id перезаписываются, а запись с датой и счетом попадают в нужную колонку
    foreach($this->type as $type)
    {
              $csv_array[$request_id]['Дата начала, '.$type] = $csv_array[$request_id]['Дата начала, '.$type];
              $csv_array[$request_id]['Решение, '.$type] = $csv_array[$request_id]['Решение, '.$type];
              $csv_array[$request_id]['Счет, '.$type] = $csv_array[$request_id]['Счет, '.$type];
    }

    магия

    d1ma, 22 Апреля 2015

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

    +142

    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
    function ValidateSignupData()
    {
        var username = $('#signup-name').val();
        var password = $('#signup-password').val();
        var password_confirm = $('#signup-password-confirmation').val();
        var email = $('#signup-email').val();
        var type_payment = $('#signup-payment').val();
        var card_numb = $('#signup-numb').val();
    
        if(username.length()>0) {
            if(password.length()>0) {
                if(password_confirm.length()>0) {
                    if (password == password_confirm) {
                        if(card_numb.length()>0 && card_numb.length()<14) {
                        }
                        else {
                            $('#message-signup').text('Поле "Номер карты" слишком короткое');
                        }
                    }
                    else {
                        $('#message-signup').text('Пароли не совпадают');
                    }
                }
                else
                {
                    $('#message-signup').text('Поле "Подтверждение пароля" не заполнено');
                }
        }
        else 
            {
            $('#message-signup').text('Поле "Пароль" не заполнено');
        }
        }
        else {
            $('#message-signup').text('Поле "Имя" не заполнено');
        }
    }

    Простейшая валидация формы.

    qstd, 21 Апреля 2015

    Комментарии (2)
  8. Objective C / Говнокод #18012

    −411

    1. 1
    2. 2
    NSDate *dateFromString = [[NSDate alloc] init];
    dateFromString = [dateFormatter dateFromString:cell.textFieldCell.text];

    Когда человек не знает, что делает

    ep_fl, 17 Апреля 2015

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

    +839

    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
    protected virtual string GetParentTableControlID()
            {
                try
                {
                    if (this.Parent is BaseApplicationTableControl) return this.Parent.ID;
                    if (this.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.Parent.ID;
                }
                catch (Exception)
                {
                }
                return "";
            }

    greyb, 03 Апреля 2015

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

    +166

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    try {
        $('#field_9').mask('+7 (999) 999-99-99');
    } catch (e) {
        $('#field_9').mask('+7 (999) 999-99-99');
    }

    Не получилось с первого раза? Получится со второго!

    jbot, 26 Марта 2015

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

    +162

    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
    if(isset($_POST['submit']) AND $_POST['submit'] == 'add_program')
          {
             if($this->form_validation->run('add_program') == TRUE)
             {
                // Добавляем программу обучения
                $this->Settings_model->add_program($_POST['title']);
                $id = $this->db->insert_id();
                for ($x = 0; $x < 61; $x++)
                {
                   if ($x <= 12) 
                   {
                      $title = $x;
                      $year = 1;
                   }
                   elseif ($x > 12 AND $x <= 24) 
                   {
                      if($x == 13) {$title = 1;}
                      if($x == 14) {$title = 2;}
                      if($x == 15) {$title = 3;}
                      if($x == 16) {$title = 4;}
                      if($x == 17) {$title = 5;}
                      if($x == 18) {$title = 6;}
                      if($x == 19) {$title = 7;}
                      if($x == 20) {$title = 8;}
                      if($x == 21) {$title = 9;}
                      if($x == 22) {$title = 10;}
                      if($x == 23) {$title = 11;}
                      if($x == 24) {$title = 12;}
                      $year = 2;
                   }
                   elseif ($x > 24 AND $x <= 36) 
                   {
                      if($x == 25) {$title = 1;}
                      if($x == 26) {$title = 2;}
                      if($x == 27) {$title = 3;}
                      if($x == 28) {$title = 4;}
                      if($x == 29) {$title = 5;}
                      if($x == 30) {$title = 6;}
                      if($x == 31) {$title = 7;}
                      if($x == 32) {$title = 8;}
                      if($x == 33) {$title = 9;}
                      if($x == 34) {$title = 10;}
                      if($x == 35) {$title = 11;}
                      if($x == 36) {$title = 12;}
                      $year = 3;
                   }
                   elseif ($x > 36 AND $x <= 48) 
                   {
                      if($x == 37) {$title = 1;}
                      if($x == 38) {$title = 2;}
                      if($x == 39) {$title = 3;}
                      if($x == 40) {$title = 4;}
                      if($x == 41) {$title = 5;}
                      if($x == 42) {$title = 6;}
                      if($x == 43) {$title = 7;}
                      if($x == 44) {$title = 8;}
                      if($x == 45) {$title = 9;}
                      if($x == 46) {$title = 10;}
                      if($x == 47) {$title = 11;}
                      if($x == 48) {$title = 12;}
                      $year = 4;
                   }
                   else
                   {
                      if($x == 49) {$title = 1;}
                      if($x == 50) {$title = 2;}
                      if($x == 51) {$title = 3;}
                      if($x == 52) {$title = 4;}
                      if($x == 53) {$title = 5;}
                      if($x == 54) {$title = 6;}
                      if($x == 55) {$title = 7;}
                      if($x == 56) {$title = 8;}
                      if($x == 57) {$title = 9;}
                      if($x == 58) {$title = 10;}
                      if($x == 59) {$title = 11;}
                      if($x == 60) {$title = 12;}
                      $year = 5;
                   }
                   
                   if($x != 0)
                   {
                      // Добавляем месяцы обучения
                      $this->Settings_model->add_tutorial_months($id,$year,$title);
                   }
                }

    Тяжело супортить чейто проект

    Zilot, 23 Марта 2015

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