Skip to content

Instantly share code, notes, and snippets.

View dominictarr's full-sized avatar

Dominic Tarr dominictarr

View GitHub Profile
@dominictarr
dominictarr / hello_sinatra.rb
Created September 9, 2010 14:20
get started testing sinatra with capybara
require 'rubygems'
require 'sinatra/base'
class Hello < Sinatra::Base
get '/' do
"hello world"
end
end
@dominictarr
dominictarr / hello.rb
Created September 10, 2010 01:48
hello world
puts "hello world?"
#raise "CRAZY EXCEPTION!"
@dominictarr
dominictarr / base12.rb
Created September 10, 2010 11:13
calculate times table in base 12
begin
base = ARGV.length > 0 ? ARGV[0].to_i : 12
rescue
puts "usuage:
ruby #{__FILE__} {number}
(number = 12 by default)"
end
puts "times table in base #{base}:"
(base + 1).times {|x|
(base + 1).times {|y|
@dominictarr
dominictarr / dsl.rb
Created September 11, 2010 03:29
ruby DSL example
class DSL
def go (&block)
instance_eval &block if block
self
end
def self.go (&block)
DSL.new.go(&block)
@dominictarr
dominictarr / set default.rb
Created September 24, 2010 04:18
ruby 'default' opperator.
foo ||= true
puts foo
foo = nil
foo ||= true
puts foo
foo = false
foo ||= true
puts foo
@dominictarr
dominictarr / queue.js
Created September 26, 2010 08:01
run a function with a limited amount of concurrency.
var sys = require('sys'),
exec = require('child_process').exec;
// fs = require('fs');
// ecsv = require('ecsv')
function Queue () {
var waiting = [];
this.max = -1;
this.current = 0;
//run checks if we're under the max processors, and runs if there is room.
exports.hello = function(){return 'HI');
@dominictarr
dominictarr / handle_the_jandal.js
Created October 20, 2010 12:06
ways to process errors in node js
//test-uncaught-errors
var sys = require('sys')
, EventEmitter = require('events').EventEmitter;
function error1 (err){
sys.puts("Handle: " + err);
}
function error2 (err){
sys.puts("JANDAL: " + err);
}
function exit (){
@dominictarr
dominictarr / child.asynct.js
Created November 18, 2010 09:11
this test will be reported to pass, when clearly it should fail. async_testing v0.3.0
if (module == require.main) {
return require('async_testing').run(process.ARGV);
}
require('async_testing/lib/child')
exports ['test should fail'] = function (test){
test.ok(false)
}
@dominictarr
dominictarr / async_testing.runfile.asynct.js
Created November 20, 2010 05:31
break async_testing.runFile
//async_testing.runfile.asynct
exports ['does not call onSuiteDone twice'] = function (test){
var file = 'async_testing/test/test-stderr'
require('async_testing').runFile(file,{onSuiteDone:suiteDone})
function suiteDone (status,report){
console.log("suiteDone - " + status + "'" + file + "'")