Skip to content

Instantly share code, notes, and snippets.

View ruidlopes's full-sized avatar

Rui Lopes ruidlopes

View GitHub Profile
Verifying that +ruidlopes is my openname (Bitcoin username). https://onename.com/ruidlopes
@ruidlopes
ruidlopes / namespace.js
Created August 3, 2011 15:18
The perfect Javascript namespace creation Gist
var namespace = (function(s) {
return function(ns) {
var current, scopes = ns.split("."), scope = s;
while (current = scopes.shift())
scope = scope[current] = scope[current] || {};
return scope;
};
})(typeof global !== "undefined" ? global : window);
@ruidlopes
ruidlopes / expectations-test.js
Created April 19, 2011 15:38
testing expectations
var expectations = require("./expectations");
var f = function() {
return "we're here";
};
var expect = expectations.create(f);
// multiple bindings
expect.on("checked", console.log);
@ruidlopes
ruidlopes / expectations.js
Created April 19, 2011 15:38
an event-based approach to github.com/bpedro/node-expectation
exports.create = function(checkFunction, data, period) {
var emitter = new (require("events").EventEmitter)();
var wrapper = function(data) {
if (result = checkFunction(data))
emitter.emit("checked", result);
else
setTimeout(emitter.start, period || 1000);
};
emitter.start = function () { emitter.emit("start"); };
@ruidlopes
ruidlopes / latex-utf8-preamble.tex
Created March 4, 2011 18:56
LaTeX UTF8 Preamble
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
$(function() {
$.getJSON(window.location, function(json) { $m(json); });
});
@ruidlopes
ruidlopes / gist:767143
Created January 5, 2011 22:23
you know you want to put this on your .bash_profile (OSX)
function hack() {
mkdir -p $1
cd $1
git init
mate .
}
@ruidlopes
ruidlopes / om nom flickr!
Created December 30, 2010 21:39
Scrap full resolution pictures from Flickr, given a file containing URLs pointing to each picture's "homepage"
awk '{print "wget -qO- " $1"sizes/o/ | grep allsizes-photo -A 2 | grep img | awk -F\\\" '"'"'{print $2}'"'"' | xargs wget -O " NR ".jpg"}' urls.txt | sh