Skip to content

Instantly share code, notes, and snippets.

@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: apiteam@swagger.io
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)
@Mahoney
Mahoney / DatabaseMigrationSpec.groovy
Last active July 20, 2022 18:13
Test liquibase migration output
package mything.db
import com.zaxxer.hikari.HikariDataSource
import liquibase.Liquibase
import liquibase.database.DatabaseFactory
import liquibase.database.jvm.JdbcConnection
import liquibase.resource.ClassLoaderResourceAccessor
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.spock.Testcontainers
import spock.lang.Shared
@Mahoney
Mahoney / add_docker_alias.sh
Created June 1, 2022 13:53
Add a new alias to an existing container from a container running within a docker network
#! /bin/sh
# Requires curl, jq & /var/run/docker.sock to be mounted into the container
set -eu
main() {
alias=$1
container_id="$(hostname)"
@Mahoney
Mahoney / wildcard-cert.sh
Created April 28, 2022 16:16
Generate a wildcard cert using lets encrypt with route53 on macOS
#!/usr/bin/env bash
set -euo pipefail
domain_name=$1
brew install certbot
$( brew --prefix certbot )/libexec/bin/pip install certbot-dns-route53
@Mahoney
Mahoney / Integers.kt
Last active March 23, 2022 17:40
Type safe integer behaviour in Kotlin
sealed interface Integer {
operator fun plus(other: Integer): Integer
operator fun plus(other: NonZeroInteger): Integer
operator fun plus(other: NonNegativeInteger): Integer
operator fun plus(other: NonPositiveInteger): Integer
operator fun plus(other: PositiveInteger): Integer
operator fun plus(other: NegativeInteger): Integer
operator fun plus(other: Zero): Integer
operator fun div(other: NonZeroInteger): Integer
@Mahoney
Mahoney / Json.kt
Created March 4, 2022 09:18
Actual working JSON in Kotlin
sealed interface Json {
@JvmInline value class Boolean(val value: kotlin.Boolean) : Json
@JvmInline value class Number(val value: kotlin.Number) : Json
@JvmInline value class String(val value: kotlin.String) : Json
class Object(private val value: Map<kotlin.String, Json?>) : Map<kotlin.String, Json?> by value, Json
class Array(private val value: List<Json?>) : List<Json?> by value, Json
}
interface ToJson {