Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
gordonbrander / boing.js
Last active November 6, 2022 07:34
boing.js (second pass)
// Create a spring object.
export const Spring = (curr, prev, dest, stiffness, damping) => ({
curr, // The current position of spring
prev, // The position of spring at previous tick
dest, // The destination of spring
stiffness, // How hard it springs back
damping, // Friction. 1.0 means no bounce.
});
// Given numbers, calculate the next position for a spring.
@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 / htmlin5.md
Last active November 6, 2022 07:36
HTML in 5 min

HTML in 5 min

The gist

  • HTML is just plain text.
  • You write it in any text editor. Be careful, though! Programs like Microsoft Word will trick you. They look like plain text, but they are not. I suggest using something like TextWrangler. It saves plain text, but also helpfully color-codes your code.
  • You save HTML in a text file, but instead of giving it a .txt extension, you give it a .html.

Tags

@gordonbrander
gordonbrander / multimethod-example.js
Last active November 18, 2022 05:05
Javascript multimethods
import multimethod from './multimethod.js'
const foo = multimethod(x => typeof x)
foo.string = x => 'called string method'
foo.number = x => 'called number method'
foo('x')
// 'called string method'
foo(1)
@gordonbrander
gordonbrander / multimethods.lua
Last active August 29, 2023 14:34
Lua multimethods
--[[
Lua multimethods. Inspired by Clojure's multimethods.
How to use it:
local Multi = require('multimethods')
-- Create a new multimethod and use isa as dispatch function.
-- This will dispatch on first argument by type.
local foo = Multi.create(isa)
@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
],
[
@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 / 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 / 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": [