This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import static org.junit.Assert.*; | |
import main.Game; | |
import org.junit.Before; | |
import org.junit.Test; | |
public class BowlingTest { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public class Game { | |
class Frame { | |
final int firstRoll; | |
final int secondRoll; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Converter { | |
public static String toRomans(int i) { | |
return getMultipleM(i/1000) + toRomans(i/100,"C","D","M") + toRomans(i/10, "X", "L", "C") + toRomans(i%10, "I", "V", "X"); | |
} | |
private static String toRomans(int i, String symbolI, String symbolV, String symbolX) { | |
int moduloRest10 = i%10; | |
if ( moduloRest10 == 0) { | |
return ""; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Timer; | |
import java.util.TimerTask; | |
public class EggCooker { | |
private View view; | |
private long remainingTime; | |
private ITimer timer; | |
public EggCooker(View view, ITimer timer) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir /tmp/ruby-build-patch | |
cd /tmp/ruby-build-patch | |
# download and patch the ruby sources | |
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz | |
tar xzf ruby-1.9.3-p125.tar.gz | |
cd ruby-1.9.3-p125 | |
curl https://raw.github.com/wayneeseguin/rvm/master/patches/ruby/1.9.3/p125/gcdata.patch | patch -p1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should use constant memory" do | |
warm_up_measure = memory_usage_for_items(1) | |
small_inputs_memory = memory_usage_for_items(1) | |
large_inputs_memory = memory_usage_for_items(200) | |
large_inputs_memory.should be <= small_inputs_memory * 1.05 | |
end | |
def memory_usage_for_items(item_count) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Object | |
# Will call the given block with it's result every time the method | |
# returns | |
def on_result_from(method_name) | |
stock_response = self.original_response(method_name) | |
self.stub(method_name) do |*args, &block| | |
result = stock_response.call(*args, &block) | |
yield result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Matcher to verify that all items match something else | |
RSpec::Matchers.define :all_ do |item_matcher| | |
match do |actual_items| | |
actual_items.all? { |item| item_matcher.matches?(item)} | |
end | |
description do | |
"#{item_matcher.description} to be true for all the items" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "add keywords to posts" | |
task :add_keywords do | |
Dir.glob(File.join(File.dirname(__FILE__),"source/_posts/*.markdown")) do |file| | |
yaml = YAML.load_file(file) | |
keywords = yaml['categories'] || [] | |
title = yaml['title'] | |
keywords += title.scan(/'.*'/).map {|kw| kw.gsub("'",'')} | |
keywords += title.scan(/\S+[\sv~>]+?\d+\.\d+\.?\d*/) |