Skip to content

Instantly share code, notes, and snippets.

@jabney
jabney / micro-redux.js
Last active February 15, 2024 17:03
micro-redux: a minimal implementation of Redux createStore, with thunkish behavior added in
/**
* Minimal implementation of Redux createStore, with thunkish behavior.
*/
import subject from './micro-subject' // see micro-subject.js gist
/**
* @template T
* @typedef {import('./subject').Subject<T>} Subject
*/
/**
@jabney
jabney / micro-subject.js
Last active February 15, 2024 17:03
micro-subject: provide basic subscribe/notify/unsubscribe functionality in a dozen or so lines of code
/**
* Provide basic subscribe/notify/unsubscribe functionality in a
* dozen or so lines of code.
*/
/**
* @template T
* @typedef {(value?: T) => void} ObserverFn
*/
@jabney
jabney / keyframeInterpolateBinary.js
Created May 6, 2017 15:42
keyframeInterplation function using binary search
function keyframeInterpolate(keyframes, time, timing, lib) {
const first = 0
const last = keyframes.length - 1
// Clamp time to [0, 1]
time = Math.max(Math.min(time, 1), 0)
if (!Array.isArray(keyframes) || !keyframes.length) {
return lib.zero()
}
@jabney
jabney / binary-search.js
Last active May 6, 2017 02:04
Binary search with comparator
// The default comparator is for any values that can be
// compared with '==', '<', '<=', '>', '>='.
function defaultComparator(candidate, target) {
if (target < candidate) {
return -1
} else if (target > candidate) {
return 1
} else {
return 0
}
import os
import re
import gzip
import base64
import json
from glob import glob
from argparse import ArgumentParser
from KnoDB.crawler.scc import case_parser
from KnoDB.crawler import bcca
@jabney
jabney / post-transform-coords.js
Last active August 29, 2015 14:23
Javascript function to return post-transform coordinates of an element.
// Return the post-transform coords of an element,
// assuming that proper pre-transform coords are supplied.
function getElementCoords(element, coords) {
var ctm = element.getCTM(),
xn = ctm.e + coords.x*ctm.a,
yn = ctm.f + coords.y*ctm.d;
return { x: xn, y: yn };
};
var circle = document.getElementById('svgCircle'),
@jabney
jabney / factory-inheritance.js
Last active August 29, 2015 14:22
JavaScript Factory Inheritance
(function() {
'use strict';
// Create a factory function (a function that returns an object).
function aFactory() {
// Create a data store.
var _data = [];
// Add supplied arguments to the data store.
if (arguments.length)
@jabney
jabney / gen_fontawesome.py
Last active August 29, 2015 14:21
Python utility for converting Font Awesome cheatsheet to a JSON file
"""
Generate fontawesome icon set in JSON format from website cheatsheet.
http://fortawesome.github.io/Font-Awesome/cheatsheet/
Usage: python gen_fontawesome.py
Output: font-awesome.json
{icon_name: entity_reference, ...}
Author: James Abney
Date: 2015-05-21
@jabney
jabney / font-awesome.json
Created May 22, 2015 03:57
Font Awesome JSON Entity Reference
{"cc": "&#xf20a;", "bookmark": "&#xf02e;", "venus-mars": "&#xf228;", "arrow-circle-o-down": "&#xf01a;", "comment-o": "&#xf0e5;", "long-arrow-left": "&#xf177;", "arrow-right": "&#xf061;", "delicious": "&#xf1a5;", "chevron-circle-left": "&#xf137;", "bullhorn": "&#xf0a1;", "outdent": "&#xf03b;", "jpy": "&#xf157;", "drupal": "&#xf1a9;", "hdd-o": "&#xf0a0;", "hand-o-left": "&#xf0a5;", "pinterest": "&#xf0d2;", "plane": "&#xf072;", "question": "&#xf128;", "child": "&#xf1ae;", "circle-o": "&#xf10c;", "italic": "&#xf033;", "meanpath": "&#xf20c;", "subway": "&#xf239;", "google-plus": "&#xf0d5;", "angle-up": "&#xf106;", "star": "&#xf005;", "star-half-empty": "&#xf123;", "facebook-official": "&#xf230;", "youtube-square": "&#xf166;", "rss": "&#xf09e;", "toggle-off": "&#xf204;", "list-ol": "&#xf0cb;", "dot-circle-o": "&#xf192;", "copyright": "&#xf1f9;", "user": "&#xf007;", "key": "&#xf084;", "minus-square-o": "&#xf147;", "mobile": "&#xf10b;", "table": "&#xf0ce;", "columns": "&#xf0db;", "bolt": "&#xf0e7;", "fighter-jet": "&
@jabney
jabney / augment.js
Last active August 29, 2015 14:19
Javascript augmentation pattern for a factory method
// This augmentation style is appropriate for a factory-style function,
// which might be something that was imported as part of a library.
var factory = function factory() {
var data = [];
// Return an object with one or more methods.
return {
init: function() {
data.push.apply(data, arguments);