Skip to content

Instantly share code, notes, and snippets.

🐕
Woof! Woof!

syzer syzer

🐕
Woof! Woof!
Block or report user

Report or block syzer

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
})
@syzer
syzer / jqueryPosition.ver1.js
Created Jan 16, 2018
My friend's did some jQyery... let's see
View jqueryPosition.ver1.js
var $scrolledelement = document.getElementById("left");
$scrolledelement.scrollTop = localStorage.scrollPosition;
$scrolledelement.onscroll = function() {
$pos = $scrolledelement.scrollTop
localStorage.setItem("scrollPosition", $pos);
$outelement.innerHTML = localStorage.scrollPosition;
};
View checkRunAsShell.js
if (require.main === module) {
console.log('Called from bash')
} else {
console.log('Called as a module')
}
@syzer
syzer / map_wihout_loop_ifs.js
Last active Nov 16, 2015
map without ifs , and loops
View map_wihout_loop_ifs.js
// here condR === undefined
const falsy = (condL, condR) => condL !== condR;
const map = (fn, [first, ...rest]) =>
(falsy(first) && []) && [fn(first), ...map(fn, rest)];
console.log(':)', map((x) => (x + x), [1, 2, 3]));
You can’t perform that action at this time.