Skip to content

Instantly share code, notes, and snippets.

#!/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 / 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;
@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 / 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 / AliveCharacter.java
Created July 26, 2025 11:37
RPG Combat Kata - Polymorphic Refactoring to Eliminate IF Statements
// ABOUTME: Represents a living RPG character with full capabilities
// ABOUTME: Handles damage reception, healing, and state transitions to dead when health reaches zero
public class AliveCharacter extends RPGCharacterBase {
public AliveCharacter() {
super(MAX_H);
}
public AliveCharacter(int health) {