- 1
- 2
- 3
- 4
- 5
$i = 1
resultsArray.each do |results|
results.rank = $i
$i += 1
end
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 9
−98
$i = 1
resultsArray.each do |results|
results.rank = $i
$i += 1
end
+овер9к прочих глобальных переменных и проскакивающие ; в конце строк. Привет, похапе.
−51
$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
−96
return unless successful == false
−47
// ...
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]
−50
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;
Сериализация формы.
+6
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;
}
+3
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;
}
На продакшене.
0
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;
}
+149
$flag = "yes";
/* ... */
if($flag) {
$flag = $flag;
}