Skip to content

Instantly share code, notes, and snippets.

@istro
istro / gist:3310936
Created August 10, 2012 04:02
started tdd-ing schulze voting method... didn't get far, but had fun, stopped during refactoring so it's all broken
require 'rspec'
describe "Schulze" do
before :each do
@ballots = [['q','f','b'],['f','b','q'],['q','f','b']]
@ballots2 = [['f','q','b'],['f','b','q'],['q','f','b']]
@schulze = Schulze.new @ballots
@schulze_twin = Schulze.new @ballots2
end
@istro
istro / list.rb
Created June 28, 2012 04:07
Todo CLI with rspec
module Todo
class List
def initialize(file_path)
@file_path = file_path
@tasks = parse_tasks(File.read(@file_path))
end
def parse_tasks(text)
# we use #collect here so that we will return an array of tasks
text.split("\n").collect do |line|
@istro
istro / in_words.rb
Created June 15, 2012 01:25
in_words in progress
module InWords
def in_words
places=1
num = self
while(num/10 != 0)
places num+= 1
num = num/10
end
if self>1000
@istro
istro / trianglemagic
Created June 14, 2012 03:01
Method to find the type of triangle by the length of three sides
# The problem:
# Write a triangle method that accepts three numbers as arguments. The method should return a print
# whether the three lengths form an equilateral, isosceles, or scalene triangle.
#
# We were just learning to define methods, and having learned if/else statements and touched on
# ternary statements, so we just wanted to make it as concise as we could with our limited knowledge :)
#