Skip to content

Instantly share code, notes, and snippets.

View bkahlert's full-sized avatar
😷

Björn Kahlert bkahlert

😷
View GitHub Profile
@bkahlert
bkahlert / UndefinedToNullMappingWebMvcRegistrationsConfiguration.java
Last active January 31, 2020 01:50
For Spring Boot: unified query parameter parsing with undefined value, like in `?foo&bar=&baz=string`
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 / MultiReceiver.kt
Last active February 25, 2021 23:06 — forked from Takhion/MultiReceiver.kt
Multiple receivers in Kotlin
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 / copy-out.sh
Last active August 24, 2021 10:08
POSIX script to access EXT4 partitions in img files
#!/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 / JsonBannerDemo.java
Last active February 12, 2022 12:22
Enabled Spring Boot banner while using JSON formatted logging using spring.main.banner-mode=LOG
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;
@bkahlert
bkahlert / init.gradle.kts
Created February 20, 2023 11:48
Remove .DS_Store from Gradle build directory before running tasks—globally, that is from any built project
/**
* [Gradle init script](https://docs.gradle.org/current/userguide/init_scripts.html) that has
* to be places in one of the [documented locations](https://docs.gradle.org/current/userguide/init_scripts.html#sec:using_an_init_script),
* for example
* - `$GRADLE_USER_HOME/init.gradle.kts`, respectively
* - `$HOME/init.gradle.kts
*/
rootProject {
logger.info("Running init script on $name")
@bkahlert
bkahlert / error-handling-out.md
Last active August 10, 2023 17:52
Bash Error Handling — shell options -e/errexit, inherit_errexit, -E/errtrace and the ERR trap

Bash Error Handling — shell options -e/errexit, inherit_errexit, -E/errtrace and the ERR trap

This Markdown file is 90% the output of error_handling.bash.

I wrote the script / this document to describe the shell options errexit, inherit_errexit, and errtrace as well as the ERR trap and their conditions and interactions in more detail as this is what I always failed to understand with the pieces of information I found so far.

References