Skip to content

Instantly share code, notes, and snippets.

Avatar
🐕
Woof! Woof!

syzer syzer

🐕
Woof! Woof!
View GitHub Profile
@syzer
syzer / angular-hmr-remove-ref.js
Created Feb 6, 2020
When ref stayed in the nodes
View angular-hmr-remove-ref.js
platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
// Ensure Angular destroys itself on hot reloads.
if (window['ngRef']) {
window['ngRef'].destroy();
}
window['ngRef'] = ref;
// Otherwise, log the boot error
}).catch(err => console.error(err));
View bumpPackages.sh
VERSIONS="
1.2.3.3
1.2.4
2.9.9
2.9.0
"
for VERSION in $VERSIONS; do
echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g'
done
@syzer
syzer / test-npm-cli.sh
Created Oct 17, 2019
test npm cli tool locally before is published to registry
View test-npm-cli.sh
npm publish
npm i --globally message-que-0.5.5.tgz
ls -ln ~/.nvm/versions/node/v12.10.0/bin/
@syzer
syzer / asyncReduce.js
Created Oct 20, 2018
Use reduce for serial async resolution AKA map.series
View asyncReduce.js
const asyncFunction = (nextID) =>
new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`Called with ${new Date()}`)
resolve()
}, 1000)
})
;[1, 2, 3].reduce((accumulatorPromise, nextID) => {
console.log(`Looped with ${new Date()}`)
@syzer
syzer / requestsInSeries.js
Created Sep 8, 2018
Example of async requests in series
View requestsInSeries.js
const sleep = s =>
new Promise(resolve =>
setTimeout(resolve, s * 1000))
const fetch = url =>
new Promise(resolve =>
setTimeout(() => resolve(url), 1.5 * 1000))
// Promise.all([
// 'a',
@syzer
syzer / upperFirst.js
Created Jun 13, 2018
When you wanna do replace but you are `point-free`
View upperFirst.js
const a = 'yello world'
const upperFirst = pipe(
juxt([pipe(head, toUpper), tail]),
join(''))
upperFirst(a)
// => 'Yello world'
View ava in pacakage.json
```json
"ava": {
"require": "babel-register",
"babel": "inherit"
}
```
View today.js
const { padStart } = require('lodash')
const pad0 = e => padStart(e, 2, '0')
const date = new Date()
const today = [
date.getUTCFullYear(),
pad0(date.getUTCMonth() + 1),
pad0(date.getUTCDate())
].join('.')
// => 2018.01.19
@syzer
syzer / getPathWithoutLens.js
Created Jan 18, 2018
getting complex objects can be hard
View getPathWithoutLens.js
const dotPath = R.useWith(R.path, [R.split('.')])
const propsDotPath = R.useWith(R.ap, [R.map(dotPath), R.of])
var obj = {
a: { b: { c: 42 } },
d: 2
}
propsDotPath(['a.b.c', 'd'], obj)
// => [ 42, 2 ]
@syzer
syzer / readline.js
Created Jan 17, 2018
readline by line.. do not terminate, can use object-stream-tools
View readline.js
if (module.parent) {
return
}
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: false // isTTY
})
You can’t perform that action at this time.