Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / circle.js
Last active January 3, 2016 13:29
simple x and y cords for a circle
function circle (radius, x, y, nPoints) {
var circle = [];
var nPoints = nPoints || 360;
var wedge = 2 * Math.PI / nPoints;
for (var angle = wedge; angle < 2 * Math.PI; angle += wedge) {
circle.push({
x: x + radius * Math.cos(angle),
y: y + radius * Math.sin(angle)
});
@bradparker
bradparker / generic-state-container.md
Last active January 6, 2016 03:34
Generic state container

Must do prop transformation, it needs to add a specific onChange handler to each control.

I dislike this immensly but it'll work with our existing components and is ugly enough to encourage us to move to something like Redux.

// import get from 'lodash/object/get'

const handleControlChange = (onChange, statePath) => (value) =>
  onChange(statePath, value)
  
@bradparker
bradparker / package.json
Last active January 12, 2016 06:13
Keep it simple
{
"name": "get-going",
"version": "2.0.1",
"description": "",
"main": "dist/index.html",
"engines": {
"node": "5.2.0"
},
"scripts": {
"setup:source:dir": "mkdir -p source",
@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
@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 / 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
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 / 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