Skip to content

Instantly share code, notes, and snippets.

View mjstrasser's full-sized avatar

Michael Strasser mjstrasser

View GitHub Profile
@mjstrasser
mjstrasser / UuidBase62.kt
Last active July 21, 2025 07:59
Base-62 compact encoding and decoding of UUID
package mjs.uuid
import kotlin.uuid.Uuid
const val BASE_62_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
@OptIn(kotlin.uuid.ExperimentalUuidApi::class)
fun Uuid.toBase62(): String {
fun divideBy62(number: List<Byte>): Pair<Int, List<Byte>> {
tailrec fun divideStep(
@mjstrasser
mjstrasser / StoppedClock.kt
Last active June 23, 2025 01:47
Simple UUID v7 implementation in Kotlin
@file:OptIn(ExperimentalTime::class)
package mjs.uuid
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update
import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.Instant
@mjstrasser
mjstrasser / StoppedClock.kt
Created June 16, 2025 22:50
Simple implementation of kotlinx.datetime.Clock at a fixed instant that can be reset or changed
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.time.Duration
/**
* Simple implementation of [Clock] for testing. Once created, the clock is
* stopped and returns the same instant unless it is reset, advanced or retarded.
*
@mjstrasser
mjstrasser / StoppedClock.kt
Created November 18, 2024 07:11
Simple implementation of kotlinx.datetime.Clock for testing that is stopped unless changed
import kotlinx.atomicfu.atomic
import kotlinx.atomicfu.update
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlin.time.Duration
/**
* Simple implementation of [Clock] for testing. Once created, the clock is
* stopped and returns the same instant unless it is reset, advanced or retarded.
*
@mjstrasser
mjstrasser / README.md
Last active October 15, 2020 05:38
Run Seq with mkcert, NGINX SSL offloading in Docker Compose

What this does

Runs a single-user instance of Seq in Docker with NGINX offloading of a mkcert certificate, listening on port 45341. It also runs the Seq GELF listener in a third container.

Prerequisites

{
"name": "retry-axios",
"version": "1.0.0",
"description": "Retry function for axios promise-based HTTP client",
"scripts": {
"test": "jest --coverage"
},
"dependencies": {
"is-retry-allowed": "^1.1.0"
},
@mjstrasser
mjstrasser / StreamUtils.java
Last active June 5, 2018 04:13
Utilities for working with Java streams
package mjs.stream.utils;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class StreamUtils {
/**
* Converts a stream into an iterable for use by, e.g. Spring CrudRepository classes.
*/
@mjstrasser
mjstrasser / zipper.erl
Created March 19, 2017 01:21
Higher-order functions in practice from Functional Programming in Erlang MOOC
-module(zipper).
-compile(compile_all).
-include_lib("eunit/include/eunit.hrl").
%% Tail-recursive implementation of zip/2
%% that combines items into 2-tuples.
zip(Xs, Ys) -> lists:reverse(zip(Xs, Ys, [])).
% Stop when either list finishes.
zip([], _, Zs) -> Zs;
zip(_, [], Zs) -> Zs;
@mjstrasser
mjstrasser / index.erl
Created March 13, 2017 04:46
Index generator for week 2 assignment in Functional Programming in Erlang MOOC from University of Kent (futurelearn.com)
-module(index).
-export([get_file_contents/1,show_file_contents/1,
index_file/1, word_index/1]).
-include_lib("eunit/include/eunit.hrl").
%% Index the words in the specified file.
index_file(Filename) ->
word_index(get_file_contents(Filename)).
@mjstrasser
mjstrasser / keybase.md
Last active January 30, 2016 12:46
Keybase proof

Keybase proof

I hereby claim:

  • I am mjstrasser on github.
  • I am mjstrasser (https://keybase.io/mjstrasser) on keybase.
  • I have a public key whose fingerprint is F541 37DC 4A71 A203 BEE9 F12C A13D 44D8 2E90 4858

To claim this, I am signing this object: