Skip to content

Instantly share code, notes, and snippets.

Manual Rides - From MMF and Strava and Entered through their EDH Account
@bradparker
bradparker / map.md
Last active April 20, 2016 03:46
Map
const map = (fn, arr) => {
  if (!arr.length) return []
  const [head, ...tail] = arr
  return [fn(head, ...map(fn, tail)]
}
map :: (a -> b) -> [a] -> [b]
@bradparker
bradparker / decrement-by.hs
Last active April 5, 2016 10:24
decrementBy
decrementBy :: (Ord a, Num a) => a -> a -> a
decrementBy n d
| n < d = 0
| otherwise = n - d
--- 1 `decrementBy` 2
--- 0
--- 2 `decrementBy` 1
--- 1
--- pi `decrementBy` 1
@bradparker
bradparker / type-aliases.hs
Created April 7, 2016 11:46
Type aliases
type AssociativeList key value = [(key, value)]
type Name = String
type PhoneNumber = String
type PhoneBook = AssociativeList Name PhoneNumber
data List a =
Empty |
Cons a (List a)
deriving (
Eq,
Ord
)
-- Type classes are pretyy cool
@bradparker
bradparker / excludeParents.js
Last active May 11, 2016 13:00
Exclude parent dirs
const assert = require('assert')
const isEqual = (a, b) => {
if (a.length !== b.length) return false
return a.every((aElem, index) => aElem === b[index])
}
// flip :: (a -> b -> c) -> (b -> a -> c)
const flip = (f) => (a, b) => f(b, a)
@bradparker
bradparker / task.js
Last active May 15, 2016 10:33
Task
const fetch = require('node-fetch')
const Task = require('data.task')
const KEY = 'KEY!'
const asteroidRequest = new Task((reject, resolve) => (
fetch(`https://api.nasa.gov/neo/rest/v1/feed?start_date=2016-05-05&end_date=2016-05-05&api_key=${KEY}`)
.then((res) => res.json())
.then(resolve)
.catch(reject)
@bradparker
bradparker / by-module.md
Last active August 2, 2017 04:45
Project Structure

Modules example

A module which represents part of a Reaat app could export an array of routes and a reducer.

export {default as routes} from './routes'
export {default as reducer} from './store/reducer'

The top level application can take these exports and collect them together into the root routes def and the root reducer.

@bradparker
bradparker / mutator.js
Created October 13, 2016 01:09
Mutator
const { keys, assign } = Object
const exampleSource = {
first_name: 'Bob',
last_name: 'Boberson',
charity_1: '1',
charity_2: '2',
charity_3: '3'
}
@bradparker
bradparker / use.md
Last active October 26, 2016 08:53
Currying is ok I guess
> const curry = require('./curry')
> const add3 = (a, b, c) => a + b + c
> add3(1, 2, 3)
6
> const curAdd3 = curry(add3)
> curAdd3(1)
[Function]
> curAdd3(1, 2)
[Function]