Skip to content

Instantly share code, notes, and snippets.

James Abney jabney

Block or report user

Report or block jabney

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jabney
jabney / micro-reselect.js
Last active Jan 22, 2020
micro-reselect: memoize a function based on the state passed to it (mimics reselect npm module)
View micro-reselect.js
/**
* 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 / micro-react-redux.js
Last active Jan 22, 2020
micro-react-redux: a minimal implementation of react-redux style provider and connect function
View micro-react-redux.js
/**
* Minimal implementation of react-redux style provider and connect function.
*/
import React, { useState, useEffect, useContext } from 'react'
const StoreContext = React.createContext(null)
/**
* Wraps root component for providing store context, e.g.,
*
@jabney
jabney / micro-redux.js
Last active Jan 22, 2020
micro-redux: a minimal implementation of Redux createStore, with thunkish behavior added in
View micro-redux.js
/**
* 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 Jan 22, 2020
micro-subject: provide basic subscribe/notify/unsubscribe functionality in a dozen or so lines of code
View micro-subject.js
/**
* 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
keyframeInterplation function using binary search
View keyframeInterpolateBinary.js
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
Binary search with comparator
View binary-search.js
// 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
}
View case_loader.py
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 Aug 29, 2015
Javascript function to return post-transform coordinates of an element.
View post-transform-coords.js
// 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 Aug 29, 2015
JavaScript Factory Inheritance
View factory-inheritance.js
(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 Aug 29, 2015
Python utility for converting Font Awesome cheatsheet to a JSON file
View gen_fontawesome.py
"""
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
You can’t perform that action at this time.