var u = "Browser";
if (this.isIPad) {
u = "iPad"
} else {
if (this.isDDGIgnore) {
u = "Ignore"
} else {
if (/seamonkey/.test(x)) {
u = "SeaMonkey"
} else {
if (/iceape/.test(x)) {
u = "Iceape"
} else {
if (/palemoon/.test(x)) {
u = "PaleMoon"
} else {
if (this.isFirefox) {
u = "Firefox"
} else {
if (this.isAndroid) {
u = "Android"
} else {
if (/xbox/.test(x)) {
u = "xBox"
} else {
if (/midori/.test(x)) {
u = "Midori"
} else {
if (/opr/.test(x)) {
u = "Opera"
} else {
if (/maxthon/.test(x)) {
u = "Maxthon"
} else {
if (this.isYandex) {
u = "Yandex"
} else {
if (/vivaldi/.test(x)) {
u = "Vivaldi"
} else {
if (this.isChrome) {
u = "Chrome"
} else {
if (/fennec/.test(x)) {
u = "Fennec"
} else {
if (/epiphany/.test(x)) {
u = "Epiphany"
} else {
if (this.isFirefox) {
u = "Firefox"
} else {
if (/uzbl/.test(x)) {
u = "Uzbl"
} else {
if (this.isEdge) {
u = "Edge"
} else {
if (this.isIE && navigator.platform === "Win64" && !k() && Modernizr.touch && document.documentElement.clientWidth == screen.width) {
u = "IEMetro"
} else {
if (this.isIE) {
u = "IE"
} else {
if (this.isOpera) {
u = "Opera"
} else {
if (this.isIPhone) {
u = "iPhone"
} else {
if (/arora/.test(x)) {
u = "Arora"
} else {
if (this.isSafari) {
u = "Safari"
} else {
if (this.isKonqueror) {
u = "Konqueror"
} else {
if (this.isBlackberry) {
u = "Blackberry"
} else {
if (/phantomjs/.test(x)) {
u = "PhantomJS"
} else {
if (this.isIDevice) {
u = "iOS"
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Found when looking at facebook.com code and formatting using google chrome developer tools.
var show = true;
function toggleShow(){
if(show === true){
show = false;
return show;
}else{
show = true;
return show;
}
}
return show = !show
, dude...
if(wyraz.charAt(i) <"A"
&& wyraz.charAt(i) != "-"
&& wyraz.charAt(i) != " "
&& wyraz.charAt(i) != "."
&& wyraz.charAt(i) != "&"
&& wyraz.charAt(i) != "_"
&& wyraz.charAt(i) != "\""
&& wyraz.charAt(i) != "'"
) {
if(polska_litera(wyraz.charAt(i) ) == 0 )
return NO;
}
if(wyraz.charAt(i) >"Z"
&& wyraz.charAt(i) != "-"
&& wyraz.charAt(i) != " "
&& wyraz.charAt(i) != "."
&& wyraz.charAt(i) != "&"
&& wyraz.charAt(i) != "_"
&& wyraz.charAt(i) != "\""
&& wyraz.charAt(i) != "'"
)
Just PKP :)
function focused(evt, errors) {
let form = evt.target
const output = errors.map((error)=> {
// Find first component with error on form and set focus to it
let focusedInput = (Object.keys(error) == "phonebookId") ? Object.keys(error) :
(Object.keys(error) == "phonebook_str") ? Object.keys(error) :
(Object.keys(error) == "message") ? Object.keys(error) :
(Object.keys(error) == "image") ? Object.keys(error) :
(Object.keys(error) == "buttonLink") ? Object.keys(error) :
(Object.keys(error) == "messageSms") ? Object.keys(error) : false
return focusedInput.shift()
})
const selector = output.shift()
form.querySelector('[id="' + selector + '"]').focus()
return selector
}
What can I say... If you plan to work with freelancers with low rate then you should be ready to find it in them code :)
$scope.$$childHead.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling.$$nextSibling
Was trying to find a very specific text box and as an AngularJS noob, this was the only way I could find it at first. I eventually figured out how to not do this before it ever got committed to production though. :)
function returnTrue() {
return true;
}
var filter = options.dataSource.filter();
if(e.filter) {
filter = filter && filter.filters.length ? filter.filters.concat(e.filter.filter) : e.filter.filters;
}
else {
filter = filter && filter.filters.length ? filter.filters.linqRemove({ field: e.field }) : [];
}
options.dataSource.filter(filter);
// Is this valid?
function validateStockInItems() {
if (stockInItemsToUpdate.length === 0)
return true;
return true;
}
Found in a legacy code base for a stock management system. I will be rewriting said system soon.
o.isInsured = function ()
{ return !!this.insured; }
Why don't be like normal people and use bool() cast?
for(var j=0;j<10;j++){
cell=document.createElement('td');
switch(j)
{
case 0:
var date1 = events[i]['start'];
var date2 = events[i]['end'];
cell.appendChild(document.createTextNode(date1.getFullYear()+'/'+date1.getMonth()+'/'+date1.getDate()+' '+date1.getHours()+':'+date1.getMinutes()+' To '+date2.getFullYear()+'/'+date2.getMonth()+'/'+date2.getDate()+' '+date2.getHours()+':'+date2.getMinutes()));
break;
case 1: cell.appendChild(document.createTextNode(events[i]['title'])); break;
case 2: cell.appendChild(document.createTextNode(events[i]['description'])); break;
}
row.appendChild(cell);
}
The for loop that counts to 10, but the last seven
function formatUpToANumberOfZeroesAfterFloatingPoint(number, numberOfZeroes, floatingPointSymbol) {
numberOfZeroes = (numberOfZeroes === undefined || numberOfZeroes < 0) ? 2 : numberOfZeroes;
floatingPointSymbol = floatingPointSymbol === undefined ? '.' : floatingPointSymbol;
let numberSplitByFloatingPoint = number.toString().split(floatingPointSymbol);
if (numberSplitByFloatingPoint.length !== 2)
return `${number}${floatingPointSymbol}${'0'.repeat(+numberOfZeroes)}`;
let numberAfterFloatingPoint = numberSplitByFloatingPoint[1].toString();
let formattedNumber = `${numberSplitByFloatingPoint[0]}`;
let numberAfterFloatingPointLength = numberAfterFloatingPoint.toString().length;
if (+numberOfZeroes > +numberAfterFloatingPointLength)
return `${formattedNumber}${floatingPointSymbol}${numberAfterFloatingPoint}${'0'.repeat(+numberOfZeroes - numberAfterFloatingPointLength)}`;
let countOfNumbersAfterFloatingPoint = numberAfterFloatingPointLength;
for (var i = numberAfterFloatingPointLength - 1; i >= 0; i--) {
if (+(numberAfterFloatingPoint[i]) !== 0 || +countOfNumbersAfterFloatingPoint === +numberOfZeroes) {
formattedNumber += `${floatingPointSymbol}${numberAfterFloatingPoint.substring(0, countOfNumbersAfterFloatingPoint)}`;
break;
}
countOfNumbersAfterFloatingPoint--;
}
return formattedNumber;
}
Well, a junior dev here. A cute female QA came to me with a request - "the field for the price already has precision up to 4 decimal places, but we don't like the 4 ugly zeroes, so if the number ends in zeroes, let it have only 2" - she said in the most innocent-like tone ever known to mankind. How easy I mumbled and accepted the task. As she was leaving she added - "oo almost forgot, we also would like it if all the data fields for the price that are shown in the tables also are formatted that way". As I was watching her better side, while she was getting reunited with her QA tribe, I got shivers down the spine. I had a bad feeling about that one, but I wasn't sure why yet. Suddenly as I was getting up to get a cup of coffe, it dawned on me - "this poor excuse for a project is using jqGrid for displaying the data". To wrap things up - I got a quadruple espresso with a shot of Jacky, developers best friend in a time of need, and came up with this piece of art. Enjoy :)
const errorHandler = () => {
throw new Error();
};
function downScaleCanvas(a, b) {
var c = Math.ceil,
d = Math.floor;
if (!(1 > b) || !(0 < b)) throw "scale must be a positive number <1 ";
var e = b * b,
f = a.width,
g = a.height,
h = d(f * b),
i = d(g * b),
j = 0,
k = 0,
l = 0,
m = 0,
n = 0,
o = 0,
p = 0,
q = 0,
r = 0,
s = 0,
t = 0,
u = 0,
v = 0,
x = 0,
y = 0,
z = !1,
A = !1,
B = a.getContext("2d").getImageData(0, 0, f, g).data,
C = new Float32Array(3 * h * i),
D = 0,
E = 0,
F = 0;
for (k = 0; k < g; k++)
for (n = k * b, r = 0 | n, o = 3 * r * h, A = r != (0 | n + b), A && (x = r + 1 - n, y = n + b - r - 1), j = 0; j < f; j++, l += 4) m = j * b, q = 0 | m, p = o + 3 * q, z = q != (0 | m + b), z && (u = q + 1 - m, v = m + b - q - 1), D = B[l], E = B[l + 1], F = B[l + 2], z || A ? z && !A ? (s = u * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * b, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t) : A && !z ? (s = x * b, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = y * b, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t) : (s = u * x, C[p] += D * s, C[p + 1] += E * s, C[p + 2] += F * s, t = v * x, C[p + 3] += D * t, C[p + 4] += E * t, C[p + 5] += F * t, t = u * y, C[p + 3 * h] += D * t, C[p + 3 * h + 1] += E * t, C[p + 3 * h + 2] += F * t, t = v * y, C[p + 3 * h + 3] += D * t, C[p + 3 * h + 4] += E * t, C[p + 3 * h + 5] += F * t) : (C[p] += D * e, C[p + 1] += E * e, C[p + 2] += F * e);
var G = document.createElement("canvas");
G.width = h, G.height = i;
var H = G.getContext("2d"),
I = H.getImageData(0, 0, h, i),
J = I.data,
K = 0;
for (l = 0, p = 0; K < h * i; l += 3, p += 4, K++) J[p] = c(C[l]), J[p + 1] = c(C[l + 1]), J[p + 2] = c(C[l + 2]), J[p + 3] = 255;
return H.putImageData(I, 0, 0), G
}
dohhhhhh !!
if (i === 1 || i === 2 || i === 3 || i === 4 || i === 5 || i === 6 || i === 7 || i === 8 || i === 9 || i === 10){
return true;
}
function isAllowSearchLength(text) {
return text.length > isNaN(parseInt(text, 10)) ? 1 : 0;
}