View NonRepeatingNumbers.cs
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
using System.Collections.Generic; | |
using System.Linq; | |
using NUnit.Framework; | |
//Using Maybe.cs | |
namespace ArrayStructure | |
{ | |
[TestFixture] | |
public class Tests | |
{ |
View PointOfSaleTerminal.java
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
package ca.jbrains.pos; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.InetAddress; | |
import java.util.HashMap; | |
public class PointOfSaleTerminal { | |
public static void main(String[] args) throws IOException { | |
final InputStreamReader commandSource = new InputStreamReader(System.in); |
View gist:2a29465457bddcca0c45
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
-- Thanks to @kimwallmark for teaching me `maybe` and showing me how a single lookup. | |
-- I had the brilliant idea of using `snd`, even though I dislike the name. :) | |
fizzbuzz :: Integer -> String | |
fizzbuzz n = maybe (show n) snd $ classify n | |
where | |
classify n = find (\(m, _) -> n `mod` m == 0) [(15, "Fizzbuzz"), (5, "Buzz"), (3, "Fizz")] |
View gist:9451941
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
# SMELL I don't like the name gemfile_lock_file, but I don't know | |
# what else to call it. I want to distinguish it from Gemfile. | |
def extract_gems_from_gemfile_lock_file(contents) | |
gems = [] | |
# Extract all the non-empty lines between and excluding 'specs:' and 'PLATFORMS' | |
contents.each_line do |line| | |
line = line.strip | |
# It takes a few seconds to understand this algorithm, | |
# but I can't yet justify replacing it with a functional | |
# approach. Again, it depends what the reader understands |
View make-diagrams.sh
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 | |
download_yuml_image() { | |
local file="$1" | |
local output_directory="$2" | |
instructions=$(tr "\\n" "," < <(cat $file)) | |
image_basename=$(basename $(echo $file | sed -E "s/(.+)\.yuml$/\1/")) | |
image_filename="${output_directory}/${image_basename}.png" |
View gist:1259077
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
public class BusinessObject { | |
/** @deprecated */ | |
public void actionMethod() { | |
actionMethod(Service.getInstance()); | |
} | |
// A SEAM! A SEAM! New clients should use me!! | |
public void actionMethod(ServiceDelegate serviceDelegate) { | |
// Other things | |
serviceDelegate.doService(); |
View Cell.java
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
package rules; | |
public class Cell { | |
protected int numberOfLiveNeighbors; | |
private CellState state; | |
public Cell() { | |
this.state = CellState.DEAD; | |
} |
View mock_problems.rb
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
# common use of mocks in a Rails app | |
it "updates the requested book" do | |
mock_book = mock(:book) | |
Book.should_receive(:find).with("37").and_return(mock_book) | |
mock_book.should_receive(:update_attributes).with({:these => 'params'}) | |
put :update, :id => "37", :book => {:these => 'params'} | |
end | |
# without mocks a more readable, less brittle test | |
it "updates the requested book" do |
View SellOneItemTest.java
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
ackage ca.jbrains.pos.test; | |
import org.junit.*; | |
import static org.junit.Assert.*; | |
import java.util.*; | |
public class SellOneItemTest { | |
private POSDisplay posDisplay = new POSDisplay(); | |
private Sale sale; |
View comparing_expect_then_act_with_act_then_verify.groovy
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
public class CreateActionTest { | |
def mockery = new JUnit4Mockery(); | |
def modelRepository = mockery.mock(ModelRepository.class); // corresponds to class methods on Model in Rails | |
def model = new Model(); // treated as Entity (DDD sense) | |
def controller = new Controller(modelRepository); | |
@Before | |
public void supposeModelRepositoryCreatesOurModelObject() { | |
mockery.stub(modelRepository).create().will(returnValue(model)); |
NewerOlder