Skip to content

Instantly share code, notes, and snippets.

View novemberborn's full-sized avatar

Mark Wubben novemberborn

View GitHub Profile
@novemberborn
novemberborn / gist:747439
Created December 19, 2010 16:13
HTTP response parsing errors are emitted from the client, not the response object
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 December 16, 2010 10:48
Closures inside for-loops
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(); }));
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
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){}
});
/*=====
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){
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(""));
});
});
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