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

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

    0

    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
    static public function countHandled()
    {
        $criteria = new CDbCriteria;
    
        $criteria->select .= ', SUM(`su`.`purchase_stage` = "in-progress") AS sum';
        $criteria->having = '`sum` > 0';
    
        $criteria->with = array(
            'siteUser' => array(
                'with' => array(
                    'interest'
                ),
                'join' => 'LEFT JOIN `site_users` AS `su` ON '
                    .'IF(LENGTH(`siteUser`.`phone`) = 11, SUBSTR(`siteUser`.`phone`, 2, 10), `siteUser`.`phone`) = '
                    .'IF(LENGTH(`su`.`phone`) = 11, SUBSTR(`su`.`phone`, 2, 10), `su`.`phone`)'
            )
        );
        $criteria->scopes = array(
            'notDone'
        );
        $criteria->compare('siteUser.purchase_stage', SiteUsers::PURCHASE_STAGE_LOST);
        $criteria->addNotInCondition('interest.reject_reason', array(
            SiteUserInterest::REJECT_REASON_TEST,
            SiteUserInterest::REJECT_REASON_SERVICE_TO
        ));
        $criteria->addCondition('`su`.`date_modified` >= DATE_SUB(NOW(), INTERVAL 2 DAY)');
    
        $criteria->group = '`t`.`site_users_return_id`';
    
        return self::model()->count($criteria);
    }
    
    static public function countCopied()
    {
        $criteria = new CDbCriteria;
    
        $criteria->select .= ', SUM(`su`.`purchase_stage` = "in-progress") AS sum';
        $criteria->having = '`sum` > 0';
    
        $criteria->with = array(
            'siteUser' => array(
                'with' => array(
                    'interest'
                ),
                'join' => 'LEFT JOIN `site_users` AS `su` ON '
                    .'IF(LENGTH(`siteUser`.`phone`) = 11, SUBSTR(`siteUser`.`phone`, 2, 10), `siteUser`.`phone`) = '
                    .'IF(LENGTH(`su`.`phone`) = 11, SUBSTR(`su`.`phone`, 2, 10), `su`.`phone`)'
            )
        );
        $criteria->scopes = array(
            'notDone'
        );
        $criteria->compare('siteUser.purchase_stage', SiteUsers::PURCHASE_STAGE_LOST);
        $criteria->addNotInCondition('interest.reject_reason', array(
            SiteUserInterest::REJECT_REASON_TEST,
            SiteUserInterest::REJECT_REASON_SERVICE_TO
        ));
        $criteria->addCondition('`su`.`date_created` >= DATE_SUB(NOW(), INTERVAL 2 DAY)');
    
        $criteria->group = '`t`.`site_users_return_id`';
    
        return self::model()->count($criteria);
    }

    - Найди мне одно отличие:
    Ответ автора:
    "- можно конешно и параметром
    - Насамом деле это два разных счета и для вычисления совпали критерии - я так это увидел
    - Можно соптимизировать, не вопрос)"

    У класса два статичных метода, в конечном итоге при условие что countHandled() ? countCopied() / countHandled() * 100 : 0
    Ладно, опустим что сам подход не очень оптимальный, но тут явно говнокод, аля контрл-ц\в,

    зы. Спешил походу, лентяй :)

    doommer, 29 Декабря 2015

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

    −2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    void TMainForm::MakeScreenPrint()
    {
    	MainForm->Print();
    }
    
    void __fastcall TMainForm::N18Click(TObject *Sender)
    {
    	MakeScreenPrint();
    }

    Обертка

    GreatMASTERcpp, 27 Декабря 2015

    Комментарии (1)
  4. C++ / Говнокод #19216

    −1

    1. 1
    #define GUIDSTR(s) __uuidof(class DECLSPEC_UUID(s) __guid_##__COUNTER__)

    Может можно покороче?

    Ccik, 22 Декабря 2015

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

    0

    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
    if( sync_ip_index < 0 && result() ) {
                QString tmp = tr(", нет синхронизации");
                addResultMessage( false, p->dev(), tmp);
                p->dev()->setState( CDiagramObject::e_Warning );
                setResult( false );
            }
            else if ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0) {
                // ( ( (sync_ip_index >= 0)  ? ( sources_from_xml.indexOf( sources_from_ntpq[ sync_ip_index ] ) < 0 ) : false ) )  {
                // (p1 ( p2               )    ( p3                      ( f1                                 )                 )
                // p1..3 - predicates
                // Check sync_ip_index >= 0 (p2)
                //  true, then
                //    find sync source ip in list filled from xml config , and if there is finded, (p3) are true, else (p3) are false, and then (p1) will be false
                //  false, then
                //    (p1) will be false
                // This construction for one string check syncronized source ip for host, if host not synchronized
                QString tmp = tr(", хост синхронизирован с источником не указанным в схеме");
                addResultMessage( false, p->dev(), tmp);
                p->dev()->setState( CDiagramObject::e_Warning );
                setResult( false );
            }

    Под конец рабочего дня уже поехала крыша, см. комментарии.

    OlegUP, 22 Декабря 2015

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    select value, value_type from b_iblock_element_property WHERE id = **;
    
    b_iblock_element_property.value: a:2:{s:4:"TYPE";s:4:"text";s:4:"TEXT";s:17:"Хорошее состояние";}
    b_iblock_element_property.value_type: text

    bitrix <3

    heyzea1, 21 Декабря 2015

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    auto id = qobject_cast<QStandardItemModel *>(ui->cbxDevice->model())
                            ->item(ui->cbxDevice->currentIndex(),
                                   RemoteDev::Constants::DEV_ID_COLUMN)
                            ->data(RemoteDev::Constants::DEV_ID_ROLE);

    Q(Styled)ItemDelegate::setModelData, достаем данные из модели комбобокса: другая колонка, кастомная роль. Жиза :(

    Elvenfighter, 20 Декабря 2015

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

    +2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $model->attributes = $_POST[$class];
    
    // костыль на ajax валидацию и отправку файлов
    $save = isset($_GET['notsave']) ? false : true;
    if ($save) {

    видимо автор кода соглашается с "хорошим" решением...

    akanit, 16 Декабря 2015

    Комментарии (1)
  9. Куча / Говнокод #19188

    0

    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
    <?xml version="1.0" encoding="utf-8"?>
    <!-- Generator: Adobe Illustrator 19.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
    <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    	 viewBox="0 0 77.1 97.7" style="enable-background:new 0 0 77.1 97.7;" xml:space="preserve">
    <style type="text/css">
    	.st0{fill:#010101;}
    	.st1{fill:#FFC627;}
    	.st2{fill:#FFD432;}
    	.st3{fill:#231F20;}
    	.st4{fill:#FFFFFF;}
    </style>
    <g>
    	<g>
    		<g>
    			<g>
    				<path class="st0" d="M6.1,71.6c-3.3,0-6.1,2.7-6.1,6.1v13.9c0,3.3,2.7,6.1,6.1,6.1h61.3c3.3,0,6.1-2.7,6.1-6.1V77.7
    					c0-3.3-2.7-6.1-6.1-6.1H6.1z"/>
    				<path class="st1" d="M67.3,73.5H6.1c-2.3,0-4.1,1.9-4.1,4.1v13.9c0,2.3,1.8,4.1,4.1,4.1h61.3c2.3,0,4.1-1.8,4.1-4.1V77.7
    					C71.5,75.4,69.6,73.5,67.3,73.5 M69.5,91.6c0,1.2-1,2.2-2.2,2.2H6.1c-1.2,0-2.2-1-2.2-2.2V77.7c0-1.2,1-2.2,2.2-2.2h61.3
    					c1.2,0,2.2,1,2.2,2.2V91.6z"/>
    				.........
    			</g>
    		</g>
    	</g>
    	<path class="st1" d="M73.4,73.4c0-1.1,0.9-1.8,1.8-1.8c1,0,1.8,0.7,1.8,1.8c0,1.1-0.9,1.8-1.8,1.8C74.3,75.2,73.4,74.5,73.4,73.4
    		 M75.3,72c-0.8,0-1.4,0.6-1.4,1.4c0,0.8,0.6,1.4,1.4,1.4c0.8,0,1.4-0.6,1.4-1.4C76.6,72.5,76,72,75.3,72 M74.9,74.4h-0.4v-2h0.8
    		c0.5,0,0.8,0.2,0.8,0.6c0,0.4-0.2,0.5-0.5,0.5l0.5,0.9h-0.4l-0.4-0.9h-0.2V74.4z M74.9,73.2h0.3c0.3,0,0.4-0.1,0.4-0.3
    		c0-0.2-0.1-0.3-0.4-0.3h-0.3V73.2z"/>
    </g>
    </svg>

    а вы когда-нибудь заглядывали в SVG?

    makc3d, 15 Декабря 2015

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

    +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
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    public static CategoryAttribute Build(string category_name, string attribute_type, string attribute_name, object attribute_value)
            {
                try
                {
                    CategoryAttribute document_attribute;
    
                    switch(attribute_type)
                    {
                        case "string":
                        case "double_as_string":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.String);
                            break;
                        case "string_as_date":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.DateTime);
                            break;
                        case "int":
                        case "double_as_int":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.Integer);
                            break;
                        case "double":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.Double);
                            break;
                        default:
                            throw new ApplicationException("Не верно настроен тип данных атрибута '" + attribute_name + "' категории '" + category_name + "'.");
                    }
    
                    if (attribute_value == null)
                        return document_attribute;// атрибут остался неопределенным
    
                  switch (document_attribute.Type)
                  {
                      case TypeEnum.String:
                            {
                                switch (attribute_type)
                                {
                                    case "string":
                                        {
                                            if (!(attribute_value is string))
                                                throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                               + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                               attribute_type + "'.");
    
                                            document_attribute.sValue = attribute_value as string;
                                        } break;
                                    case "double_as_string":
                                        {
                                            if (!(attribute_value is double))
                                                throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                               + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                               attribute_type + "'.");
    
                                            document_attribute.sValue = ((double)attribute_value).ToString();
                                        } break;
                                }
                            }
                            break;
                            case TypeEnum.Integer:
                            {
                                switch (attribute_type)
                                {
                                    case "int":
                                    {
                                        if (!(attribute_value is int))
                                            throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                           + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                           attribute_type + "'.");
    
                                        document_attribute.iValue = (int)attribute_value;
                                    }   break;
                                    case "double_as_int":
                                    {
                                        if (!(attribute_value is double))
                                            throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                           + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                           attribute_type + "'.");
    
                                        document_attribute.iValue = (int)(double)attribute_value;
                                    }   break;
                                }
                            }
                            break;
                          case TypeEnum.Double:
                            {
                                if (!(attribute_value is float || attribute_value is double || attribute_value is int || attribute_value is long))
                                    throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                        + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" + attribute_type + "'.");
    
                                document_attribute.dValue = (double)attribute_value;
                            }
                            break;
                    }
    
                    return document_attribute;
    
                    catch (Exception e)
                       {
                         //...
                       }
                  }

    Создание объекта типа CategoryAttribute.

    algore, 15 Декабря 2015

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $(".tabs_nav-item").click ->
        if($(this).hasClass("_active")) 
        else 
          $this = $(this)
          target = $(this).attr("href")
          $this.addClass("_active").siblings("._active").removeClass("_active")
          $(target).addClass("_active").siblings("._active").removeClass("_active")

    LOL
    P.S. coffeescript

    Crazyzubr, 03 Декабря 2015

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