Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
gordonbrander / gordonbrander-highlighter.css
Last active August 29, 2015 13:56
Highlighter for Markdown
/*
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
@gordonbrander
gordonbrander / foldable.litcoffee
Last active August 29, 2015 14:03
Foldable -- fold elements based on textContent matches

Basic stuff

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

@gordonbrander
gordonbrander / bus.js
Last active September 4, 2015 22:26
Simple app microframework based on a message bus
// 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
@gordonbrander
gordonbrander / LiveCollection.js
Created December 27, 2011 19:40
Backbone Live Collections w/ Streaming and Automatic Duplicate Handling
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.
//
@gordonbrander
gordonbrander / statelessview.js
Created May 9, 2012 16:33
Potential Kicks Controller/View API
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()
@gordonbrander
gordonbrander / tomethod-toLambda.js
Created July 12, 2012 17:05
toMethod and toLambda - higher order helpers for codebases that use both functional and OOP styles
// 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);
@gordonbrander
gordonbrander / grid.less
Created August 31, 2012 23:21
Flexible Grid factory in Less
/* 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);
}
@gordonbrander
gordonbrander / user-testing-script.markdown
Created September 12, 2012 20:53
User Testing Think Aloud Script

Preparation

  • Print a copy of wireframes to use as paper prototypes
  • Sharpie marker

Tip: You can use Photo Booth or iMovie to record video/audio from your Mac.

What is the job-to-be-done for this script?

@gordonbrander
gordonbrander / idOf.js
Last active December 14, 2015 06:29 — forked from anonymous/idOf.js
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')) ?