Skip to content

Instantly share code, notes, and snippets.

@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)
data List a =
Empty |
Cons a (List a)
deriving (
Eq,
Ord
)
-- Type classes are pretyy cool
@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
@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 / 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 -&gt; b) -&gt; [a] -&gt; [b]
Manual Rides - From MMF and Strava and Entered through their EDH Account
@bradparker
bradparker / lijsp.js
Last active March 17, 2016 04:18
LIJSP... heh
import { expect } from 'chai'
const head = (arr = []) => arr.slice(0)[0]
const tail = (arr = []) => arr.slice(1)
const last = (arr = []) => arr.slice(0).pop()
const init = (arr = []) => arr.slice(0, arr.length - 1)
const subExpression = (tokens, depth = 0, currentBranch = []) => {
if (tokens.length === 0 || head(tokens) === ')') {
return [currentBranch, tail(tokens)]
@bradparker
bradparker / mathy-parser.js
Last active February 21, 2016 08:05
Dunno yet
import { expect } from 'chai'
const head = (arr = []) => arr[0]
const tail = (arr = []) => arr.slice(1)
const last = (arr = []) => arr.slice(0).pop()
const init = (arr = []) => arr.slice(0, arr.length - 1)
const nextInScope = (tokens, depth = 1, closeCount = 0) => {
if (depth === closeCount) {
return tokens
@bradparker
bradparker / hoc-examples.js
Last active January 18, 2016 05:41
HOC examples
// I18n
const translateable = (translations) => (Component) =>
(props = { locale: 'default' }) => {
const localTranslations = translations[locale]
return <Component { ...props } { ...localTranslations } />
}
const Greeter = ({ greeting, name }) =>
<p>{ greeting }, { name }</p>
@bradparker
bradparker / simple-rev.js
Created January 15, 2016 03:00
simple revision-er
'use strict'
const crypto = require('crypto')
const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const recursive = require('recursive-readdir')
const assign = Object.assign
const keys = Object.keys