Skip to content

Instantly share code, notes, and snippets.

Avatar
😷

Björn Kahlert bkahlert

😷
View GitHub Profile
@bkahlert
bkahlert / UndefinedToNullMappingWebMvcRegistrationsConfiguration.java
Last active Jan 31, 2020
For Spring Boot: unified query parameter parsing with undefined value, like in `?foo&bar=&baz=string`
View UndefinedToNullMappingWebMvcRegistrationsConfiguration.java
import lombok.SneakyThrows;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.MethodParameter;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.lang.NonNull;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;
@bkahlert
bkahlert / copy-out.sh
Created Jan 17, 2021
POSIX shell script to copy-out / extract files and directories from img files, works with EXT4
View copy-out.sh
#!/bin/sh
# Abort script at first error, when a command exits with non-zero status
# (except in until or while loops, if-tests, list constructs)
set -e
# Attempt to use undefined variable outputs error message, and forces an exit
set -u
# Similar to verbose mode (-v), but expands commands
#set -x
@bkahlert
bkahlert / MultiReceiver.kt
Last active Feb 25, 2021 — forked from Takhion/MultiReceiver.kt
Multiple receivers in Kotlin
View MultiReceiver.kt
fun <A, B, C, R> multiReceiver(f: A.() -> B.() -> C.() -> R) = { a: A, b: B, c: C -> f(a)(b)(c) }
val sample1: (X, Y, Z) -> Int = multiReceiver { { { x + y + z } } }
val sample2: X.() -> Y.() -> Z.() -> Int = { { { x + y + z } } }
class X(val x: Int)
class Y(val y: Int)
class Z(val z: Int)
fun main() {
@bkahlert
bkahlert / JsonBannerDemo.java
Last active Apr 28, 2021
Enabled Spring Boot banner while using JSON formatted logging using spring.main.banner-mode=LOG
View JsonBannerDemo.java
package demo;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;