This file contains hidden or 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 pubSubRegistry(){ | |
const subscriptions = []; | |
return { | |
publish: function publish(event) { | |
subscriptions.forEach(function(subscription) { | |
subscription(event); | |
}); | |
}, |
This file contains hidden or 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
/* | |
A set of useful functional programming snippets | |
*/ | |
/** pipe | |
* @param fns Function[] - array of functions to execute | |
* | |
*/ | |
const pipe = (...fns: Function[]) => init => fns.reduce((acc, fn) => fn(acc), init); |
This file contains hidden or 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 reg = { | |
foo: true, | |
bar: false, | |
qux: true, | |
wc_123:true, | |
new_feature:true | |
}; | |
function dec2bin(dec){ | |
return (dec >>> 0).toString(2); |
This file contains hidden or 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
// https://hackernoon.com/functional-javascript-functors-monads-and-promises-679ce2ab8abe | |
const Thing = value => ({ | |
value, | |
map: morphism => Thing(morphism(value)), | |
flatMap: morphism => morphism(value) | |
}) | |
const thing1 = Thing(1) //=> Thing (1) | |
const thing2 = thing1.flatMap(x => Thing(x + 1)) //=> Thing (2) |
This file contains hidden or 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
// Future versions of Hyper may add additional config options, | |
// which will not automatically be merged into this file. | |
// See https://hyper.is#cfg for all currently supported options. | |
module.exports = { | |
config: { | |
// Choose either "stable" for receiving highly polished, | |
// or "canary" for less polished but more frequent updates | |
updateChannel: 'stable', |
This file contains hidden or 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
nvm ls-remote | |
nvm install 10.15.3 | |
nvm alias LTS v10.15.3 | |
nvm default LTS | |
nvm alias default 10.15.3 | |
nvm use 10.15.3 | |
npx npm -g install npm@latest | |
npm -v |
This file contains hidden or 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 { keys } = Object; | |
const isObject = a => typeof a === "object" && !Array.isArray(a); | |
const bothObjects = (a, b) => isObject(a) && isObject(b); | |
const neitherObjects = (a, b) => !isObject(a) && !isObject(b); | |
const sameType = (a, b) => (typeof a === typeof b); | |
const merge = (a, b) => | |
bothObjects(a, b)? | |
deepMerge(a, b): |
This file contains hidden or 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
import * as assert from 'assert'; | |
const paths = [ | |
'src', | |
'src/react-dom', | |
'src/react-dom/src', | |
'src/react-dom/src/client', | |
'src/react-dom/src/client/ReactDOMHostConfig.js', | |
'packages', | |
'packages/react-dom', |
This file contains hidden or 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 Id = <T extends {}>(v: T) => { | |
return { | |
valueOf: () => v, | |
map: (fn:any) => Id(fn(v)) | |
} | |
}; | |
console.log( | |
Id('foo') | |
.map( |
This file contains hidden or 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 addFive = (v) => (v + 5); | |
const timesTen = (v) => (v * 10); | |
const toObj = (v) => ({value: v}); | |
const addFiveTimesTenObj = (v) => [addFive, timesTen, toObj].reduce((acc, item) => (item(acc)), v); | |
console.log(addFiveTimesTenObj(123)); | |
console.log(addFiveTimesTenObj(13)); |
NewerOlder