Skip to content

Instantly share code, notes, and snippets.

View ClausPolanka's full-sized avatar

Claus Polanka ClausPolanka

View GitHub Profile
function greeter(salutation) {
var counter = 0;
var prefix = '. ' + salutation + ' ';
return function(name) {
counter++;
return counter + prefix + name + '!';
};
}
@Test
public void reportsLostIfAuctionClosesWhenBidding() {
context.checking(new Expectations() {{
ignoring(auction);
allowing
(sniperListener).sniperBidding(); then(sniperState.is("bidding"));
atLeast(1).of
(sniperListener).sniperLost(); when(sniperState.is("bidding"));
@ClausPolanka
ClausPolanka / quicksort.hs
Created October 14, 2010 14:01
Quicksort in Haskell
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
@ClausPolanka
ClausPolanka / gist:628201
Created October 15, 2010 13:43
Quicksort via filters in Haskell
quicksort' :: (Ord a) => [a] -> [a]
quicksort' [] = []
quicksort' (x:xs) =
let smallerSorted = quicksort' (filter (<=x) xs)
biggerSorted = quicksort' (filter (>x) xs)
in smallerSorted ++ [x] ++ biggerSorted
@ClausPolanka
ClausPolanka / gist:628209
Created October 15, 2010 13:52
The largest number under 100,000 that's divisible by 3829
largestDivisible :: (Integral a) => a
largestDivisible = head (filter p [100000,99999..])
where p x = x `mod` 3829 == 0
@ClausPolanka
ClausPolanka / gist:628239
Created October 15, 2010 14:09
The sum of all odd squares that are smaller than 10,000 in Haskell
sum (takeWhile (<10000) (filter odd (map (^2) [1..])))
@ClausPolanka
ClausPolanka / Clean Code - Comments.java
Created December 9, 2010 10:12
Redundant Comment in OrderOverviewHandler
/**
* Our sample handler extends AbstractHandler, an IHandler base class.
*
* @see org.eclipse.core.commands.IHandler
* @see org.eclipse.core.commands.AbstractHandler
*/
public class OrderOverviewHandler extends AbstractHandler {
@ClausPolanka
ClausPolanka / Clean Code - Comments.java
Created December 9, 2010 10:14
Unnecessary Comment for unnecessary constructor.
/**
* The constructor.
*/
public OrderOverviewHandler() {}
@ClausPolanka
ClausPolanka / Clean Code - Comments.java
Created December 9, 2010 10:16
Bad comment and null as return value.
/**
* the command has been executed, so extract extract the needed information from the application
* context.
*/
public Object execute(ExecutionEvent event)
throws ExecutionException {
LaunchCommand orderOverviewCmd = new LaunchCommand("overviewOrderStatus");
LaunchCommandParameter param = new LaunchCommandParameter();
param.setLaunchMode(LaunchMode.DIALOG);
@ClausPolanka
ClausPolanka / Clean Code - Comments.java
Created December 9, 2010 10:46
Unnecessary comment, code ownership (author) and bad vertical formatting and unnecessary initialization
...
* <p>
* You can create a command, you can test it and you can execute it.
*
* @author rge
*/
public class LaunchCommand {
private String commandId = null;
private boolean bAvailable = false;