Skip to content

Instantly share code, notes, and snippets.

Detective

What is it?

Simply put, this is a ruby testing library which asks questions in order to determine compliance.

That is, you ask the user questions with "ask", and test results with "expect". You can also give instructions with "instruct".

The entire testing suite is evaluated using the command-line. e.g.

@jamesu
jamesu / gist:1088084
Created July 17, 2011 21:30
Synchtube debug mode
// Paste this in a JS console
$('body').append('<div id="io_debug"></div>');
// Users
sp.users.me // current user
sp.users.me.attributes().id // current user id
User.find(id).attributes().nick // username from id
// Print out all users in room
User.each(function(user) { console.log(user.attributes().id); });
@jamesu
jamesu / README.markdown
Created July 20, 2011 12:23
Array operator on ActiveRecord

Array operator on ActiveRecord

This adds a [] operator to ActiveRecord models to quickly find single records, e.g.

User[:id => 1]

Thats it!

@jamesu
jamesu / roar.sh
Created July 27, 2011 10:24
Disable all the annoying features in OSX Lion
# Commands to disable all the annoying features in OSX Lion
# Fork if you've got any more ideas!
# NOTE: most of these commands seem to need a restart to work
# Press and hold (i.e. fix key autorepeating)
defaults write -g ApplePressAndHoldEnabled -bool false
# Window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool NO
@jamesu
jamesu / README.markdown
Created August 29, 2011 15:23
DumbStore

DumbStore

A rather dumb storage solution. By default all data will be stored in "database.dumb" in the current directory.

Usage

Usage: dumbstore.rb [options] set/get/delete/keys <key> <value>
    -d, --database PATH              Path to database
    -h, --help                       Display this screen
@jamesu
jamesu / mkatlas.rb
Created September 14, 2011 21:54
Atlas generator
#!/usr/bin/env ruby
# Author: Matthias Hoechsmann, gamedrs.com
# Ported to Ruby by James Urquhart, github.com/jamesu
# Artefact Removal using Edge Copy by Patrick Wolowicz, subzero.eu
# This source code an be used freely and is provided "AS IS" without any warranties.
# Go and visit www.zombiesmash.gamedrs.com. Thank you :)
# README
# mkatlas.rb is a ruby script for generating an atlas image from individual images and a C header file with image coordinates.
@jamesu
jamesu / tiddly_to_notational.rb
Created October 8, 2011 22:07
Convert a TiddlyWiki to Notational Velocity notes
#!/usr/bin/env ruby
# Converts tiddlywki tiddlers into files which can be imported into Notational Velocity
require 'fileutils'
require 'rexml/document'
require 'time'
require 'date'
tiddlywiki_location = ARGV[0]
if tiddlywiki_location.nil?
puts "Please specify the location of your Tiddliwki"
@jamesu
jamesu / countbits.rb
Created January 29, 2012 14:44
Counting bits without testing every bit
# Counts bits without testing every single bit, using a simple lookup table.
# Assumes a maximum size of 32bits.
$blookup = (0..255).map do |i|
count = 0
(0..7).each { |j| count += 1 if (i>>j) & 0x1 != 0 }
count
end
# Count
@jamesu
jamesu / remove_duplicates.sh
Created February 1, 2012 15:37
Remove duplicate emails from an mbox
#!/bin/sh
formail -D 100000000 idcache < $1 -s > $1_new
@jamesu
jamesu / nginx_consolidate.rb
Created February 4, 2012 15:32
Consolidate nginx server logs
#!/usr/bin/ruby
# usage: nginx_consolidate.rb /var/log/nginx/*log*
#
require 'zlib'
ARGV.sort.each do |file|
if File.extname(file) == ".gz"
Zlib::GzipReader.open(file) { |f| STDOUT.write f.read }
else