Skip to content

Instantly share code, notes, and snippets.

View syzer's full-sized avatar
🐕
Woof! Woof!

syzer syzer

🐕
Woof! Woof!
View GitHub Profile
@syzer
syzer / today.js
Created January 19, 2018 16:02
today
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
```json
"ava": {
"require": "babel-register",
"babel": "inherit"
}
```
@syzer
syzer / upperFirst.js
Created June 13, 2018 16:29
When you wanna do replace but you are `point-free`
const a = 'yello world'
const upperFirst = pipe(
juxt([pipe(head, toUpper), tail]),
join(''))
upperFirst(a)
// => 'Yello world'
@syzer
syzer / requestsInSeries.js
Created September 8, 2018 15:27
Example of async requests in series
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 / asyncReduce.js
Created October 20, 2018 19:40
Use reduce for serial async resolution AKA map.series
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 / test-npm-cli.sh
Created October 17, 2019 13:20
test npm cli tool locally before is published to registry
npm publish
npm i --globally message-que-0.5.5.tgz
ls -ln ~/.nvm/versions/node/v12.10.0/bin/
@syzer
syzer / bumpPackages.sh
Created October 31, 2019 14:14
Bump packages
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 / angular-hmr-remove-ref.js
Created February 6, 2020 13:28
When ref stayed in the nodes
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));
@syzer
syzer / QantilevsMedian.js
Last active August 19, 2021 16:55
How many to solve to improve percentile using ramda.js
// sort array ascending
const asc = arr => arr.sort((a, b) => a - b);
// sample standard deviation
const std = (arr) => {
const mu = mean(arr)
const diffArr = arr.map(a => (a - mu) ** 2)
return Math.sqrt(sum(diffArr) / (arr.length - 1))
}
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t=t||self).R={})}(this,function(t){"use strict";function a(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function o(r){return function t(n){return 0===arguments.length||a(n)?t:r.apply(this,arguments)}}function n(e){return function t(n,r){switch(arguments.length){case 0:return t;case 1:return a(n)?t:o(function(t){return e(n,t)});default:return a(n)&&a(r)?t:a(n)?o(function(t){return e(t,r)}):a(r)?o(function(t){return e(n,t)}):e(n,r)}}}var r=n(function(t,n){return+t+ +n});function i(t,n){var r,e=(t=t||[]).length,u=(n=n||[]).length,i=[];for(r=0;r<e;)i[i.length]=t[r],r+=1;for(r=0;r<u;)i[i.length]=n[r],r+=1;return i}function f(t,s){switch(t){case 0:return function(){return s.apply(this,arguments)};case 1:return function(t){return s.apply(this,arguments)};case 2:return function(t,n){return s.apply(this,arguments)};case 3:return function(t,n,r){retu