This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Use flexible layout with flexbox */ | |
/* source: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes */ | |
#main { | |
display: flex; | |
} | |
#main > article { | |
flex: 3 1 54%; | |
order: 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = exports = { | |
"env": { | |
"es6": true, | |
"node": true, | |
"browser": true | |
}, | |
"parserOptions": { | |
"sourceType": "module", | |
"ecmaFeatures": { | |
"jsx": true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function replace<T>(arr: Array<T>, i: number, val: T) { | |
const end = i >= (arr.length-1) ? arr.length : i+1; | |
return [...arr.slice(0, i < 0 ? 0 : i), val, ...arr.slice(-(arr.length-end)||arr.length)]; | |
} | |
console.log(replace([],0,99)) | |
console.log(replace([1,2,3],0,99)) | |
console.log(replace([1,2,3],1,99)) | |
console.log(replace([1,2,3],-1,99)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let promise = ctx => new Promise((resolve, reject) => Object.assign(ctx, {resolve, reject})) | |
function future(o = {}) { | |
let p = promise(o) | |
return Object.assign(o, { onValue: p.then.bind(p) }) | |
} | |
function fn() { | |
let f = future() | |
f.onValue(n => console.log(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findPath(specs, pathKey) { | |
let result | |
specs.find(spec => !!(result = spec.find(pathKey))) | |
return result | |
} | |
function addPrefix(prefix, path) { | |
return isStr(prefix) && path.indexOf(prefix) !== 0 ? `${prefix}${path}` : path | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flattenToObj = (arr, base = {}) => Object.assign(base, ...arr) | |
function shieldProps(t, ...keys) { | |
let keep = flattenToObj(Object.keys(t).filter(k => !keys.includes(k)).map(k => ({ [k]: t[k] }))) | |
return Object.setPrototypeOf(keep, t) | |
} | |
let o = { s: 'xxx'} | |
Object.defineProperty(o, 't', { value: {v: 'yyy'}, writable: false, enumerable: true }) | |
let a = shieldProps(o, 't') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a1 = Array(3).map(x => 42) // => [undefined,undefined,undefined] | |
let a2 = Array.from(Array(3), x => 42) // => [42, 42, 42] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipe(...fns) { | |
function invoke(v) { | |
return fns.reduce((acc, fn) => (fn ? fn.call(this, acc) : acc), v) | |
} | |
return invoke | |
} | |
let i=1, fn = m => console.log(i++,m) | |
let piped = pipe.bind(null, fn) | |
piped = piped.bind(null, fn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent | |
;(function() { | |
if (typeof window.CustomEvent === "function") return false | |
function CustomEvent(event, params) { | |
params = params || { bubbles: false, cancelable: false, detail: undefined } | |
var evt = document.createEvent("CustomEvent") | |
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail) | |
return evt | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [], arr2 = [] | |
for(let i=0; i<200; i++) | |
{ | |
let s = String.fromCharCode(i) | |
if(s === encodeURIComponent(s)) arr.push(s) | |
if(s === encodeURI(s)) arr2.push(s) | |
} | |
//arr - // !'%()*-.~ | |
console.log(arr.length, arr2.length) |