Skip to content

Instantly share code, notes, and snippets.

View JamieDixon's full-sized avatar

Jamie Dixon JamieDixon

View GitHub Profile
const compose = (f, g) => x => f(g(x));
function Observable(source, fn = x => x) {
this.fn = fn;
this.source = source;
}
Observable.of = (source, fn) => new Observable(source, fn);
Observable.prototype.map = function (fn) {
// This file demonstrates a component that handles local state (setState) using a redux type interface.
// The interesting part is that you can use redux middleware with this component via applyMiddleware.
// Example usage:
import { createLogger } from 'redux-logger';
import createSagaMiddleware from 'redux-saga';
import { takeLatest, call } from 'redux-saga/effects';
const sagaMiddleware = createSagaMiddleware();
function riddleMeThis(maze) {
function _riddleMeThis(maze, position = 0, steps = 1) {
const current = maze[position];
const nextPosition = position + current;
const next = maze[nextPosition];
if (next == null) {
return steps;
}
// http://adventofcode.com/2017/day/4
const numberValidLines = lines =>
lines.filter(line => {
const lineArray = line.split(' ');
return lineArray.length === (new Set(lineArray)).size;
}).length;
const calculateChecksum = input => input.reduce((agg, row) => agg + (Math.max(...row) - Math.min(...row)), 0);
// Standard recursive
function length(arr) {
const [head, ...tail] = arr;
if(head === undefined) {
return 0;
}
return 1 + length(tail);
function createTemplate(num) {
var Ts = [];
var args = [];
var selectors = [];
var selectorArgs = [];
for(var i = 1; i <= num; i ++) {
Ts.push(`T${i}`);
args.push(`arg${i}: T${i}`);
selectors.push(`Selector<TState, TProps, T${i}>`);

A module is a mechanism for encapsulating and publicly exposing (exporting) functionality within our app.

A module therefore has two purposes:

  1. To export a public API upon which other parts of the application can rely
  2. To encapsulate the private implementation behind the public API

Exported functionality is deemed safe to import by any other part of the application.

function isObject(value) {
const type = typeof value
return value != null && (type == 'object' || type == 'function')
}
function isNumber(value) {
return typeof value === 'number';
}
function isArray(value) {
function throttleWithIdentity(wait, fn) {
const cache = new Map();
return function(id) {
if (!cache.has(id)) {
cache.set(id, throttle(wait, fn));
}
return (cache.get(id) || noop)(id);
};