Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
// If you already have a Prototype dependency, see
//
// http://www.prototypejs.org/api/hash/toQueryString
var toQueryString = function(hash) {
var s = "";
for (var k in hash) if (hash.hasOwnProperty(k)) {
if (s !== "") { s += "&"; }
foreach (debug_backtrace() as $f) {
printf("%s:%d: %s\n", $f["file"], $f["line"], $f["function"]);
}
function generate($consumer_key, $consumer_secret, $method, $url, $args) {
// http://oauth.net/core/1.0/#encoding_parameters
$encode = function($s) {
return str_replace("%7E", "~", rawurlencode($s));
};
// As described in section 9.1.3 of the spec, we need to take the hash of
// three strings:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- XPath expression to return album given track from "iTunes Music Library.xml" -->
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:value-of select="//key[text() = 'Name'][following-sibling::*[1][text() = 'The Girl You Lost to Cocaine']]/../key[text() = 'Album']/following-sibling::*[1]"/>
</xsl:template>
var events = require('events'), sys = require('sys');
var emitter = new events.EventEmitter();
function fn1() {
sys.debug("in fn1");
emitter.addListener("foo", fn2);
// emitter.removeListener("foo", fn1);
}
var events = require('events'), sys = require('sys');
var emitter = new events.EventEmitter();
function fn1() {
sys.debug("in fn1");
emitter.addListener("foo", fn2);
process.nextTick(function() {
emitter.removeListener("foo", fn1);
});
From 9c2cdf7f751ce4b463e02f8426df3af6fd05444b Mon Sep 17 00:00:00 2001
From: Michael Stillwell <mjs@beebo.org>
Date: Tue, 9 Feb 2010 22:32:52 +0000
Subject: [PATCH] Add test: modifying event listeners during callback.
---
test/mjsunit/test-event-emitter-modify-in-emit.js | 32 +++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
create mode 100644 test/mjsunit/test-event-emitter-modify-in-emit.js
function add(i, j) {
return i + j;
}
Function.prototype.continuation = function() {
arguments[arguments.length - 1](
this.apply(this, Array.prototype.slice.call(arguments, 0, arguments.length - 1))
);
}
From 5c1b089a11c900c9345c798887e59056f215af43 Mon Sep 17 00:00:00 2001
From: Michael Stillwell <mjs@beebo.org>
Date: Mon, 22 Feb 2010 23:33:17 +0000
Subject: [PATCH] Enhance http.createServer() so that if multiple functions are provided as
arguments, each function is added as a request listener. i.e.
http.createServer(m1, m2);
will arrange for both m1 and m2 to be called and passed request and response
objects when a request is received.
From 69137a18824722581fbd57c13f7ffd4cf56555f1 Mon Sep 17 00:00:00 2001
From: Michael Stillwell <mjs@beebo.org>
Date: Tue, 23 Feb 2010 08:14:36 +0000
Subject: [PATCH] Test: Multiple listeners for http.Server's "request" event.
---
test/mjsunit/test-http-multi-listener.js | 44 ++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
create mode 100644 test/mjsunit/test-http-multi-listener.js