Skip to content

Instantly share code, notes, and snippets.

View joedski's full-sized avatar
💭
Ætheric

Joe joedski

💭
Ætheric
View GitHub Profile
@joedski
joedski / README.md
Last active August 29, 2015 14:01 — forked from nicerobot/README.md

To run this, you can try:

curl -ks https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh | bash

I haven't tested this script doing it this way but i run a lot of my Gists like this so maybe this one'll work too.

Alternatively,

curl -ksO https://gist.github.com/nicerobot/2697848/raw/uninstall-node.sh

chmod +x ./uninstall-node.sh

port requests : Signal (Task x ())
port requests =
let
-- Task x a
zipCodeLookups =
Signal.map lookupZipCode query.signal
sendResult =
Signal.send results.address
@joedski
joedski / multidispatch-thunk.js
Last active May 28, 2017 20:35
Javascript: Redux: Dispatching Multiple Actions: Redux Thunk
function multiAction(actions) {
return (dispatch) => actions.map(a => dispatch(a));
}
@joedski
joedski / multidispatch-middleware.js
Created May 28, 2017 20:50
Javascript: Redux: Dispatching Multiple Actions: Custom Middleware
// First, our action creator.
const MULTI_ACTION = 'multiAction/MULTI_ACTION';
const multiAction = (actions, meta = {}) => ({
type: MULTI_ACTION,
payload: { actions },
meta,
});
// Next, the middleware itself.
const multiActionMiddleware = store => next => action => {
@joedski
joedski / multidispatch-middleware-array.js
Created May 28, 2017 20:54
Javascript: Redux: Dispatching Multiple Actions: Custom Middleware Array Edition
const multiActionMiddleware = store => next => action => {
if (!Array.isArray(action)) return next(action);
return action.map(a => store.dispatch(a));
};
@joedski
joedski / react-redux-example-1-multiaction.jsx
Last active May 28, 2017 21:00
Javascript: Redux: Dispatching Multiple Actions: React Redux Example
export default connect(
null,
dispatch => ({
doAllTheThings: dispatch(multiAction([
doThisThing(),
doThatThing({ computer: 'over' }),
doTheOtherThing('foo'),
])),
}),
)(props => (
@joedski
joedski / multimemo.createApplier.js
Created July 13, 2017 23:52
Multiparam Memoization: createApplier
function createApplier(calculator, memoizers, totalValueCount, currValues) {
const memoize = memoizers[currValues.length];
function applyNonFinalValue(value) {
const nextValues = [...currValues, value];
return createApplier(calculator, memoizers, totalValueCount, nextValues);
}
function applyFinalValue(value) {
return calculator(...currValues, value);
@joedski
joedski / passSelectorCountToMemoizer.js
Created July 14, 2017 00:07
Multiparameter Memoization: The whole shebang
// A simple enhancer to use on reselect's createSelectorCreator that makes it
// pass the number of selectors received as the first option (after the calculator)
// to the memoizer.
function passSelectorCountToMemoizer(baseCreateSelectorCreator) {
return function selectorPassingSelectorCreator(memoize, ...memoizeOptions) {
return function createActualSelector(...args) {
const calculator = args.pop();
const selectors = Array.isArray(args[0]) ? args[0] : args;
return baseCreateSelectorCreator(memoize, selectors.length, ...memoizeOptions)(selectors, calculator);
@joedski
joedski / tieredMemoize.example.js
Created July 14, 2017 00:10
Multiparameter Memoization: Example
const reselect = require('reselect');
const createSelectorCreator = passSelectorCountToMemoizer(reselect.createSelectorCreator);
const createSelector = createSelectorCreator(createTieredMemoizer({ memoizers: [multiMemo] }));
const getFooBy = (state, id) => state.foos.byId[id];
const getBar = state => state.bar;
const getBaz = state => state.baz;
const getStuff = createSelector(
getFooBy, getBar, getBaz,
@joedski
joedski / tieredMemoize.arbitraryArity.js
Created July 15, 2017 03:49
Tierd Memoization of Functions of Arbitrary Arites (also fixed the single memo)
// Simple naive single-param single-memo.
function singleMemo(fn) {
let calledAtLeastOnce = false;
let prevArg;
let value;
return function singleMemoizedFn(arg) {
if (arg !== prevArg || !calledAtLeastOnce) {
calledAtLeastOnce = true;
prevArg = arg;