Skip to content

Instantly share code, notes, and snippets.

All

Season Home Away Winner Result
2005 England Australia England 2-1 (5)
2006/07 Australia England Australia 5-0 (5)
2008/09 West Indies England West Indies 1-0 (5)
2009 England Australia England 2-1 (5)
2010/11 Australia England England 3-1 (5)
2013 England Australia England 3-0 (5)
@Mahoney
Mahoney / MutableAnswers.kt
Last active April 8, 2025 13:49
Extensions to mockk to allow atomic changes to stubbed answers
package ext.mockk
import io.mockk.Call
import io.mockk.MockKAnswerScope
import io.mockk.MockKStubScope
import java.util.concurrent.atomic.AtomicReference
infix fun <T, B> MockKStubScope<T, B>.returnsMutably(initialValue: T): MutableAnswer<T, B> =
answersMutably { initialValue }
@Mahoney
Mahoney / file_repetitions.kts
Created March 23, 2025 15:00
Script to view repetitions in a directory
#! /usr/bin/env kotlin
import java.io.File
import java.nio.file.Path
import java.security.MessageDigest
import java.text.NumberFormat
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
import kotlin.io.path.fileSize
import kotlin.io.path.relativeTo
@Mahoney
Mahoney / RenderMarkdown.kt
Last active March 23, 2025 14:42
Rendering a Markdown Table in Kotlin
fun renderMarkdownTable(
header: List<String>,
rows: List<List<Any?>>
): String {
val columnsAreNumeric: List<Boolean> = rows
.map { row -> row.map { cell -> cell == null || cell is Number } }
.reduce { areNumbersSoFar, row ->
areNumbersSoFar.mapIndexed { index, isNumberSoFar ->
isNumberSoFar && row[index]
@Mahoney
Mahoney / RandomAccessOrderedSet.kt
Last active August 28, 2024 10:58
A subtype of Set that presupposes the Set is Ordered and allows random access
interface RandomAccessOrderedSet<out E> : Set<E> {
// Positional Access Operations
/**
* Returns the element at the specified index in the ordered set.
*/
operator fun get(index: Int): E
// Search Operations
/**
* Returns the index of the first occurrence of the specified element in the ordered set, or -1 if the specified
@Mahoney
Mahoney / petstore.yaml
Created March 20, 2024 13:37
petstore.yaml
openapi: 3.0.0
info:
title: Swagger Petstore
description: 'This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.'
contact:
email: [email protected]
version: '1.0.5'
servers:
- url: https://petstore.swagger.io/v2
variables: {}
@Mahoney
Mahoney / example_openapi.yaml
Created March 20, 2024 13:11
WireMock Cloud workshop OpenAPI
paths:
/things/{thingId}:
get:
description: Get things by thingId.
operationId: getThingsByThingId
parameters:
- name: thingId
in: path
required: true
style: simple
@Mahoney
Mahoney / HigherKindedTypes.kt
Created December 8, 2023 11:49
Sort of Higher Kinded Types in Kotlin
fun <A, B, C, R> inTransaction(work: (A, B, C) -> R): (A, B, C) -> R {
// do something
return { a: A, b: B, c: C ->
// do something
try {
work(a, b, c)
} finally {
// do something
}
}
@Mahoney
Mahoney / Main.java
Last active November 7, 2022 10:39
Issue with getting null in the right place with Jackson
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@Mahoney
Mahoney / explain-analyze-subjects.md
Last active September 17, 2022 12:55
Explain analyze before and after adding an index

No index:

CTE Scan on flat_members  (cost=10145.57..10147.59 rows=101 width=8) (actual time=3.321..26.953 rows=3 loops=1)
  CTE flat_members
    ->  Recursive Union  (cost=0.00..10145.57 rows=101 width=8) (actual time=3.319..26.947 rows=3 loops=1)
          ->  Seq Scan on subject_group_members gm  (cost=0.00..866.77 rows=1 width=8) (actual time=3.315..4.825 rows=2 loops=1)
                Filter: (subject_id = 30459)
                Rows Removed by Filter: 48380
          ->  Hash Join  (cost=0.33..927.68 rows=10 width=8) (actual time=10.937..11.043 rows=0 loops=2)
                Hash Cond: (s.subject_id = f.subject_group_id)