Skip to content

Instantly share code, notes, and snippets.

@xpmatteo
xpmatteo / gist:1616428
Created January 15, 2012 16:56
Solution to Greed Ruby Koan
class Array
def occurrences_of(match)
self.select{ |number| match == number }.size
end
def delete_one(match)
for i in (0..size)
if match == self[i]
self.delete_at(i)
@xpmatteo
xpmatteo / gist:5243745
Created March 26, 2013 07:44
This is IMHO an improvement over Bobby Johnson test cases for the Gilded Rose Kata (https://github.com/NotMyself/GildedRose/blob/first_refactor/src/GildedRose.Tests/UpdateItemsTests.cs) Chief improvements: a) the duplication is factored in small nice methods. If the GildedRose API changes, we will have to change the test in one place, not hundre…
import static org.junit.Assert.*;
import org.junit.Test;
public class GildedRoseTest {
private GildedRose app;
@Test
public void at_the_end_of_each_day_our_system_lowers_both_values_for_every_item() {
@xpmatteo
xpmatteo / gist:8317762
Last active December 1, 2017 10:05
Solution of the FizzBuzz problem in an OCP dojo
describe('fizz buzz',function(){
var self = this;
beforeEach(function(){
var threeChecker = new Checker(3, "Fizz");
var fiveChecker = new Checker(5, "Buzz");
var sevenChecker = new Checker(7, "Bang");
self.fizzBuzzer = new FizzBuzzer([threeChecker, fiveChecker, sevenChecker]);
});
it('Default is say the number',function(){
@xpmatteo
xpmatteo / water-flow.hs
Created June 19, 2015 10:33
A solution to the water flow problem
data Tile = Rock | Air
type Stripe = [Tile]
type Heights = [Int]
type Water = Int
trimLeft :: Stripe -> Stripe
trimLeft [] = []
trimLeft (Air : xs) = trimLeft(xs)
trimLeft xs = xs
@xpmatteo
xpmatteo / string-calculator-kata-test.cbl
Last active April 15, 2016 07:32
The String Calculator Kata in Cobol :)
IDENTIFICATION DIVISION.
PROGRAM-ID. StringCalculatorTest.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> constants
01 newline PIC X VALUE x'0a'.
*> add parameters
class Pacman
attr_accessor :screen
def initialize(starting_screen)
@screen = starting_screen
end
def evolve!
if (dash_index = @screen.index '-')
@screen[dash_index] = '<'
elsif (dot_index = screen.index '.')
package com.thoughtworks.eg;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Server;
### Keybase proof
I hereby claim:
* I am xpmatteo on github.
* I am xpmatteo (https://keybase.io/xpmatteo) on keybase.
* I have a public key ASBWP-o6nQG5WW90TWnwBLgDDC1ynXMcXt9JPU5OfbXD1wo
To claim this, I am signing this object:
private static final int NONSTANDARD_PORT = 9999;
private MailAdapter mailAdapter = new MailAdapter("localhost", NONSTANDARD_PORT);
private SimpleSmtpServer smtpServer;
@Before
public void setUp() throws Exception {
smtpServer = SimpleSmtpServer.start(NONSTANDARD_PORT);
}
@After
@xpmatteo
xpmatteo / SetOfPrimes.java
Created December 2, 2018 18:11
An imperative, object-oriented way to solve the "give me the first N primes" problem
public class SetOfPrimes {
private List<Integer> primes = new ArrayList<>();
public static SetOfPrimes ofSize(int desiredSize) {
SetOfPrimes setOfPrimes = new SetOfPrimes();
int candidate = 2;
while (setOfPrimes.size() < desiredSize) {
setOfPrimes.considerForInclusion(candidate++);
}