Skip to content

Instantly share code, notes, and snippets.

View davidchase's full-sized avatar
📺
Working from home

David Chase davidchase

📺
Working from home
View GitHub Profile
@davidchase
davidchase / esnextbin.md
Created September 26, 2016 15:45
esnextbin sketch
@davidchase
davidchase / README.md
Last active October 14, 2016 15:17
Browser Test Runner Example
@davidchase
davidchase / esnextbin.md
Created October 7, 2016 18:22
esnextbin sketch
import {curryN, has, values, is} from 'ramda'
// given a error object from a third party source
// which may not guarantee structure
// quick search via recursion to find property
const err = {
system: {
status: {
err: {
response: 'boom',
@davidchase
davidchase / esnextbin.md
Last active December 10, 2016 16:21
esnextbin sketch
@davidchase
davidchase / esnextbin.md
Last active December 11, 2016 13:18
esnextbin sketch
// @TODO pull out the mapping and filtering
// make composable/lazy(only run when fold'ing)
const copyList = xs => reduce(concat, [], xs)
const filterR = (f, xs) => reduce((acc, x) => f(x) ? acc.concat(x) : acc , [], xs)
const mapR = (f, xs) => reduce((acc, x) => acc.concat(f(x)), [], xs)
// List with methods in terms of reduce
const List = xs => ({
xs,
map: f => List(mapR(f, xs)),
const Coyo = (f, v) => ({fn: f, val: v})
const id = x => x
const liftCoyo = a => Coyo(id, a)
const fmap = (fn, coyo) => Coyo(compose(fn, coyo.fn), coyo.val)
const lower = coyo => map(coyo.fn, coyo.val)
// Array#reduce + recursion to flatten
// any level of nested arrays
// So we reduce the nested array and aggregate the values of the Integer type into the seed array
// during the aggregation we 1st check if the values from the input array are of the Array type via `isArray`
// if so we call the function `flatten` again passing that array value as input and if the value is
// not of the Array type it we `concat` the value with the seed array
// below is a timeline of how the values look after the input array is given
// [[1, 2, [3]], 4]: --- [1,2,[3]] --> 1 --> 2 --> [3] --> 3 --> 4
const flatten = array => array.reduce((acc, val) => acc.concat(Array.isArray(x) ? flatten(val) : val), [])
@davidchase
davidchase / simple-http-request.js
Created February 27, 2017 04:40
simple-http-request.js
const toString = buff => buff.toString()
const jParse = str => JSON.parse(str)
const stringify = obj => JSON.stringify(obj)
const keys = obj => Object.keys(obj)
const dissoc = (str, obj) =>
keys(obj).reduce((acc, k) => k !== str ? (acc[k] = obj[k], acc) : acc , {})
const simpleReq = (url, opts = {}) =>
new Promise((resolve, reject) => {