Skip to content

Instantly share code, notes, and snippets.

Avatar

Gordon Brander gordonbrander

View GitHub Profile
View gordonbrander-highlighter.css
/*
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 {
View memoize.js
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 / kv.js
Last active Aug 29, 2015
KV: key-value iteration functions for JavaScript
View kv.js
// 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;
}
@gordonbrander
gordonbrander / foldable.litcoffee
Last active Aug 29, 2015
Foldable -- fold elements based on textContent matches
View foldable.litcoffee

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 / foldable.js
Last active Aug 29, 2015
Foldable -- fold elements based on search strings in hash
View foldable.js
// Foldable.js
// =============================================================================
//
// Fold DOM elements based on whether they match a query string.
//
// How:
//
// var foldableParagraphs = document.querySelectorAll('p.foldable');
// foldable(foldableParagraphs)
//
@gordonbrander
gordonbrander / indexesof.js
Created Jul 18, 2014
indexesOf: collect all indexes of pattern found in string.
View indexesof.js
// 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;
@gordonbrander
gordonbrander / hashtext.js
Last active Aug 29, 2015
Hashtext: twitter-style text rendering for Node and the web. Moved here https://github.com/gordonbrander/hashtext.
View hashtext.js
// Hashtext: the no-markup markup language.
// Quick-and-dirty Twitter-style text rendering.
//
// * Auto-paragraphatize and linebreak newlines.
// * Auto-link URLs (and prettify them, too).
// * Expand #hashtags into something useful (your choice).
//
// Copyright (c) 2014 Gordon Brander.
// Released under the MIT license http://opensource.org/licenses/MIT.
//
View domconstruct.js
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
Pull structured content out of the DOM.
- Hero images
- Title
- Summary
@gordonbrander
gordonbrander / states.js
Created Jul 16, 2015
Finite state switcher
View states.js
// Create a finite state switching function.
// Given a list of states, returns a function that will take a `prev` state
// and `next` state and will only advance state to `next` if it is one of
// the defined states.
const states = (...states) => (prev, next) =>
states.indexOf(next) !== -1 ? next : prev;
View css-namespace.js
/*
Automatically namespace all CSS selectors.
Eliminates most problems with style leak
.active {}
...becomes
.button-active {}
*/
You can’t perform that action at this time.