This file contains hidden or 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
#!/bin/sh | |
# Calculates a metric of how many `any`'s are there compared to line count for TypeScript codebase (in percents) | |
# Basically we count all `any` occurences, then count all lines in the codebase, and lastly divide one by another | |
echo "scale = 4; $(find -name "*.ts?" -not -path "./node_modules/*" | xargs grep -o '\bany\b' | wc -l) * 100 / $(find -name "*.ts?" -not -path "./node_modules/*" | xargs wc -l | tail -1 | awk '{print $1}')" | bc |
This file contains hidden or 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
function move(el, distance, duration) { | |
let startTime; | |
function recur() { | |
window.requestAnimationFrame((time) => { | |
if (startTime === undefined) { | |
startTime = time; | |
} | |
const elapsed = time - startTime; | |
const fraction = elapsed / duration; | |
const dx = Math.min(distance, distance * fraction); |
This file contains hidden or 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
// Custom promise-based compose | |
const composeWithPromise = (...args) => | |
R.composeWith((f, val) => { | |
if (val && val.then) { | |
return val.then(f); | |
} | |
if (Array.isArray(val) && val.length && val[0] && val[0].then) { | |
return Promise.all(val).then(f); | |
} | |
return f(val); |
This file contains hidden or 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
const MongoClient = require('mongodb').MongoClient; | |
const uri = 'mongodb://localhost:27017/'; | |
const mongoClient = new MongoClient(uri, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}); | |
(async () => { | |
const connection = await mongoClient.connect(); |
This file contains hidden or 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
function heavyFunc() { | |
const limit = Math.pow(10, 8); | |
let res = 0; | |
for (let i = 1; i < limit; i++) { | |
res += Math.atan2(i, i) * Math.random(); | |
} | |
return res; | |
} | |
async function heavyFuncWithAsync() { |
This file contains hidden or 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
/** | |
* Разные асинхронные паттерны в JS, решающие одну и ту же задачу | |
*/ | |
///////////////// callbacks /////////////////////////////////// | |
function asyncFunction(callback) { | |
setTimeout(callback.bind(this, 42), 100); | |
} | |
asyncFunction(console.log.bind(this, 'asyncFunction:')); |
This file contains hidden or 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
const readline = require('readline'); | |
const questions = [ | |
['Can the fox be recursive?', 'O_o'], | |
['Can readline be non-recursive?', 'Yep'] | |
]; | |
const cmd = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout |
This file contains hidden or 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
const readline = require('readline'); | |
const questions = [ | |
['What does the fox say?', 'Yeeeee'], | |
['Will you be coding this weekend?', 'Whaaaatt?!'] | |
]; | |
const cmd = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout |
This file contains hidden or 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
root = true | |
[*] | |
indent_style = space | |
indent_size = 2 | |
tab_width = 2 | |
end_of_line = lf | |
charset = utf-8 | |
trim_trailing_whitespace = true | |
insert_final_newline = true |
This file contains hidden or 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 secret = pm.variables.get('secret-key'), | |
timestamp = Date.now(), | |
query = pm.request.url.query | |
.filter(x => !x.disabled && x.key !== 'signature') | |
.map(x => { | |
if (x.key === 'timestamp') { | |
return `${x.key}=${timestamp}`; | |
} | |
else { | |
return `${x.key}=${x.value}`; |
NewerOlder