document.body.addEventListener('click', e => {
e.stopPropagaion();
e.stopImmediatePropagation();
e.preventDefault();
}, { capture: true });
Аналогично можно и для клавиатурных событий попробовать. function workHours(on, off, testNow = null) {
// TODO: validate input
const now = testNow ?? new Date().getHours();
const a = Number(on);
let b = Number(off);
const format = (status, nextTime) => ({ status, next_time: nextTime });
if (a === b) {
return format(true, 0);
}
if (a > b) {
b += 24;
}
if (now >= a && now < b) {
return format(true, 0);
}
if (now < a) {
return format(false, a - now);
}
return format(false, a + 24 - now);
}
// Тесты тесты
const tests = [
[9, 17, 10, { status: true, next_time: 0 }],
[9, 17, 8, { status: false, next_time: 1 }],
[9, 17, 17, { status: false, next_time: 16 }],
[19, 17, 17, { status: false, next_time: 2 }],
[19, 19, 17, { status: true, next_time: 0 }],
];
const eq = (a, b) => Object.entries(a).every(([k, v]) => b[k] === v);
tests.forEach(test => {
const [on, off, now, expected] = test;
const result = workHours(on, off, now);
const testResult = eq(result, expected);
if (testResult) {
console.log('Passed', {on, off, now, result});
}
console.assert(testResult, test);
});
- console.log(data.data.values)
+ console.log(data.values)
range
, majorDimension
и values
. Последнее и интересует. http://localhost:8000/api
docker run -p 8000:8000
http://centrifugo:8000/api
const findRangeKey = (keysArray, keyString) => {
const num = Number(keyString);
if (keysArray.includes(keyString)) {
// exact match
return keyString;
}
return keysArray.find(key => {
const [min, max] = key.split('-').map(Number);
if (max !== undefined) {
return num >= min && num <= max;
}
return num === min;
});
};
findRangeKey(['10', '20-40'], 30); // "20-40"
findRangeKey(['10', '20-40'], 20); // "20-40"
findRangeKey(['10', '20-40'], 10); // "10"
const data = {
'10': {
'5-15': {
title: '10-5-15',
}
},
'20-60': {
'5': { title: '20-60-5' },
'10': { title: '20-60-10' },
'20-40': { title: '20-60-20-40' },
},
};
const getTitle = (data, a, b) => {
const aKey = findRangeKey(Object.keys(data), a);
if (!aKey) {
return null;
}
const bKey = findRangeKey(Object.keys(data[aKey]), b);
if (!bKey) {
return null;
}
return data[aKey][bKey].title;
};
console.log(getTitle(data, '10', '5')); // "10-5-15"
console.log(getTitle(data, 40, 30)); // "20-60-20-40"
services:
frontend:
image: example/webapp
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
pids: 1
reservations:
cpus: '0.25'
memory: 20M
ls -l@
«Собака» – для расширенных атрибутов.$ ls -l@
drwx------@ 5 username staff 160 Sep 22 20:22 Applications
com.apple.quarantine 21
drwx------+ 57 username staff 1824 Jun 15 16:17 Desktop
drwx------+ 179 username staff 5728 Jan 17 12:03 Documents
drwx------+ 266 username staff 8512 Jan 15 18:25 Downloads
drwx------@ 125 username staff 4000 Dec 1 19:16 Dropbox
com.apple.FinderInfo 32
com.apple.quarantine 34
drwx------@ 74 username staff 2368 Oct 2 17:40 Library
com.apple.FinderInfo 32
xattr filename
$ xattr Dropbox/
com.apple.FinderInfo
com.apple.quarantine
Или подробнее, со значением атрибута в 16-ричном виде или текстовом: с ключом -l
$ xattr -l Dropbox/
com.apple.FinderInfo:
00000000 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020
com.apple.quarantine: 0082;00000000;DropboxFolderTagger;
man xattr
const keys = ['key1', 'key2', 'key3'];
const values = ['value1', 'value2', 'value3', 'value4', 'valu5', 'value6'];
const makeGen = function*(arr) {
let index = 0;
const { length } = arr;
while (true) {
yield arr[index++ % length];
}
}
const keyGen = makeGen(keys);
const valGen = makeGen(values);
const length = Math.max(keys.length, values.length);
const result = Array.from({ length }, () => [keyGen.next().value, valGen.next().value]);
console.log(JSON.stringify(result, null, 2));
/*
[
[
"key1",
"value1"
],
[
"key2",
"value2"
],
[
"key3",
"value3"
],
[
"key1",
"value4"
],
[
"key2",
"valu5"
],
[
"key3",
"value6"
]
]
*/
fadeOut()
вероятно, из jQuery?- elem.fadeOut();
+ $('selector').fadeOut();