Skip to content

Instantly share code, notes, and snippets.

(function () {
if (document.getElementById('edit-keys-3-wrapper')) {
var query = window.location.search.substring(1);
if(/^keys/.test(query))
document.getElementById('edit-keys-3').value = query.substring(query.indexOf('=') + 1, (query.indexOf('&') == -1 ? query.length : query.indexOf('&'))).replace(/\+/g, ' ');
}
}());
@nfeldman
nfeldman / gist:1128011
Created August 5, 2011 17:16
datauri for a generic ajax spinner
/* there's nothing special or interesting about this, I just need a place to store it and a gist seemed as good as any */
.loading {
background: url(data:image/gif;base64,R0lGODlhHgAeAPf2AP7+/v39/fDw8O/v7/z8/PHx8e7u7vv7++Xl5fr6+vn5+ebm5gAAAPX19fT09Pb29vPz8/f39/j4+Ofn5/Ly8tTU1O3t7dXV1cnJyezs7Ojo6Orq6uTk5OPj476+vuvr69nZ2cjIyNbW1unp6crKytjY2MvLy9zc3LOzs7KyssfHx+Hh4b+/v9/f3+Li4tPT097e3sDAwNfX193d3dra2sHBwYmJidvb2+Dg4L29vby8vM/Pz7e3t9LS0sTExNDQ0LS0tIiIiLW1tcbGxszMzLi4uLq6uoyMjHBwcMPDw8XFxVhYWLGxsXFxccLCws7Ozra2trCwsG9vb42Njbm5uc3NzXNzc4qKilpaWtHR0bu7u3JycpKSkjs7O3Z2dq+vr66urj09PVlZWaioqKSkpISEhIKCgpqaml5eXnR0dJGRkSIiIltbW2lpaaWlpYaGhouLi1NTUz4+PqmpqXh4eI6OjpWVlZCQkJSUlJ6enpiYmJycnKqqqmpqakNDQ4eHh6Kiop+fn6ysrCUlJW5ubklJSa2trVRUVIODg4WFhUBAQCAgIKGhoV9fX0FBQYGBgaamppaWlmxsbFxcXGBgYFdXV5OTk5mZmTY2NiQkJB8fH21tbXl5eVBQUDw8PHt7ez8/P11dXX9/fzU1NSgoKJubm2dnZzQ0NDMzM52dnVFRUWtra5eXlyoqKk5OTiMjI1VVVQoKCmRkZE1NTaurq0ZGRjk5OTc3N35+fo+Pj0VFRX19fSEhISkpKURERBsbGywsLCcnJ6enpxgYGB4eHmJiYlJSUhoaGk9PT3V1dWFhYR0dHUdHRwUFBQcHBzg4
@nfeldman
nfeldman / gist:1133214
Created August 9, 2011 01:14
PathActions
/**
* @fileoveriew A very rough sketch for location hooks (or location based
* events) system to simplify and structure tying multiple functions to a path.
* Can be triggered conditionally by binding init() to an event handler or
* on page load. This is version 0.1, so it doesn't do much, but it does
* handle wildcards. Examples of use are provided at the end of this gist
* TODO convert console copy/paste tests to unit tests
* TODO test in IE
* TODO create repo for this project
* @version 0.1
@nfeldman
nfeldman / gist:1157984
Created August 19, 2011 20:56
genericish implementation of a block toggling script for Drupal
/**
* @fileoverview, written for my own amusement, these few lines make a robust
* replacement for the first 340ish lines found within the jQuery on ready
* handler in the main.js file on the new site. This is fine as a standalone,
* but there are redundancies if this is used with the other scripts I've
* contributed to this project. If used, the duplication should be fixed.
* @author Noah Feldman
* updated 2011-08-22: removed superfluous semicolon
*/
// PUT THIS IN THE `$(document).ready(function () {` IN main.js
@nfeldman
nfeldman / gist:1190459
Created September 3, 2011 02:47
demonstration of function composition using Fortinbras components
/**
* Standalone demonstration of function composition using Fortinbras components
* Paste into a browser console and run. (Bonus demo: safe use of ASI)
* @author Noah Feldman
*/
// basic compose looks like: compose(f, g) (x) = f(g(x))
// or: apply argFunc to the arguments, then apply func to the result
// mine does the same thing, but let's us supply extra arguments
function compose (func, argFunc, thisObj) {
@nfeldman
nfeldman / LICENSE.txt
Created September 6, 2011 04:50 — forked from jed/LICENSE.txt
polyfill requestAnimationFrame across browsers
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@nfeldman
nfeldman / gist:1202166
Created September 7, 2011 23:37
hydrate a javascript object from a string
// this is a quick function that may be useful to someone aside from myself. 'Hydrate' might not be the best choice
// of words, but it comes close. This takes a '.' delimited string (and optionally an existing object) and builds
// the javascript object it represents. It was originally declared inside a IIFE where U was an unused property and
// therefore guaranteed to be undefined, so I've wrapped it in one here, too.
(function (G, U) {
function hydrateObject (obj, prop) { // obj is optional
var levels, len, ret;
if (prop === U && typeof obj == 'string') {
prop = obj;
@nfeldman
nfeldman / LICENSE.txt
Created September 24, 2011 02:14 — forked from jed/LICENSE.txt
use cached DOM elements to escape HTML
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@nfeldman
nfeldman / getNestedObject.js
Created September 24, 2011 03:38
pluck an object from an array
/**
* required by pluckObjectByKey can be handy if you're dealing with JavaScript written by Java devs
* they like long.strings.with.dots.in.them.
*/
function getNestedObject (obj, path) {
var nest, len;
if (path) {
nest = path.split('.').reverse();
len = nest.length;
while (len--) {
@nfeldman
nfeldman / simplePrettyJson.js
Created October 26, 2011 00:42
basic JSON prettify
function simplePrettyJson (str) {
var stack = [], // collect all tokens
word = [], // accumulator to build tokens of more than one char, like an object's keys.
// Not strictly needed but could be useful if we ever allow callbacks
ws = '',
tab = ' ', // 3 spaces are standard and 2 are trendy, but 4 are readable
depth = 0,
inquotes = false,
curr, next, prev;