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
/* | |
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 { |
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 |
// A message bus. Dispatches messages to `receive` in order (FIFO). | |
const Bus = (receive) => { | |
var isDraining = false; | |
const queue = []; | |
// Define a function to send a message to the queue. | |
const send = (msg) => { | |
queue.push(msg); | |
// If we're not already draining the queue, start draining. | |
// We only want to kick this loop off once, since send can be called |
var LiveCollection = (function (_, Backbone) { | |
var Collection = Backbone.Collection; | |
// Define a Backbone Collection handling the details of running a "live" | |
// collection. Live collections are expected to handle fetching their own | |
// data, rather than being composed from separate models. | |
// They typically add new models instead of resetting the collection. | |
// A custom add comparison makes sure that duplicate models are not | |
// added. End result: only new elements will be added, instead | |
// of redrawing the whole collection. | |
// |
var postModels = new Models(); | |
postModels.fetch(); | |
postModels.on('change', function (postModels) { | |
$('.post').models(postModels) | |
.render(function (model) { | |
$(this) | |
.find('.meta .author').html(model.prop('meta.author')).end() |
// Convert a function that does not use `this` context into a function that | |
// does. The category of information that was previously passed as the first | |
// parameter of the function is now its `this` context. | |
function toMethod(lambda) { | |
return function () { | |
var args = [this]; | |
var concat = args.concat; | |
// Spread arguments over arity of concat, since arguments is not a true array. | |
var combined = concat.apply(args, arguments); | |
return lambda.apply(null, combined); |
/* Creates a grid with a margins on either side of all units. To do the left-margin style of grid, change the .unit definition, subtracting 1 from the number of columns. */ | |
@context: 740px; | |
@col: 40px; | |
@gutter: 20px; | |
.unit(@cols) { | |
@target: (@cols * @col) + (@cols * @gutter); | |
width: 100% * (@target / @context); | |
} |
function uid() { | |
// Generate a unique and non-colliding id. | |
return Math.random().toString(36).slice(2); | |
} | |
// Create unique, non-colliding ID namespace. | |
var __id__ = uid(); | |
function idOf(thing) { | |
return (thing && typeof(thing) === ('object' || 'function')) ? |