Skip to content

Instantly share code, notes, and snippets.

View nkpart's full-sized avatar

Nick Partridge nkpart

  • Brisbane, Australia
View GitHub Profile
$logger = Object.new {
#now I want to override stuff in here
def foo
"bar"
end
}
$s = Time.now
$logger = Object.new
def $logger.method_missing(sym, *args)
puts "[%s, %.3f] %s" % [sym.to_s.upcase, Time.now - $s, args.join(' ')]
end
@nkpart
nkpart / gist:1985
Created July 24, 2008 01:23 — forked from benhoskings/gist:1974
undefined
class PedAssignOptions < Struct.new(:links_file, :access_file, :walk_int_file, :output_file); end
class ParseFail < Struct.new(:reason); end
class ArgvParser
def parse argv
if argv.size == 1 and ['-h','--help'].include? argv.first then
return :help
end
if argv.length != PedAssignOptions.members.size then
return ParseFail.new("Incorrect number of arguments, got #{argv.size} expected #{PedAssignOptions.members.size}")
#! /bin/sh
BASEDIR=`dirname $0`
JAVA_OPTS="-Xmx2048m -Xms2048m -Xmn512m -server"
MAIN="start"
CP=$BASEDIR/../lib/jruby.jar:$BASEDIR/../lib/jgrapht-jdk1.5.jar:$BASEDIR/../lib/ped-assign.jar
java -cp $CP $JAVA_OPTS $MAIN $*
@nkpart
nkpart / gist:2344
Created July 25, 2008 00:05
undefined
package com.vlc.beach.zoning;
import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import com.googlecode.instinct.marker.annotate.Mock;
import com.googlecode.instinct.marker.annotate.Specification;
import static com.vlc.beach.zoning.SpecNotWorkingContext.Applicator.applicator;
import fj.F;
import org.jmock.Expectations;
import org.junit.runner.RunWith;
private <A,T> Runnable combine(final Callable<T> c, final Actor<T> a) {
return new Runnable() {
public void run() {
try {
a.act(c.call());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
@nkpart
nkpart / gist:3232
Created July 30, 2008 05:35
This spec passes when it shouldn't. The mockRunnable is never called.
package com.vlc;
import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import com.googlecode.instinct.marker.annotate.Specification;
import org.jmock.Expectations;
import org.junit.runner.RunWith;
@RunWith(InstinctRunner.class)
public final class InstinctFailContext {
@Specification
public void shouldThrowOnInvalidLines() {
expectException(VlcRuntimeException.class, "Invalid dimension definition, expected 3 tokens: 200-12", new Runnable() {
public void run() {
dimensionCreator.apply(invalidLine1);
}
});
expectException(VlcRuntimeException.class, "Invalid dimension definition, types incorrect: 200-12-A", new Runnable() {
public void run() {
dimensionCreator.apply(invalidLine2);
package com.vlc;
import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import com.googlecode.instinct.marker.annotate.Specification;
import org.jmock.Expectations;
import org.junit.runner.RunWith;
@RunWith(InstinctRunner.class)
public final class InstinctFailContext {
class TreeBuilder
def build a
root_node = Node.new(a)
yield root_node if block_given?
root_node.as_tree
end
class Node
def initialize value
@value = value