Skip to content

Instantly share code, notes, and snippets.

View surfsoft's full-sized avatar

Phil Haigh surfsoft

View GitHub Profile
@surfsoft
surfsoft / Kotlin-Deserialization.md
Last active May 20, 2021 16:26
An approach to generic deserialization in Kotlin

An approach to generic deserialization in Kotlin

This gist outlines an approach to generic deserialization in Kotlin, using Vavr (which provides the Either functionality) and Jackson (for deserialization).

What it gives you is:

  • A single deserialization method for turning JSON into object graphs
  • The option to use custom deserialization methods for individual fields - or all fields of a particular data type
  • Little to no rework when the JSON model changes, beyond updating your data classes

In exchange all that is required is that the naming and structure of your model classes mirror your JSON naming and structure.

@surfsoft
surfsoft / kubernetes-for-bash.sh
Created April 15, 2021 11:26
Kubernetes productivity scripts (WIP)
#! /bin/bash
# A set of bash functions that provide simplified commands to perform common kubernetes functions
# Set the default context.
# $1 = some unique portion of the context you want.
# Will list matching contexts if $1 is not unique.
function set-context() {
MATCHES=$(kubectl config get-contexts | awk '{ print $1 }' | grep "$1" | wc -l)
if test $((MATCHES)) -eq 1 ; then
@surfsoft
surfsoft / kotlin-sanitising-string-deserialiser.md
Last active May 20, 2020 09:35
Selectively sanitising JSON string values in Kotlin

Selectively sanitising JSON string values in Kotlin

You've a JSON document you are consuming over REST, and you want to sanitise one or more string values to make sure nobody injects any pesky JavaScript that might end up as content on a web page somewhere? Look no further than a custom JSON deserialiser coupled with the OWSAP endcoder library:

The code

import com.fasterxml.jackson.core.*
import com.fasterxml.jackson.databind.*
import org.owasp.encoder.Encode
@surfsoft
surfsoft / update-ender-5-plus-firmware.md
Last active June 29, 2023 15:45
How to update the Creality Ender 5 Plus firmware

How to update the Creality Ender 5 Plus firmware

The downloads from Creality only include instructions and software for flashing the firmware from Windows. If you don't have access to a Windows machine there is another way: avrdude. However, there are a few steps you need to take to work out how to flash your printer.

These instructions refer specifically to the Ender 5 Plus but I've tried to make them a bit more open-ended so that you'll be able to work out how to do this for other printers in their range. They are fairly generic and therefore should work for both OSX/macOS and Linux users.

Before you start