- 1
- 2
while (st.indexOf(" ") != -1)
st = st.replace(" ", " ");
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+4
while (st.indexOf(" ") != -1)
st = st.replace(" ", " ");
0
/**
* Static Content Helpers
*/
(function (window, ng, app) {
app.service('$StaticContentHelpers', function () {
var instance = null;
/**
* Конструктор хелперов
*
* @returns {Object} Функции-хелперы
* @constructor
*/
function Init () {
/**
* Обертка для статического контента,
* добавляет static домен, который пришел с бэкенда
*
* @param {String} url Урл, к которому необходимо добавить домен для статики
*
* @return {String} Готовый абсолютный url для статического контента
*/
function wrapStaticContent (url) {
// Проверим, от корня ли путь
return window.currentStaticDomain + ((/(^\/)/.test(url)) ? '' : '/') + url;
}
return {
wrapStaticContent: wrapStaticContent
}
}
function getInstance () {
if (!instance) {
instance = new Init();
}
return instance;
}
return {
getInstance: getInstance
};
});
}(window, angular, mainModule));
гуру паттернов..
+5
$(document).on('click', 'a.switcher_link', function(e) {
e.preventDefault();
var btn = $(this);
$.getJSON(btn.attr('href'), {type: 'json'}, function(data) {
btn.parent().parent().parent().parent().parent().parent().parent().parent().replaceWith(data.data);
});
});
Нашел и ахуел....
+4
$ nodejs
> var buffer = new ArrayBuffer(2);
undefined
> var uint16View = new Uint16Array(buffer);
undefined
> var uint8View = new Uint8Array(buffer);
undefined
> uint16View[0]=0xff00
65280
> uint8View[1]
255
> uint8View[0]
0
https://developer.mozilla.org/en/docs/Web/JavaScript/Typed_arrays
endianness - теперь и в жабаскрипте. Почти как union
−2
this.params.IsCellEditable = function(rowNumber, cellNumber) {
cellNumber == 1;
this.params.ButtonList = this.params.ButtonList.filter(b=>b[0] === "OnRefresh");
let textContr = new CTextArea('textContr');
textContr.SourceName = "value";
textContr.ViewName = "Params";
textContr.ComEdit = true;
this.params.arrEditObj[1] = textContr;
}
Найдено в нашем проекте в старом модуле, в авторстве никто не признаётся.
Во-первых, строка 2 бессмысленна. Во-вторых, всё последующее имело бы хоть какой-то смысл _вне_ этой функции, а внутри уже на строке 3 выкидывает ошибку, потому что контекст там и есть this.param из первой строчки. В-третьих, строка 3 призвана выкидывать из тулбара виджета this.param все кнопки, кроме OnRefresh, но на самом деле она там только одна и есть. В-четвёртых, строчки 7 и 8 просто лишние (ну, это из логики используемого в проекте движка следует). В-пятых, из названия метода можно предположить (и это действительно так), что он должен бы возвращать булевское значение, но он всегда возвращает только undefined и, таким образом, все ячейки виджета оказываются нередактируемыми — что совсем лишает смысла создание контрола для редактирования в строках 5—9.
Редкостная бредятина. Кто-то в полном затмении писал, и даже десяти секунд не потратил на тестирование.
0
function floatToStringPrec(f, precisionDigits)
{
var PRECISION = Math.pow(10, precisionDigits);
var integerPart = Math.floor(f);
var fractionalPart = f % 1;
if (fractionalPart == 0)
{
return integerPart.toString();
}
var zeroesInFracPart = -Math.log10(fractionalPart);
if (Math.floor(zeroesInFracPart) == zeroesInFracPart)
{
zeroesInFracPart--;
}
else
{
zeroesInFracPart = Math.floor(zeroesInFracPart);
}
fractionalPart = Math.round(fractionalPart * PRECISION);
while (fractionalPart % 10 == 0)
{
fractionalPart /= 10;
}
var zeroes = '';
if (zeroesInFracPart > 0)
{
zeroes = Array(zeroesInFracPart + 1).join('0');
}
return integerPart.toString() + '.' + zeroes + fractionalPart.toString();
}
Преобразовать плавающего питуха в строку; сохранить не более precisionDigits цифр после запятой (остальные - округлить).
0
var routers = new (R(views))();
Чет по другому не придумал как в роутер view передать
0
//- ASAP OR DIE♪
// re: ASAP OR DIE♪
//- next time, you should die
+4
if (aKeqboard[i][j] == 'Пробел') {
var sLang = storage.get("language");
sContent += '<td width="770" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
}
else
if (aKeqboard[i][j] == 'ПробелENG') {
var sLang = storage.get("language");
sContent += '<td width="703" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_eng_' + sLang + ' k_f k_c_b" style="color: transparent;" onclick=\"opacit_ALE(' + id + ');\"></div></td>';
}
else
if (aKeqboard[i][j] == 'Shiftrus' || aKeqboard[i][j] == 'Shiftrusm' || aKeqboard[i][j] == 'Shifteng' || aKeqboard[i][j] == 'Shiftengm')
sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="shift_' + sLang + '" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
else
if (aKeqboard[i][j] == 'mShiftrus' || aKeqboard[i][j] == 'mShiftrusm' || aKeqboard[i][j] == 'mShifteng' || aKeqboard[i][j] == 'mShiftengm')
sContent += '<td width="77" height="78" align="center"><div id="search_btn_' + (id++) + '" class="mshift" style="color: transparent;" onclick=\"opacit(' + id + ');\"></div></td>';
else
if (aKeqboard[i][j] == 'Eng')
sContent += '<td width="123" height="78" align="center"><div id="search_btn_' + (id++) + '" class="eng_button" onclick=\"opacit(' + id + ');\"></div></td>';
else
if (aKeqboard[i][j] == 'Рус')
sContent += '<td width="212" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button" onclick=\"opacit_ALR(' + id + ');\"></div></td>';
else
if (aKeqboard[i][j] == 'Рус2') {
if (this._statusEng == true) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button2_eng" onclick=\"opacit_ALABC(' + id + ');\"></div></td>'; }
else if (this._statusEng == false) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="rus_button2" onclick=\"opacit_ALR(' + id + ');\"></div></td>'; }
}
else
if (aKeqboard[i][j] == '.,?123') {
if (this._statusEng == true) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="digit123" onclick=\"opacit_ALDABC(' + id + ');\"></div></td>'; }
else if (this._statusEng == false) { sContent += '<td width="167" height="78" align="center"><div id="search_btn_' + (id++) + '" class="digit123" onclick=\"opacit_ALD(' + id + ');\"></div></td>'; }
}
else
if (aKeqboard[i][j] == ' ')
sContent += '<td width="0" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" onclick=\"opacit(' + id + ');\" style="display: none;"></div></td>';
else
if (aKeqboard[i][j] == '...')
sContent += '<td width="75" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_s_' + sLang + ' k_f k_c_b" onclick=\"opacit(' + id + ');\" style="display: none;"></div></td>';
else
if (aKeqboard[i][j] == 'Стереть') {
var sLang = storage.get("language");
sContent += '<td width="120" height="78" align="center"><div id="search_btn_' + (id++) + '" class="k_b_' + sLang + ' k_f_del k_c_w" onclick=\"opacit(' + id + ' );\"></div></td>';
}
else
if (aKeqboard[i][j].length > 1) {
sContent += '<td width="167" height="70" align="center"><div id="search_btn_' + (id++) + '" class="k_b_green k_f k_c_w" onclick=\"opacit(' + id + ');\"></div></td>';
}
else {
sContent += '<td width="80" height="70" align="center"><div id="search_btn_' + (id++) + '" class="k_v k_f k_c_b" onclick=\"opacit(' + id + ');\"></div></td>';
}
}
+3
function captcha_answer (res) {
if (res.email == 0) {
$('#email').css('border','1px solid #C5C5C5');
$(".email").text("");
$(".email").hide();
}
if (res.email == 1) {
$('#email').css('border','1px solid red');
$(".email").text("E-mail слишком короткий");
$(".email").show();
}
if (res.email == 2) {
$('#email').css('border','1px solid red');
$(".email").text("E-mail слишком длинный");
$(".email").show();
}
if (res.email == 3) {
$('#email').css('border','1px solid red');
$(".email").text("Некорректный E-mail");
$(".email").show();
}
if (res.email == 4) {
$('#email').css('border','1px solid red');
$(".email").text("E-mail занят");
$(".email").show();
}
if (res.nickname == 0) {
$('#nickname').css('border','1px solid #C5C5C5');
$(".nickname").text("");
$(".nickname").hide();
}
if (res.nickname == 1) {
$('#nickname').css('border','1px solid red');
$(".nickname").text("Ник слишком короткий");
$(".nickname").show();
}
if (res.nickname == 2) {
$('#nickname').css('border','1px solid red');
$(".nickname").text("Ник слишком длинный");
$(".nickname").show();
}
if (res.nickname == 3) {
$('#nickname').css('border','1px solid red');
$(".nickname").text("Ник занят");
$(".nickname").show();
}
if (res.password_1 == 0) {
$('#password_1').css('border','1px solid #C5C5C5');
$(".password_1").text("");
$(".password_1").hide();
}
if (res.password_1 == 1) {
$('#password_1').css('border','1px solid red');
$(".password_1").text("Пароль слишком короткий");
$(".password_1").show();
}
if (res.password_1 == 2) {
$('#password_1').css('border','1px solid red');
$(".password_1").text("Пароль слишком длинный");
$(".password_1").show();
}
if (res.password_2 == 0) {
$('#password_2').css('border','1px solid #C5C5C5');
$(".password_2").text("");
$(".password_2").hide();
}
if (res.password_2 == 1) {
$('#password_2').css('border','1px solid red');
$(".password_2").text("");
$(".password_2").show();
}
if (res.password_2 == 2) {
$('#password_2').css('border','1px solid red');
$(".password_2").text("Пароли не совпадают");
$(".password_2").show();
}
};
Есть скрипт, он аяксом посылает запрос на страницу, скрипт "отвечает" в формате json, ответы типа {"email":"1"} а вот это собственно "расшифровка" ответов :)