Skip to content

Instantly share code, notes, and snippets.

View tim-klug's full-sized avatar

Tim tim-klug

  • Serrala Group GmbH
  • Hamburg
View GitHub Profile
@tim-klug
tim-klug / spring-snippets.md
Last active April 24, 2023 09:09
Spring Snippets

Spring Snippets

Injecting a value from properties into an Java Optional.

@Value("${my.propery.name:#{null}}")
private Optional<String> myPropery;

Using Mapstruct in non Spring tests

@tim-klug
tim-klug / java-stream-webflux-vavr-snippets.md
Last active February 28, 2023 08:53
Java stream, Webflux and Vavr snippets

Java stream, Webflux and Vavr snippets

nested Mono<>

public Mono<Either<AppError, UserDTO> > registerUser(RegisterUserDTO dto) {
return userFactory
        .create(dto.username(), dto.password(), UserRole.COMMON)
        .flatMap(it -> it
 .map(user -&gt; reactiveUserRepository
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBF+Qh/gBEADB7W+bMIy3gWNO90j+G5S1f5UBLu5VMd5vznUJYZUryZAegTjs
lCwQ3fILQa58IAqWIQ7qXSSj06KzxPB2jFHdJzwaNdZfggWeGddIantO2qtyOlOb
SPh1saUG91f9tdEvfQyJccaHs6FRC06c0aXBPcQzdK334wQgeFl5CAF2RM+b69M7
v5dqDcf+OYIM8SzRtkSbj+HuY8KG+7yqd6/o9g+yNFXZM6cEdAG4XZTYFt/UfsXK
aX+BG8nneEh0vb7mw7W1Hn5FTe3h5N2lIEpHrc8Qp+gXgMytdpVr4jYejK/6n4Yk
Pu+7DrLxJ+kATVlOrim9P1nntzSbrMgjKWaJl/XJMQDyEKq4fOtGWEu4C2qjuBNu
bUzdm2Wp181kPh6Yom8U5tRuOGZcjAyS08KOwso61ayC45+TtHp/NGhW5t+I6Xp7
X9DG2c5IEj/xl44c4qa3QrnDOg4bDNbmW7+Ppd7T9nA1+sq1kFgtw9DWQTZjUSAB
@tim-klug
tim-klug / shell-tricks.md
Last active April 24, 2023 06:18
[Shell-tricks]

bash-tricks

Command Result
Ctrl + L clear the actual window
sudo !! run the last command with sudo privileges
grep -Ev '^#|^$' <file> display file content with comments and empty lines
Ctrl + R search in bash history up
Ctrl + S search in bash history down
cd - go to the previous path
@tim-klug
tim-klug / java-functional.md
Last active June 20, 2021 15:08
Java Functional

Stream.ofNullable(possibleNullCollection) .flatMap(List::stream)

@tim-klug
tim-klug / mavne-cheat-sheet.md
Created April 28, 2021 08:07
[Maven Cheat Sheet]

Download all plugins for a project.

$> mvn dependency:resolve-plugins
@tim-klug
tim-klug / bash-snippets.md
Last active April 27, 2021 12:11
[Bash Snippets]

Ceritifcates

Check Certificate

#> openssl x509 -noout -text -in

curl

@tim-klug
tim-klug / gpg-agent-relay
Last active April 21, 2021 14:14
[GPG Agent Relay]
#!/usr/bin/env bash
# Inspired by https://blog.nimamoh.net/yubi-key-gpg-wsl2/
# Guide:
# Install GPG on windows & Unix
# Add "enable-putty-support" to gpg-agent.conf
# Download wsl-ssh-pageant and npiperelay and place the executables in "C:\Users\[USER]\AppData\Roaming\" under wsl-ssh-pageant & npiperelay
# https://github.com/benpye/wsl-ssh-pageant/releases/tag/20190513.14
# https://github.com/NZSmartie/npiperelay/releases/tag/v0.1
# Adjust relay() below if you alter those paths
@tim-klug
tim-klug / kafka-cheatsheet.md
Last active April 19, 2021 09:50
[Kafka Cheat Sheet] Cheat Sheet for Kafka #Kafka

Setup

The first thing to do is to run the landoop/fast-data-dev Docker image. For example:

docker run --rm -it -p 2181:2181 -p 3030:3030 -p 8081:8081 -p 8082:8082 -p 8083:8083 -p 9092:9092 -p 9581:9581 -p 9582:9582 -p 9583:9583 -p 9584:9584 -e ADV_HOST=127.0.0.1 landoop/fast-data-dev:latest

Note: Please follow the instructions on fast-data-dev README to customize the container.

@tim-klug
tim-klug / boxes.kts
Created May 23, 2020 19:38
Boxes riddle
listOf(2,2,2,1,2,2).asSequence()
.map{ it.toInt() }
.chunked(3)
.map { it.sortedDescending() }
.onEach { println(it) }
.zipWithNext { a, b ->
a.zip(b)
}
.onEach { println(it) }
.flatten()