Instantly share code, notes, and snippets.

View 1. Before
@Test
public void shortRegularRental() {
Customer customer = createCustomer();
addRental(customer, "Groundhog Day", Movie.REGULAR, 2);
String expected = "Rental record for Luke\n";
expected += "\tGroundhog Day\t2.0\n";
expected += "Amount owed is 2.0\n";
expected += "You earned 1 frequent renter points";
View gist:575564
public class RpnCalculator {
@Test
public void NewCalculatorHas0InItsAccumulator { ... }
@Test
public void NewAccumulatorShouldAllowItsAccumulatorToBeSet { ... }
}
View gist:575607
public class ANewlyCreatedRpnCalculatorShould {
private RpnCalculator calculator;
@Before
public void init(){
calculator = new RpnCalculator();
}
@Test
View test_fizz_buzz.rb
def test_fizzbuzz_de_1_a_20
sequence = []
1.upto(20) do |n|
fizzbuzz = FizzBuzz.new(n)
sequence.push(fizzbuzz.run)
end
assert_equal '1,2,fizz,4,buzz,fizz,7,8,fizz,buzz,11,fizz,13,14,fizzbuzz,16,17,fizz,19,buzz', sequence.join(",")
end
View Rambo.java
package Agil;
import robocode.*;
import java.awt.Color;
import static robocode.util.Utils.getRandom;
/**
* Rambo - a robot by @alex_aquiles
*/
public class Rambo extends Robot
{
View gist:828327
from("jetty:http://localhost/myapp/myservice").process(new MyBookService());
from("smpp://smppclient@localhost:2775?password=password&enquireLinkTimer=3000&transactionTimer=5000&systemType=consumer").to("bean:foo");
from("imap://admin@mymailserver.com password=secret&processOnlyUnseenMessages=true&consumer.delay=60000").to("seda://mails");
View devise.pt-BR.yml
pt-BR:
errors:
messages:
not_found: 'não encontrado'
already_confirmed: 'já foi confirmado'
not_locked: 'não foi bloqueado'
not_saved:
one: '1 erro impediu que %{resource} fosse gravado:'
other: '%{count} erros impediram que %{resource} fosse gravado:'
View factorial.rb
def fatorial(number)
if (number == 0)
return 1
else
return number * fatorial(number - 1)
end
end
View gist:962448
(defparameter *small* 1)
(defparameter *big* 100)
(defun guess-my-number ()
(ash (+ *small* *big*) -1))
(defun smaller ()
(setf *big* (1- (guess-my-number)))
(guess-my-number))
View fibonacciSequence.scala
def fibonacciSequence : Stream[Long] = {
def fibonacciFrom(a: Long, b: Long) : Stream[Long] = a #:: fibonacciFrom(b, a+b)
fibonacciFrom(0, 1)
}