Skip to content

Instantly share code, notes, and snippets.

@jiffle
jiffle / refactorsafe-enum-kotlin.kts
Created September 9, 2021 08:09
Refactor-Safe Enum Pattern in Kotlin
import com.fasterxml.jackson.annotation.JsonValue
enum class AccountStatus(@JsonValue val text: String) {
PENDING("Pending"),
ACTIVE("Active"),
EXPIRED("Expired"),
CANCELLED("Cancelled");
companion object {
private val valuesByText = values().associateBy { it.text }
@jiffle
jiffle / strikt-cheatsheet.md
Last active March 2, 2023 15:44
Strikt Cheatsheet

Tricks and tips for using Strikt assertions

Strikt is very powerful, however it is sometimes hard to find particular methods. This is a handy cheatsheet.

Basics

Top-level assertions

expect, expectThat, expectCatching and expectThrows

@jiffle
jiffle / git-tricks.md
Created August 26, 2018 11:07
Git History Rewriting Tricks

Git History Rewriting Tricks

Removing incorrectly committed files from the last commit

This uses a Soft Reset to revert the commit, leaving the commit modifications as local working copy changes:

git reset --soft HEAD^ or git reset --soft HEAD~1

@jiffle
jiffle / Kotlin Coroutines Cheatsheet.md
Last active June 20, 2018 05:16
Guide on Kotlin Coroutines for muggles

Core Language Methods

Block method Returns Thread Notes
launch Job From Pool parameter
async Deferred From Pool parameter Use await to get result
withTimeout value from Coroutine From Pool parameter
thread Null New thread Not a coroutine, but same as launch

Launch Methods

@jiffle
jiffle / kotlin-language-cheatsheet-part1.md
Last active March 3, 2018 15:28 — forked from dodyg/gist:5823184
Kotlin Programming Language Cheat Sheet Part 1

Kotlin Programming Language - Part 1

Kotlin language website is at https://kotlinlang.org.

All the codes here can be copied and run on Kotlin online editor.

Basics

  • You do not need ; to break statements.
  • Comments are similar to Java or C#, /* This is comment */ for multi line comments and // for single line comment.
@jiffle
jiffle / Kotlin-Nullability-Cheatsheet.md
Last active March 28, 2023 12:18
Kotlin Nullability Cheatsheet

Kotlin provides significantly improved support for nullable (and non-nullable) types.

These are all the language and Kotlin library features that help support working with nullable types:

Fundamentals

Non-nullable type declaration:

var a: String = "abc"
@jiffle
jiffle / Evolving REST Services.md
Last active July 9, 2024 16:20
Evolving REST Services and Backward Compatibility

Evolving Rest Services and Backward Compatibility

My aim is to define a set of rules that can be used to decide whether an incremental data change is backwardly compatible or not, list things to beware of for a particular change, and mitigations that can be put in place.

Clearly it is assumed that the services will be using API versioning, and that a major API version number change would allow any required change to that API. The scope of this document is to explore what changes can be made within a single API version.

Main Release Management models

There are four main release management models, each of which has its own requirements and challenges in versioning the APIs.

@jiffle
jiffle / Effective Email Cheatsheet.md
Last active February 20, 2023 10:30
Effective Email Style Cheatsheet

Military Style For Effective Email Communications

The military structure their communications for maximum clarity and conciseness. These are the key points to write emails in an fffective manner:

1. Prefix Email subject with keyword

Format: STATUS - Message Title

Status keywords:

@jiffle
jiffle / Spock Cheatsheet.md
Last active May 9, 2024 14:19
Spock Useful Patterns Cheatsheet

Spock Useful Patterns Cheatsheet

Adding sequences of behaviour to Mocks and Stubs

The >>> operator allows a sequence of values to be returned:

myMock.someCall() >>> ['first value', 'second value', 'third value', 'etc']

This returns each string in turn. Behaviour (such as throwing exceptions) in closures cannot be used by this operator.

The >> operator allows value or behaviour (closures) to be returned

@jiffle
jiffle / Java 8 Patterns Cheatsheet.md
Last active May 3, 2022 15:48
Cheatsheet of Standard Design Patterns implemented using Java 8 Lambdas

Design Patterns implemented in Java 8

These patterns are implemented using Java 8 Lambdas (together with Project Lombok annotations).

Factory Pattern

Factory I : No Parameter Constructor

Enum class: