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
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 ]
View readline.js
if (module.parent) {
return
}
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
// terminal: false // isTTY
})
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')
}
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]));
View gist:74516ccb0f9ca48dfa4a
// char => char
function closingTag(char) {
return {
'(': ')',
'{': '}',
'[': ']'
}[char];
}
// char => boolean
View gist:f40ed918cb5102438500
function match_brackets(str){
var stack = [],
lookup = {
//key : value pairs
'(' : ')',
'{' : '}',
'[' : ']',
},
_keys = Object.keys(lookup),
View gist:0de000098c15482d52ba
function train(fileName, splitter) {
var parts = fs.readFileSync(fileName).toString().split(splitter).map(function (el) {
return _.prepare(el).split(' ');
});
return mergeBig(parts);
}