1. Список говнокодов пользователя dgkj

    Всего: 9

  2. Ruby / Говнокод #22053

    −98

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $i = 1
    resultsArray.each do |results|
      results.rank = $i
      $i += 1
    end

    +овер9к прочих глобальных переменных и проскакивающие ; в конце строк. Привет, похапе.

    dgkj, 27 Января 2017

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

    −51

    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
    $scope.advert = {
      weekDays : [1]
    };
    $scope.featuredDays = [0, 3, 7, 14];
    $scope.days = [];
    for (var i = 0; i < 31; i++) {
      var day = i + 1;
      if (day < 10) {
        day = "0" + day;
      }
      $scope.days.push(day);
    }
    
    $scope.monthes = [
      {name:"January", value: 0},
      {name:"February", value: 1},
      {name:"March", value: 2},
      {name:"April", value: 3},
      {name:"May", value: 4},
      {name:"June", value: 5},
      {name:"July", value: 6},
      {name:"August", value: 7},
      {name:"September", value: 8},
      {name:"October", value: 9},
      {name:"November", value: 10},
      {name:"December", value: 11}
    ];
    
    $scope.years = [2016,2017, 2018, 2019, 2020, 2021];

    AngularJS. No idea

    dgkj, 29 Ноября 2016

    Комментарии (4)
  4. Ruby / Говнокод #21587

    −96

    1. 1
    return unless successful == false

    dgkj, 27 Октября 2016

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

    −47

    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
    // ...
    var hours_array = [];
    var hours_list = [];
    var current_time = new Date;
    if (working_hours_array !== undefined && working_hours_array.length > 0) {
        hours_array = working_hours_array; // working_hours_array: [11, 22]
    }
    if (hours_array !== undefined && hours_array.length == 2) {;
        for (var i = parseInt(hours_array[0]); i <= parseInt(hours_array[1]); i++) {
            var hour = i;
            hours_list.push(hour);
        }
        var current_hour = current_time.getHours();
        current_hour = parseInt(current_hour);
        if (test_mode) {
            current_hour = 23;
        }
        var hour_found = false;
        for (var j = 0; j < hours_list.length; j++) {
            if (hours_list[j] == current_hour) {
                hour_found = true;
                break;
            }
        }
        // ...
    }

    Проверка рабочих часов магазина.

    // hours_list: [11,12,13,14,15,16,17,18,19,20,21,22]

    dgkj, 15 Июня 2016

    Комментарии (0)
  6. JavaScript / Говнокод #20203

    −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
    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
    var data = "";
    var delivery_type;
    if (modes_object["delivery"] == true) delivery_type = "delivery";
    else delivery_type = "no_delivery";
    data += "delivery_type=" + delivery_type;
    var shop_id = $(".order__shop_select").val();
    data += "&shop_id=" + (shop_id);
    if (modes_object["delivery"] == true) {
        var address = $('[data-input="address"] .input_to_check').val();
        data += "&address=" + (address);
    }
    var phone = $('[data-input="phone"] .input_to_check').val();
    data += "&phone=" + (phone);
    var client_name = $('[data-input="client_name"] .input_to_check').val();
    data += "&client_name=" + (client_name);
    var email = $('[data-input="email"] .input_to_check').val();
    data += "&email=" + (email);
    var comment = $('.order__textarea').val();
    data += "&comment=" + (comment);
    if (modes_object["new_addr"]) {
        var new_addr_name = $('[data-block="new_addr"] .order__input').val();
        data += "&new_addr_name=" + new_addr_name;
    }
    if ($('[data-input="tableware_quantity"]').length) {
        var tableware_quantity = $('[data-input="tableware_quantity"] .input_to_check').val();
        data += "&tableware_quantity=" + tableware_quantity;
    }
    if ($('[data-input="promo_code"]').length) {
        var promo_code = $('[data-input="promo_code"] .input_to_check').val();
        data += "&promo_code=" + promo_code;
    }
    
    data += ($(".order__save_checkbox").prop("checked") == true) ? "&save_address=1" : "";
    
    var card_number = $('[data-input="card_number"] .order__input').val();
    data += "&card_number=" + card_number;
    
    if ($(".card_order__checkbox").prop("checked")) {
        data += "&card_ordered=true";
    }
    
    var time_to_take;
    if (modes_object["delivery"] == false) {
        var day_to_take = $.trim($(".order__day option:selected").text());
        var hour_to_take = $.trim($(".order__time--hour option:selected").text());
        var minute_to_take = $.trim($(".order__time--minutes option:selected").text());
        time_to_take = day_to_take + " в " + hour_to_take + ":" + minute_to_take;
        data += "&time_to_take=" + time_to_take;
    } else {
        data += "&time_to_take=";
    }
    
    if (modes_object["bank"] == true) {
        data += "&bank=true";
    }
    
    data += "&user_id=" + user_id;
    
    data += "&source=" + order_source;
    
    var modes = JSON.stringify(modes_object);
    data += "&modes=" + modes;

    Сериализация формы.

    dgkj, 15 Июня 2016

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

    +6

    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
    public function generate_hash($options = null) {
            $string_length  = (isset($options["length"])) ? $options["length"] : 10;
            $use_lowercase  = (isset($options["lowercase"])) ? $options["lowercase"] : true;
            $use_uppercase  = (isset($options["uppercase"])) ? $options["uppercase"] : true;
            $lowercase      = array(
                "a",
                "b",
                "c",
                "d",
                "e",
                "f",
                "g",
                "h",
                "i",
                "j",
                "l",
                "m",
                "n",
                "o",
                "p",
                "q",
                "r",
                "s",
                "t",
                "u",
                "v",
                "w",
                "x",
                "y",
                "z"
            );
            $uppercase      = array(
                "A",
                "B",
                "C",
                "D",
                "E",
                "F",
                "G",
                "H",
                "I",
                "J",
                "L",
                "M",
                "N",
                "O",
                "P",
                "Q",
                "R",
                "S",
                "T",
                "U",
                "V",
                "W",
                "X",
                "Y",
                "Z"
            );
            $digits         = array(
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9
            );
            $arrays         = array_merge($lowercase, $uppercase);
            $final_string   = array();
            $final_string[] = $arrays[array_rand($arrays)];
            // чтобы первым символом не была цифра
            $arrays         = array_merge($arrays, $digits);
            for ($i = 0; $i < ($string_length - 1); $i++) {
                $final_string[] = $arrays[array_rand($arrays)];
            }
            $final_string = implode("", $final_string);
            return $final_string;
    }

    dgkj, 18 Мая 2016

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

    +3

    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
    function pluralize($num) {
            switch ($num) {
                case 1:
                case 21:
                    $word = "товар";
                    break;
                case 2:
                case 3:
                case 4:
                case 22:
                case 23:
                case 24:
                case 32:
                case 33:
                case 34:
                    $word = "товара";
                    break;
                default:
                    $word = "товаров";
                    break;
            }
            return $word;
    }

    На продакшене.

    dgkj, 18 Мая 2016

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

    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
    public function format_phone($phone) {
            $phone       = preg_replace("/\D/", "", $phone);
            $first_digit = substr($phone, 0, 1);
            if ($first_digit == "7" || $first_digit == "8") {
                $phone = substr($phone, 1);
            }
            if ($first_digit == "+") {
                $phone = substr($phone, 2);
            }
            $p     = str_split($phone);
            $phone = "(" . $p[0] . $p[1] . $p[2] . ") " . $p[3] . $p[4] . $p[5] . "-" . $p[6] . $p[7] . "-" . $p[8] . $p[9];
            return $phone;
    }

    dgkj, 17 Мая 2016

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

    +149

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $flag = "yes";
    /* ... */
    if($flag) {
        $flag = $flag;
    }

    dgkj, 28 Мая 2015

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