Skip to content

Instantly share code, notes, and snippets.

Avatar

Gordon Brander gordonbrander

View GitHub Profile
@gordonbrander
gordonbrander / ruleset.example.js
Last active Aug 6, 2020
ruleset.js — parse style-attribute-like strings.
View ruleset.example.js
import {Schema, string, bool, number, listOf, optional, cssUnit4} from './ruleset.js';
const parse = Schema({
title: string,
isHidden: optional(bool, false),
numbers: listOf(number)
});
parse("title: 8 Beautiful Notes; numbers: 1, 2, 3, 4, 5, 6, 7, 8")
// > {title: "8 Beautiful Notes", numbers: [1, 2, 3...], isHidden: false}
@gordonbrander
gordonbrander / select.js
Last active Apr 16, 2018
select — sugarfree D3-style enter/update/exit DOM manipulation, using a simple function instead of method chaining
View select.js
// D3-style select-baed DOM updating.
//
// Rather than relying on jQuery-style method-chaining to update the DOM,
// we use a "view" object, an ordinary object that contains the following
// functions:
//
// - `enter(datum) -> Element` returns a DOM node for new elements.
// Element will be appended to parent.
// - `update(el, datum, old)` handles mutating an element in response to
// changes in data. `old` is the last-known data for this element.
@gordonbrander
gordonbrander / preload.js
Last active Apr 8, 2018
Preload images with promises
View preload.js
// Tip: use with await.
// const preloaded = await preloadAll(['img1.jpg', 'img2.jpg'])
export const preload = src => new Promise((resolve, reject) => {
const img = new Image()
img.onload = resolve
img.onerror = reject
img.src = src
})
View frame.js
// Promise for an animation frame.
// Tip: use with `await`.
export const frame = () => new Promise(requestAnimationFrame)
@gordonbrander
gordonbrander / dom.js
Last active Mar 26, 2020
Dom from simple VDOM
View dom.js
const dom = ({tag='div', attributes={}, styles={}, classes=[], text=null, children=null}) => {
const el = document.createElement(tag)
el.className = classes.join(' ')
for (let [key, value] of Object.entries(attributes)) {
if (value) {
el.setAttribute(key, value)
}
}
@gordonbrander
gordonbrander / hollywood-vs-sw.md
Last active Jul 21, 2019
Hollywood vs Software
View hollywood-vs-sw.md
@gordonbrander
gordonbrander / webvr-daydream.md
Last active Aug 20, 2018
How to get WebVR working with Daydream
View webvr-daydream.md

How to get WebVR working with your brand-new Daydream View & Pixel.

  1. Update Daydream app to latest (Play Store)
  2. Update Chrome app to latest (Play Store)
    • Tip: if you're feeling brave, download Chrome Canary instead. Better perf and new features.
  3. Update Google VR Services (Play Store)
  4. Open chrome://flags/#enable-webvr
    • Click "Enable"
  5. Open chrome://flags/#enable-vr-shell
    • Set dropdown to "Enabled"
@gordonbrander
gordonbrander / vendor_all_the_firmware.py
Last active Mar 24, 2017
Vendor all openag firmware in one fell swoop
View vendor_all_the_firmware.py
"""
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",
View general_greens.json
{
"_id": "general_greens",
"recipe_format": "phased",
"version": "1.0",
"optimization": [
"general purpose"
],
"date_created": "2017-02-08",
"author": "openag",
"stages": [
View 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 = {}