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 / 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'
```json
"ava": {
"require": "babel-register",
"babel": "inherit"
}
```
@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
@syzer
syzer / getPathWithoutLens.js
Created January 18, 2018 18:19
getting complex objects can be hard
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 January 17, 2018 10:38
readline by line.. do not terminate, can use object-stream-tools
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 January 16, 2018 19:31
My friend's did some jQyery... let's see
var $scrolledelement = document.getElementById("left");
$scrolledelement.scrollTop = localStorage.scrollPosition;
$scrolledelement.onscroll = function() {
$pos = $scrolledelement.scrollTop
localStorage.setItem("scrollPosition", $pos);
$outelement.innerHTML = localStorage.scrollPosition;
};
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 November 16, 2015 16:14
map without ifs , and loops
// 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]));
@syzer
syzer / gist:74516ccb0f9ca48dfa4a
Last active August 29, 2015 14:20
closing tags Maciej chelange
// char => char
function closingTag(char) {
return {
'(': ')',
'{': '}',
'[': ']'
}[char];
}
// char => boolean
function match_brackets(str){
var stack = [],
lookup = {
//key : value pairs
'(' : ')',
'{' : '}',
'[' : ']',
},
_keys = Object.keys(lookup),