This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function tryAsyncUntilOk(func, times = 4, timeout = 1250) { | |
function delay(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
for (let i = 0; i < times; i++) { | |
try { | |
const res = await func(); | |
if (typeof res !== "undefined") { | |
return res; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Storage { | |
static get(key) { | |
const value = localStorage.getItem(key); | |
if (!value) return undefined; | |
try { | |
return JSON.parse(value); | |
} catch { | |
localStorage.removeItem(key); | |
return undefined; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Необходимые максимальные показатели (wi-fi, 200 mb/s, октябрь 2020): | |
Desktop: | |
1. FCP - 0.6s | |
2. Time To Interactive - 1.9s | |
3. Speed Index - 1.2s | |
4. LCP - 0.8s | |
5. CLS - 0.001s | |
6. Total Blocking Time - 0.1s | |
7. DomContentLoaded - 1.5s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
struct course { | |
int mark; | |
char subject[30]; | |
} mark; | |
struct course *ptr; // we don't allocate memory at that point because we don't know amount yet | |
int numberOfRecords; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let range = { | |
start: 0, | |
finish: 10 | |
} | |
range = new Proxy(range, { | |
has(target, property) { | |
if (property >= range.start && range.finish >= property) return true; | |
else return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function compose(...fns) { | |
return async x => { | |
let res = x; | |
for (const fn of fns) { | |
res = await fn(res); | |
} | |
return res; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function* idGeneration(start = 0) { | |
while(true) { | |
const newID = yield start++; | |
if (typeof newID !== 'undefined') { | |
start = newID; | |
yield start++; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class RandomNameGenerator { | |
constructor(amountOfNames, lengthOfNames) { | |
this.amountOfNames = amountOfNames; | |
this.lengthOfNames = lengthOfNames; | |
this.names = new Array(); | |
}; | |
makeName(stringLength) { | |
let result = ''; | |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
const charactersLength = characters.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function* generateIDS(fromID) { | |
while (true) { | |
yield fromID++; | |
} | |
} | |
// Example of usage | |
// const generator = generateIDS(0); | |
// const MichaelID = generator.next().value; | |
// const DimaID = generator.next().value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class AsyncCollector { | |
gotData = []; | |
constructor(timeout, ...funcs) { | |
return new Promise((resolve, reject) => { | |
const promisesOfFuncs = funcs.map(item => item()); | |
Promise.all(promisesOfFuncs) | |
.then(values => this.gotData = values) | |
.then(() => { | |
setTimeout(() => { | |
resolve(this.gotData); |
NewerOlder