Skip to content

Instantly share code, notes, and snippets.

View wwqrd's full-sized avatar

Stephen wwqrd

  • United Kingdom
  • 05:08 (UTC +01:00)
View GitHub Profile
@wwqrd
wwqrd / hud.js
Created May 3, 2012 17:41
Simple debug hud
var hud = function(msg, length) {
var length = length || 2;
window.hudBuffer = window.hudBuffer || [];
window.hudBuffer.push(msg);
if(window.hudBuffer.length > length) {
window.hudBuffer.shift();
}
hudString = "";
@wwqrd
wwqrd / stats.js
Created July 31, 2012 21:17
A simple stats display
(function() {
var Stats = function() {
var d = document.createElement("div");
d.setAttribute("style","color:#fff;font-size:10px;position:absolute;top:2px;left:2px;width:80;height:30px;padding:5px;z-index:1000;background:rgba(0,0,0,0.85);");
document.getElementsByTagName("body")[0].appendChild(d);
this.d = d;
this.stats = {};
this.measurements = {};
};
@wwqrd
wwqrd / logger.js
Created October 29, 2012 12:16
Simple log shim
// Create an instance of winston using our settings file determined by NODE_ENV
var winston = require( 'winston' ),
settings = ( process.env.NODE_ENV === 'production' )
? require( '../settings.json' ).production.logger
: require( '../settings.json' ).development.logger
var transports = [];
if( settings.console ) {
@wwqrd
wwqrd / Jakefile.js
Created November 14, 2012 13:47
Example Jakefile.js
namespace('test', function () {
desc('Run server tests');
task('server', [], function () {
jake.exec('mocha spec', function () {
console.log('Server tests passed');
complete();
});
});
desc('Run client tests');
@wwqrd
wwqrd / fakeserver.js
Created November 21, 2012 14:42
FakeServer
/*global*/
/*jslint node:true*/
'use strict';
var http = require( 'http' ),
url = require( 'url' ),
events = require( 'events' ),
util = require( 'util' ),
FakeServer;
@wwqrd
wwqrd / 1984.io
Last active December 16, 2015 18:21
1984 meets Io lang
oldSpeakAddition := Number getSlot("+")
Number + := method( a,
if( a == 2 and self == 2, 5, self oldSpeakAddition( a ) )
)
writeln( 1 + 1 ) # prints "2"
writeln( 1 + 2 ) # prints "3"
writeln( 2 + 2 ) # prints "5"
@wwqrd
wwqrd / divide_by_zero.io
Last active December 16, 2015 18:58
Seven Languages in Seven Weeks - Io. fib.io: Fibonacci number, using recursion and loops; divide_by_zero.io: Change built-in behavior so that divide by zero returns 0. sum_matrix.io: Sum values in a two-dimensional list; my_average.io: Implement slot method myAverage on list primitive which returns the average of a list and throws an exception i…
oldDivision := Number getSlot("/")
Number / := method( a,
if( a <= 0, 0, self oldDivision( a ) )
)
writeln( 1 / 2 ) # prints "0.5"
writeln( 1 / 1 ) # prints "1"
writeln( 1 / 0 ) # prints "0"
@wwqrd
wwqrd / tree.rb
Created April 30, 2013 20:55
Seven Languages in Seven Weeks - Ruby. tree.rb: Create a nested tree object using a hash as an input
class Tree
attr_accessor :children, :node_name
def initialize(tree)
tree.each { |name, branches|
@node_name = name
@children = []
branches.each_slice(1) { |branch|
@children.push(Tree.new(branch))
}
from facepy import GraphAPI
import json
# connect to facebook
oauth_access_token = [TOKEN_HERE]
graph = GraphAPI(oauth_access_token)
# get friend list
@wwqrd
wwqrd / app.js
Last active December 19, 2015 21:19
var IndexRoutes = require( 'index' );
var indexRoutes;
indexRoutes = routes.generate({
config = options.config;
logger = options.logger;
Metric = options.Metric;
});