Skip to content

Instantly share code, notes, and snippets.

@tjjfvi
tjjfvi / Promise.sequential.js
Last active October 11, 2018 22:58
Promise.sequential(asyncFuncs): Sequentially executes the function and returns Array of results
Promise.sequential = funcs => funcs.reduce((p, fn) => p.then(rs => fn().then(r => [...rs, r])), Promise.resolve([]))
@tjjfvi
tjjfvi / Promise.delay.js
Created October 11, 2018 22:52
Promise.delay(ms): Creates a promise that resolves in ms millisecons
Promise.delay = ms => new Promise(resolve => setTimeout(resolve, ms));
@tjjfvi
tjjfvi / ObjectMap.js
Last active January 9, 2019 22:50
Object.mapEntries, Object.mapValues, Object.mapKeys
Object.mapEntries = (obj, fn) =>
Object.assign({}, ...Object.entries(obj).map(e => fn(e, obj)).map(([k, v]) => ({ [k]: v })));
Object.mapValues = (obj, fn) =>
Object.mapEntries(obj, ([k, v]) => [k, fn(v, obj)]);
Object.mapKeys = (obj, fn) =>
Object.mapEntries(obj, ([k, v]) => [fn(k, obj), v]);
@tjjfvi
tjjfvi / killByPort.sh
Created October 10, 2018 22:09
*nix Bash Kill By Port
#!/usr/bin/env bash
kill `netstat -tulpn | grep :$1 | sed -e "s/.*LISTEN *//" -e 's/\/.*//'`