Skip to content

Instantly share code, notes, and snippets.

package uk.org.lidalia;
import org.joda.time.Interval;
import org.joda.time.Period;
import org.junit.Test;
import org.junit.runner.RunWith;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
package uk.org.lidalia;
import org.joda.time.*;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import static com.google.common.collect.FluentIterable.from;
import static java.util.Arrays.asList;
import static org.joda.time.DurationFieldType.*;
package uk.org.lidalia.lang.collection
trait Iterable[+A] {
type MayBeEmptySelf[+B] <: Iterable[B]
// type NonEmptySelf[+B] <: NonEmptyIterable[B]
type Self[+B] <: Iterable[B]
def head: ?[A]
@Mahoney
Mahoney / these_isles_mixed.gv
Last active February 28, 2020 16:08
Graphviz Description of These Isles - Mixed Geographic & Political
digraph these_isles {
node [shape=rectangle,style=filled,fillcolor=lightcyan];
label1[label="Geographic\nTerms"];
"Mainland\nEngland";
"Mainland\nWales";
"Mainland\nScotland";
node [shape=oval]
gb[label="Great\nBritain"];
Ireland;
mona[label="Ynys Mon"];
@Mahoney
Mahoney / british_isles_geographic.gv
Created July 11, 2017 12:09
Graphviz Description of British Isles - Geographic
digraph british_isles {
node [shape=rectangle,style=filled,fillcolor=lightcyan];
other[label="Other"];
england[label="Mainland\nEngland"];
wales[label="Mainland\nWales"];
scotland[label="Mainland\nScotland"];
node [shape=oval];
islands[label="Islands"];
gb[label="Great\nBritain"];
Ireland;
@Mahoney
Mahoney / these_isles_political.gv
Last active February 28, 2020 16:06
Graphviz Description of These Isles - Political
digraph these_isles {
node [shape=rectangle,style=filled,fillcolor=lightpink];
ireland[label="Ireland"];
jersey[label="Bailiwick\nof\nJersey"];
man[label="Isle of\nMan"];
uk[label="United\nKingdom"];
ni[label="Northern\nIreland"];
crown_deps[label="Crown\nDependencies"];
guernsey[label="Bailiwick\nof\nGuernsey"]
{ Scotland England Wales ni } -> uk;
@Mahoney
Mahoney / stateful_spa.scala
Last active September 29, 2018 22:17 — forked from japgolly/stateful_spa.scala
Stateful SPA
// Overview of how this works:
// 1. Initialisation data is used to create an instance of LoadedRoot.
// 2. LoadedRoot contains a component which is the virtual top-level component.
// It uses the initialisation data and can be sure that it won't change (a guarantee you don't have with component props).
// It's the only component to have state.
// The state can applies to the entire SPA, all routes.
// It gets told by the router which page to render.
// It can house logic that applies when certain pages change to certain other pages.
// 3. LoadedRoot is passed to Routes.routerConfig.
// Routes.routerConfig creates a config that sends all routes to the LoadedRoot component, using the Page & RouterCtl as props.
@Mahoney
Mahoney / Delegating.groovy
Last active October 18, 2018 21:13
Shows how Groovy allows delegating without exposing the encapsulated type
@CompileStatic
class MyString {
@Delegate
private final String decorated
MyString(String decorated) {
this.decorated = decorated
}
}
@Mahoney
Mahoney / Eithers.scala
Created July 18, 2019 18:21
A way to build Eithers as Left or Right specifying the other side's type but with type inference for the value
package scala.util
class RightBuilder[+L] private[util]() { def apply[R](r: R): Right[L, R] = Right(r) }
class LeftBuilder[+R] private[util]() { def apply[L](l: L): Left[L, R] = Left(l) }
object Eithers {
private val leftBuilder = new LeftBuilder[Nothing]
private val rightBuilder = new RightBuilder[Nothing]
@Mahoney
Mahoney / docker_buildkit_cach_test.sh
Last active February 28, 2020 20:34
An example maintaining a cache in an image
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function clear_build_cache {
docker builder prune -f > /dev/null
}
function clean_start {