Add an element to an indexed object, mutating it. Returns object.
add = (indexed, item) ->
Array.prototype.push.call(indexed, item)
indexed
Generic reduction over anything. This will come in handy for iterating
// 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 |
/* | |
This document has been created with Marked.app <http://markedapp.com>, Copyright 2011 Brett Terpstra | |
Please leave this notice in place, along with any additional credits below. | |
--------------------------------------------------------------- | |
Title: Highlighter | |
Author: Gordon Brander http://gordonbrander.com | |
Description: Minimal theme with careful typographic scale and highlighed bold. | |
*/ | |
/* http://retinart.net/typography/typographicscale/ */ | |
html { |
/* | |
n-vector.js | |
Copyright (c) 2014 Gordon Brander | |
Released under the MIT license | |
http://opensource.org/licenses/MIT | |
Generic, efficient JavaScript vector math using ordinary arrays | |
or indexed objects. |
function id(x) { | |
return x; | |
} | |
// Memoize a function -- creates a new function that will cache the results of | |
// the first return by serializing inputs as a key. | |
// | |
// * `fn`: the function to be memoized. | |
// * `hash`: a function to create the cache key. | |
// * `out`: a function to process memoized data on the way out. Useful if you need |
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); |
// KV.js | |
// Hash iteration functions | |
// Set a value on an object at field, returning object. | |
function set(object, key, value) { | |
// Set value on object at key. | |
object[key] = value; | |
// Return object. | |
return object; | |
} |
// Foldable.js | |
// ============================================================================= | |
// | |
// Fold DOM elements based on whether they match a query string. | |
// | |
// How: | |
// | |
// var foldableParagraphs = document.querySelectorAll('p.foldable'); | |
// foldable(foldableParagraphs) | |
// |
// Microrouter based on history.pushState. | |
// All thrills, no frills. | |
// Usage: | |
// | |
// var h = urlstate(callback); | |
// h.push('#foo') | |
function urlstate(callback) { | |
// Since `history.pushState` doesn't fire `popstate`, we can use this function | |
// instead. Will update history state and call `callback` with currently | |
// showing `url`. |
// Returns an array of all indexes at which `pattern` can be found in `string`. | |
function indexesOf(string, pattern) { | |
var i = -1; | |
var indexes = []; | |
// We mutate `i` in place with the result of `indexOf`. We also use the last | |
// value of `i + 1` to continue seeking from. Any index found is pushed into | |
// the `indexes` array. If we ever get `-1` as the result of `indexOf`, we | |
// stop looping. | |
while((i = string.indexOf(pattern, i + 1)) !== -1) indexes.push(i); | |
return indexes; |