Skip to content

Instantly share code, notes, and snippets.

@xpmatteo
xpmatteo / at.pic
Created March 7, 2024 13:52
Sample PIC source
#
# See https://pikchr.org/home/doc/trunk/doc/userman.md
# And https://pikchr.org/home/pikchrshow
#
U: ellipse "Unit" mono "tests" mono thickness 0 fill lightgreen
move wid 0.2
SHELL: circle wid 200% thickness 0 fill lightblue
move wid 0.2
A: ellipse \
"Acceptance" mono "tests" mono \
@xpmatteo
xpmatteo / TurnstileTest.java
Created November 2, 2023 18:57
Recreating in vanilla Java the State monad example from https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State
package it.xpug.spike.monads.monad;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.function.Function;
import static it.xpug.spike.monads.monad.TurnstileTest.TurnstileOutput.*;
import static it.xpug.spike.monads.monad.TurnstileTest.TurnstileState.LOCKED;
import static it.xpug.spike.monads.monad.TurnstileTest.TurnstileState.UNLOCKED;
@xpmatteo
xpmatteo / Cat.java
Last active September 5, 2023 13:07
public class Cat {
private Bird caughtBird;
private boolean isFull = false;
public Cat catchBird(Bird bird) {
if (caughtBird != null) {
throw new RuntimeException("Caught one bird already");
}
caughtBird = bird;
return this;
#!/usr/bin/env bash
fail() {
echo "$0: $*"
exit 1
}
captured_output=/tmp/captured_output
temp_dir=/tmp/test-script-folder
rm -rf $temp_dir
@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++);
}
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
### 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:
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;
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 '.')
@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