This file contains 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
/* LED USB Lamp | |
This program controls a high power LED via PWM and reads in a touch pad. | |
The circuit: * LED attached from digital pin 3 to ground. * touch pad connected to pin 6 and 5 | |
Created 18 Aug 2012 By Sebastian Schuster | |
*/ |
This file contains 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
module PrimeFactorDecomposer | |
def decompose(number) | |
if number < 4 | |
number | |
else | |
[2,2] | |
end | |
end | |
end |
This file contains 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
describe PrimeFactorDecomposer do | |
include PrimeFactorDecomposer | |
it "returns no prime factors for 1" do | |
decompose(1).should be_empty | |
end | |
end |
This file contains 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
describe "A way to extract address" do | |
it "creates a value object upon read" do | |
foo = Poi.new | |
foo.name = "test" | |
foo.company_name = "bar" | |
foo.title = "zzzzz" | |
foo.address.name.should == "test" | |
foo.address.company.should == "bar" |
This file contains 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
require 'set' | |
Set.new([1, 2, 3]) | |
#<Set: {1, 2, 3}> | |
Set.new([1, 2, 3]) do |val| val * 2 end | |
#<Set: {2, 4, 6}> | |
Set.new([1,2,3]) & Set.new([2,3,4]) | |
#<Set: {2, 3}> |
This file contains 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 FibonaciSequenceGenerator | |
class SequenceToLongError < StandardError; end | |
def generate(length) | |
raise SequenceToLongError if length > 50 | |
@sequence = [] | |
1.upto(length) {|number| @sequence << fibonaci_number(number)} | |
@sequence | |
end |
This file contains 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 BowlingGame | |
attr_reader :rolls | |
def initialize | |
@rolls = [] | |
end | |
def roll(pins) | |
@rolls << pins | |
end |
This file contains 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 BowlingGame | |
def initialize | |
@rolls = [] | |
end | |
def roll(pins) | |
@rolls << pins | |
end | |
def score |
This file contains 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
module PrimeFactorDecomposer | |
def decompose(number) | |
return [number] if prime?(number) | |
primes = [] | |
2.upto(number / 2) do |candidate| | |
while (number % candidate).zero? do | |
primes << candidate | |
number = number / candidate | |
end |
This file contains 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/bash | |
echo "Enough of this filthy internet" | cowsay -s | |
sudo route -n delete default &> /dev/null |