Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
gordonbrander / vendor_all_the_firmware.py
Last active March 24, 2017 15:11
Vendor all openag firmware in one fell swoop
"""
This script fetches the latest master of all of the openag firmware repositories, then removes the `.git`, etc.
"""
import subprocess
import argparse
from os import path
LIBS = set((
"https://github.com/OpenAgInitiative/openag_firmware_module.git",
"https://github.com/OpenAgInitiative/rosserial_arduino_libs.git",
@gordonbrander
gordonbrander / smd.js
Last active September 3, 2017 05:16 — forked from anonymous/smd.js
(function(exports) {
var modules = {}
var factories = {}
// Require a module by id.
function require(id) {
if (!(id in factories)) throw Error(id + ' module is not defined')
if (!(id in modules)) {
modules[id] = {}
factories[id](require, modules[id])
@gordonbrander
gordonbrander / min-event-behavior.js
Last active August 21, 2018 11:57
Minimal FRP events and behaviors
// Minimal FRP Behaviors and Events.
// An event function is any function of shape `function (next) { ... }` where
// `next(value)` is a callback to be called by event function. Transformations
// of event are accomplished by wrapping event with another event function,
// and consuming original event within (CPS).
// A behavior is any function of shape `function (time) { ... }`, where
// `time` is current time. Behaviors may capture state, return value from time,
// or be constant. Behaviors must always return a value, but value may
@gordonbrander
gordonbrander / event-delegate.js
Last active October 16, 2018 07:11
addEventDelegate() - easy event delegation
// Copyright 2018 Gordon Brander
// Released under MIT License https://opensource.org/licenses/MIT
const closest = (el, selector) =>
el.closest ? el.closest(selector) : null;
/**
* Delegate event handling to a parent element.
* @arg {Element} el - the parent element that we will be delegating handling to.
* @arg {string} selector - CSS selector of elements that should receive events.
@gordonbrander
gordonbrander / tolstoy-confession-epilogue.md
Last active February 21, 2019 01:45
Tolstoy, A Confession (Epilogue)

Leo Tolstoy, A Confession — Epilogue

Here is the dream: I see that I am lying in bed. Feeling neither good nor bad, I am lying on my back. But I begin to wonder whether it is a good thing for me to be lying there; and it seems to me that there is something wrong with my legs; whether they are too short or uneven, I do not know, but there is something awkward about them. As I start to move my legs, I begin to wonder how and on what I am lying, something that up till now had not entered my mind. Looking about my bed, I see that I am lying on some cords woven together and attached to the sides of the bed. My heels are resting on one of the cords and my lower legs on another in an uncomfortable way.

Somehow I know that these cords can be shifted. Moving one leg, I push away the furthest cord. It seems to me that it will be more comfortable that way. But I have pushed it too far away; I try to catch it, but this movement causes another cord to slip out from under my legs, leaving them hanging down. I rearran

@gordonbrander
gordonbrander / hollywood-vs-sw.md
Last active July 21, 2019 20:12
Hollywood vs Software
@gordonbrander
gordonbrander / contract.js
Last active February 10, 2020 18:45
Racket-style contracts code sketch
// Simple runtime type checking.
export class ContractViolation extends Error {}
export const contract = predicate => value => {
if (predicate(value)) {
return value
} else {
throw new ContractViolation(
`Contract violation. Expected ${predicate}. Given ${value}.`
)
@gordonbrander
gordonbrander / 1d-spring.js
Created June 3, 2014 20:31
1D Spring integration
function dampenedHookeForce(displacement, velocity, stiffness, damping) {
// Hooke's Law -- the basic spring force.
// <http://en.wikipedia.org/wiki/Hooke%27s_law>
//
// F = -kx
//
// Where:
// x is the vector displacement of the end of the spring from its equilibrium,
// k is a constant describing the tightness of the spring.
var hookeForce = -1 * (stiffness * displacement);
@gordonbrander
gordonbrander / starting.yaml
Created May 12, 2019 00:29
Starting - creative prompts
# Prompts for beginning new projects
start:
- "#5ps#"
- "#heart#"
- "#disirability_feasibility_viability#"
- "#practical_step#"
- "#build#"
- "#story#"
- "#ooda#"
@gordonbrander
gordonbrander / accumulators.js
Last active December 26, 2020 08:26
Accumulators -- a tiny JavaScript implementation of Clojure's reducers.
// Accumulators
// =============================================================================
//
// A tiny library for reactive programming that offers blazing fast generic
// collection manipulation, asyncronous flow control and the ability to
// represent infinitely large collections.
//
// Copyright Gordon Brander, 2013. Released under the terms of the [MIT license](http://opensource.org/licenses/MIT).
//
// Background: