Skip to content

Instantly share code, notes, and snippets.

View novemberborn's full-sized avatar

Mark Wubben novemberborn

View GitHub Profile
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
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(""));
});
});
/*=====
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){
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){}
});
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
@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(); }));
@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:899634
Created April 2, 2011 16:46
Convert pasteboard string into JSON
#!/usr/bin/env node
require("child_process").exec("pbpaste", function(_, stdout){
process.stdout.write(JSON.stringify(stdout.trim()));
});
@novemberborn
novemberborn / Activate Terminal.scpt
Created June 26, 2011 18:00
Focus the terminal window open in the current space, or open a new one.
tell application "Terminal"
activate
set hasWindow to false
try
repeat with theWindow in windows
if (frontmost of theWindow) then
set hasWindow to true
end if
end repeat
end try
@novemberborn
novemberborn / zed.js
Created July 20, 2011 17:28
widgets/zed
// Supported modes:
// * non-modal (like dijit/popup, default)
// * modal (like dijit/Dialog)
// * underlay (like dijit/Dialog, off by default, specify underlay widget)
// * allowTab (TAB goes through the widget, off by default)
// * lockFocus (prevent TAB from going out of widget, by default on for modal, off for non-modal)
// * cancelOnEsc (close when ESC is hit, on by default)
// * cancelOnBlur (close when widget is blurred, on by default)
// Also supports `around`, `orient`, `x` and `y` and `padding` args from dijit/popup