Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Wubben novemberborn

View GitHub Profile
@novemberborn
novemberborn / gist:747439
Created Dec 19, 2010
HTTP response parsing errors are emitted from the client, not the response object
View gist:747439
require("net").createServer(function(stream){
stream.end("INVALID\r\n\r\nhttp");
}).listen(8080, "127.0.0.1");
require("http").createClient(8080, "127.0.0.1")
.on("error", function(err){
console.error("Client error\n%s", err.stack);
})
.request("GET", "/", {}).on("response", function(){ console.log("Got response"); });
@novemberborn
novemberborn / gist:743278
Created Dec 16, 2010
Closures inside for-loops
View gist:743278
var results = [];
for(var i = 0; i < 10; i++){
// Bad:
// results.push(function(i){ return i; });
// 'Good':
results.push((function(i){
return function(){ return i; };
})(i));
}
console.log(results.map(function(f){ return f(); }));
View gist:615171
var s = "string";
String.prototype.testEqual = function(){ return this == s; };
String.prototype.testStrict = function(){ return this === s; };
s.testEqual(); // true
s.testStrict(); // false
s = new String(s);
s.testEqual(); // true
View gist:494358
var Observer = dojo.extend(function(){}, {
observe: function(promise){
this.onStart(promise);
promise.then(dojo.hitch(this, "onEnd"));
return promise;
},
onStart: function(promise){},
onEnd: function(result){}
});
View gist:489854
/*=====
eqmx._base.__decoratorArgs = function(){
// $decorator: Function?
// Called just before the decorator is applied. May return `false`,
// in which case the decoration is aborted.
this.$decorator = $decorator;
};
=====*/
eqmx.decorate = function(/*Function*/constructor, /*eqmx._base.__decoratorArgs*/decorator){
View gist:295246
client = require("http").createClient(443, "twitter.com");
client.setSecure("X509_PEM");
client.request("GET", "/statuses/public_timeline.xml", { host: "twitter.com" }).finish(function(response){
var chunks = [];
response.setBodyEncoding("utf8");
response.addListener("body", function(c){ chunks.push(c); });
response.addListener("complete", function(){
require("sys").puts(chunks.join(""));
});
});
View gist:295235
Checking for program g++,c++ : ok /usr/bin/g++
Checking for program cpp : ok /usr/bin/cpp
Checking for program ar : ok /usr/bin/ar
Checking for program ranlib : ok /usr/bin/ranlib
Checking for g++ : ok
Checking for program gcc,cc : ok /usr/bin/gcc
Checking for gcc : ok
Checking for library dl : ok
Checking for library execinfo : not found
Checking for gnutls >= 2.5.0 : ok