Skip to content

Instantly share code, notes, and snippets.

(function(d){
console.log("Wrapping dojo.connect/subscribe");
var dc = d.connect,
ddc = d.disconnect,
ds = d.subscribe,
dus = d.unsubscribe,
uniqueHandleId = 0,
handleIds = {};
var handleData = { connect: 0, disconnect: 0, subscribe: 0, unsubscribe: 0 };
d.connect = function() {
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Lazy Widgets</title>
<link id="themeStyles" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css">
<!-- required: dojo.js -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
(function(d){
console.log("Wrapping dojo.connect/subscribe");
var dc = d.connect,
ddc = d.disconnect,
ds = d.subscribe,
dus = d.unsubscribe,
uniqueHandleId = 0,
handleIds = {};
var handleData = { connect: 0, disconnect: 0, subscribe: 0, unsubscribe: 0 };
dojo.provide("myns.data.FeedStore");
dojo.require("dojox.data.ServiceStore");
dojo.require("dojox.rpc.Service");
dojo.declare("myns.data.FeedStore", dojox.data.ServiceStore, {
// summary:
// Flexible, extensible store for normalizing read-only JSON feed data
service: null,
@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
@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 / 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 / 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 / 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: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 = '';