Skip to content

Instantly share code, notes, and snippets.

@sfoster
sfoster / gist:1267150
Created October 6, 2011 11:07
Identify unlabelled inputs on the page (wcag2) (uses dojo)
(function(){
// usage:
// dojo.create("script", { src: 'https://raw.github.com/gist/1267150/b786273d696a119bba26c4590b1608aa9a21755f/gistfile1.txt?'+(new Date).getTime(), type: 'text/javascript' }, dojo.query("head", document.documentElement).shift())
var labelMap = {};
dojo.query("label[for]").forEach(function(lbl) {
labelMap[lbl.htmlFor]=lbl;
});
console.log("labelMap: ", labelMap);
var selector = [
"input[type=text]",
define(['compose'], function(Compose){
var cache = {};
exports = Compose(Compose, function(){
var id = this.id = MyClass.nextId();
cache[id] = {};
}, {
someMethod: function(){
var id = this.id,
@sfoster
sfoster / gist:1197446
Created September 6, 2011 12:43
node jsonp wrapper for static json files
var express = require("express"),
jsonp = require("connect-jsonp"),
path = require('path'),
argv = require('optimist').argv;
// delegation the way I like it
var delegate = function(proto, mixin){
var o = Object.create(proto);
if(mixin){
@sfoster
sfoster / SceneSpec.js
Created August 12, 2011 23:43
Jasmine + AMD
define(['lib/Scene'], function(Scene){
describe("Scene", function() {
var scene;
beforeEach(function() {
scene = new Scene();
});
it("should instantiate ok", function() {
@sfoster
sfoster / gist:1128716
Created August 5, 2011 22:51
hooking up xml2json to convert XML piped in via stdin to JSON on stdout
// hooking up xml2json to convert XML piped in via stdin to JSON on stdout
// e.g.:
// curl http://www.gutenberg.org/feeds/today.rss | node index.js > gutenberg.json
var x2j = require("xml2json");
process.stdin.resume();
process.stdin.setEncoding('utf8');
var xml = '';
@sfoster
sfoster / fileWizard.js
Created July 8, 2011 12:06
Wizard-style prompts from node.js
/**
* Module dependencies.
*/
var fs = require('fs'),
path = require('path');
spawn = require('child_process').spawn,
exec = require('child_process').exec;
@sfoster
sfoster / gist:1018660
Created June 10, 2011 11:36
Screenshot sequence w. node.js and screencapture
(function(){
var sys = require('sys');
var filestem = process.ARGV.length > 2 ? process.ARGV.length[2] : "screen";
var spawn = require('child_process').spawn,
timer = null,
startTime, stopTime;
function outfile(d) {
@sfoster
sfoster / gist:1018071
Created June 10, 2011 00:56
perl script to extract tab delimited entries from Firebug's ConsoleExport html output
#!/usr/bin/perl
# quick, throwaway script to extract out info messages from the HTML dump of the
# firebug console which is produced by the ConsoleExport Firefox/Firebug
# plugin.
# I was interested in info message of the form.. so its pretty specific
# console.info("some label:87ms", 113, 200);
# TODO provide a way to extract log/warn/info/error/all entry types
@sfoster
sfoster / simple mocking
Created April 6, 2011 17:09
Simple mechanism for temporarily replacing a method's implementation e.g. for mocking during tests
var mockMethod = function(obj, methName, fn) {
var orig = obj[methName];
var handle = [obj, methName, orig];
obj[methName] = fn;
return handle;
}, unMockMethod = function(handle) {
handle[0][handle[1]] = handle[2];
};
// usage:
@sfoster
sfoster / getValue snippet
Created January 4, 2011 10:13
dojo.data store (e.g. ServiceStore extension) getValue method implementation that allows mapping of attribute names to potentially deep properties
getValue: function(/*Object*/ item, /*String*/property, /*value?*/defaultValue){
// summary:
// Gets the value of an item's 'property'
//
// item:
// The item to get the value from
// property:
// property to look up value for
// defaultValue:
// the default value