Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Wubben novemberborn

View GitHub Profile
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
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: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: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: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
@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(); }));
@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:899634
Created Apr 2, 2011
Convert pasteboard string into JSON
View gist:899634
#!/usr/bin/env node
require("child_process").exec("pbpaste", function(_, stdout){
process.stdout.write(JSON.stringify(stdout.trim()));
});
@novemberborn
novemberborn / Activate Terminal.scpt
Created Jun 26, 2011
Focus the terminal window open in the current space, or open a new one.
View Activate Terminal.scpt
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
View zed.js
// 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