Skip to content

Instantly share code, notes, and snippets.

@jabney
jabney / micro-reselect.js
Last active January 22, 2020 20:25
micro-reselect: memoize a function based on the state passed to it (mimics reselect npm module)
/**
* Implement a simplified createSelector function mimicking the reselect module.
*
* Memoizes the result of a function called with a state object as its argument.
* The given function is only called when state values change.
*/
/**
* A resolver returns a value from a state object (key/value pairs).
*
@jabney
jabney / PriorityQueue.js
Last active September 17, 2017 17:53
A heap-based priority queue in JavaScript
// PriorityQueue.js MIT License © 2014 James Abney http://github.com/jabney
(function(ex) {
'use strict';
// ---------------------------------------------------------------
// PriorityQueue Constructor
// A heap-based priority queue.
// ---------------------------------------------------------------
ex.PriorityQueue = function PriorityQueue(compare) {
var compare = compare || function(a, b) { return a < b; },
@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 / 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 / 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 / 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);