Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
gordonbrander / example.js
Created March 1, 2013 17:51
updateState - a utility for representing/updating program state as an object.
var STATE_FILTERS = [
function clampIndex(state, old, update) {
return extend(state, {
// Validate and sanitize properties.
index: clamp(state.index, 0, state.units - 1)
});
},
function calculateOffset(state, old, update) {
return extend(state, {
// Create calculated properties.
// https://en.wikipedia.org/wiki/Linked_list
// https://blog.jcoglan.com/2007/07/23/writing-a-linked-list-in-javascript/
// Reducible prototype for linked list node.
var __node__ = {
reduce: function reduceNodes(reducer, initial) {
var node = this;
var accumulated = initial;
do {
accumulated = reducer(accumulated, node);
@gordonbrander
gordonbrander / dispatches.js
Created January 18, 2014 00:49
Distpatches -- MVP signals.
// Reduce any arraylike object.
function reduceIndexed(indexed, next, initial) {
var accumulated = initial;
for (var i = 0; i < indexed.length; i += 1)
accumulated = next(accumulated, indexed[i]);
return accumulated;
}
@gordonbrander
gordonbrander / hollywood-supply-chain.md
Last active January 13, 2016 10:45
Hollywood supply chain

In one Critical Path episode (can't remember which), Horace posits that Hollywood is like a distributed functional organization:

  • Workers are organized by specialty (acting,
@gordonbrander
gordonbrander / food_computer_1.0.json
Last active August 30, 2016 18:04
food_computer_1.0.json
{
"firmware_module": [
{
"_id": "ds18b20_1",
"type": "ds18b20",
"environment": "environment_1",
"arguments": [4],
"outputs": {
"temperature": {"variable": "water_temperature"}
}
@gordonbrander
gordonbrander / long_test_recipe.json
Created September 8, 2016 20:23
long_test_recipe
{
"_id": "long_test_recipe",
"format": "simple",
"operations": [
[
0,
"air_temperature",
25
],
[
const reduce = Array.reduce;
// Call function `f` with value `x`.
const callWith = (x, f) => f(x);
// Pipe value `x` through many single-argument functions in succession.
// This is kind of like a Unix pipe. The value of the previous function is
// passed to the next function, etc. Note that functions are called
// from left-to-right, with left being first.
export const pipe = (x, ...f) => reduce(f, callWith, x);
@gordonbrander
gordonbrander / memoize.py
Last active December 20, 2016 23:36
memoize.py
class Memoize:
"""
Memoize a function based on the arguments passed in. Example::
@Memoize
def foo(x, y): return x + y
"""
def __init__(self, f):
self.__function = f
self.__cache = {}
@gordonbrander
gordonbrander / phase_recipe.yml
Last active February 8, 2017 06:20
Phase Recipe
# Implementation ideas:
# run this past sentient to verify vector based approach is better than timeseries
# get better nutrient data from gen hydro catalogue
# run this past Arielle to see if this is a good default basil recipe
# check this against Dan's grow data to verify this is a good default basil recipe
# evaluate plausability of auto-generating this recipe format from Dan's grow data
# run this past x10 people on the team to see if this is an intuitive way to create recipes
# ask people on the forum if they like this method of creating recipes?
# Why is this idea interesting?
@gordonbrander
gordonbrander / general_greens.json
Last active February 9, 2017 09:22
General Greens
{
"_id": "general_greens",
"recipe_format": "phased",
"version": "1.0",
"optimization": [
"general purpose"
],
"date_created": "2017-02-08",
"author": "openag",
"stages": [