Skip to content

Instantly share code, notes, and snippets.

@orodio
orodio / redux.js
Created May 31, 2017 21:28
redux with a generator
export const createStore = (reducer, state = {}) => {
let subs = []
const store = (function * () {
while (true) {
const event = yield null
state = reducer(state, event)
subs.forEach(fn => fn(state))
}
})
@orodio
orodio / flux.js
Created May 29, 2017 20:07
redux'ish thing with generators and adhoc handlers
const createStore = (state) => {
const noop_handler = state => state
state = state || {}
var handlers = {}
var subs = []
const store = (function * () {
while (true) {
const { type, payload } = yield null
state = (handlers[type] || noop_handler)(state, ...payload)
@orodio
orodio / cmds.md
Created April 11, 2017 23:53
elixir phoenix mac postgres
$ mix phoenix.new <NAME>
$ cd <NAME>
$ mix ecto.create

// if postgres errors
  $ brew install postgresql
  $ psql postgres
  postgres=# CREATE ROLE postgres;
 postgres=# ALTER ROLE postgres LOGIN;
@orodio
orodio / Lambda Calc
Created September 23, 2016 02:30
Lambda Calc
λf.(λx.f(xx))(λx.f(xx))
ZERO = λfx.x | f -> x -> x
ONE = λfx.fx | f -> x -> f(x)
TWO = λfx.f(fx) | f -> x -> f(f(x))
THREE = λfx.f(f(fx)) | f -> x -> f(f(f(x)))
SUCC = λnfx.nfx | n -> f -> x -> n(f)(x)
ADD = λmnfx.mf(nfx) || λmn.n succ m | m -> n -> f -> x -> m(n(f))(x)
import css from "./styles.css"
import React from "react"
import Counter from "../Counter"
import Form from "../Form"
import update from "../__lib__/update"
import unset from "../__lib__/unset"
import set from "../__lib__/set"
import xhr from 'superagent'
import { Observable } from 'rx'
/** body
* @description returns the body of a supplied response
* @param {Object} response the response from the xhr request
* @return {Any} what ever the body is
*/
function body (response) {
return response.body
@orodio
orodio / .eslintrc
Created January 15, 2016 03:46
Drawboard ESlintFile
env:
browser: true
node: true
es6: true
mocha: true
protractor: true
ecmaFeatures:
modules: true
jsx: true
import xhr from "superagent"
import { Observable } from "rx"
var id = v => v
var body = r => r.body
var r = (resolve, reject, fn=id) =>
(err, res) =>
!!err
@orodio
orodio / gist:d55fabd7eacdc5c1286f
Created December 29, 2015 06:44
playing around with some monads and canvas
var $ = document.querySelector.bind(document)
var createRenderer = register => data => data.reduce((acc, datum) => {
var { type } = datum
if (type == null || register[type] == null) return acc
return [ ...acc, register[type](datum) ]
}, [])
function Just (value) {
if (!isJust(this)) return new Just(value)
@orodio
orodio / Explain.md
Last active November 27, 2015 02:35
How we currently redux.

every event type gets an aggregate file. As declaratively as possible we describe what an action does.

// src/aggregates/poll_playlist_response.js

import { GET } from "../tools/http";
import { curryDispatch } from "../tools/curry_dispatch";

export var type = "POLL_PLAYLIST_RESPONSE";