Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View OndraZizka's full-sized avatar
🍊

Ondrej Zizka OndraZizka

🍊
View GitHub Profile
@OndraZizka
OndraZizka / switchHeadphones.sh
Last active March 25, 2024 12:58
Bluetooth headset - switch between quality sound + no mic (A2DP) and crappy sound and mic (HSP/HFP)
#!/bin/bash
#### Restart Bluetooth
if [ "$1" == "resetBT" ] ; then
sudo rfkill block bluetooth && sleep 0.1 && sudo rfkill unblock bluetooth;
exit;
fi;
#### Toggle listen/speak
if [ "$1" == "" -o "$1" == "toggle" ] ; then
@OndraZizka
OndraZizka / Slf4jLazy.kt
Last active February 22, 2024 11:28
Kotlin SLF4J log message lazy evaluation based on log level
/*
Lazy evaluation of the messages sent to Slf4j.
Usage:
log.trace { "State dump: " + expensiveLongSerialisation(state) }
See also https://jira.qos.ch/browse/SLF4J-371
*/
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import kotlin.reflect.KClass
@OndraZizka
OndraZizka / GoogleSheets-getCellLink.gs
Created August 27, 2022 09:22
Google Sheets custom function: Get a link from a given cell.
@OndraZizka
OndraZizka / StackBasedContext.kt
Created October 10, 2023 21:44
A Stack-based Processing Context for Kotlin
class StackBasedContext(
val nestingStack: Deque<NestingLevel> = ArrayDeque(),
val problems: MutableList<Pair<String, List<NestingLevel>>> = mutableListOf(),
) {
override fun toString() = nestingStack.ifEmpty { listOf("(root)") }.joinToString("/")
fun addProblem(msg: String) { problems.add(msg to nestingStack.descendingIterator().asSequence().toList()) }
fun pushLevel(dataParam: KParameter): PopOnClose { nestingStack.push(NestingLevel(dataParam)); return PopOnClose() }
fun pushLevel(collectionIndex: Int): PopOnClose { nestingStack.push(NestingLevel(collectionIndex = collectionIndex)); return PopOnClose() }
@OndraZizka
OndraZizka / ubuntu-openjdk-maven-docker.Dockerfile
Created October 27, 2022 21:37
Dockerfile: Ubuntu 22.04 + Docker + OpenJDK 18 + Maven 3.8
FROM ubuntu:22.04
ENV qqy="-qq -y -o=Dpkg::Use-Pty=0"
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get $qqy update > /dev/null \
&& apt-get $qqy install ca-certificates curl wget gnupg lsb-release > /dev/null \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
@OndraZizka
OndraZizka / git-moveBranch.sh
Last active September 8, 2023 10:41
Git: Rebase a (sub)branch from one base to another, leaving the other base's commits.
#!/bin/bash
## Places a branch to a new base.
## Useful when splitting a long branch to multiple pull requests.
##
## ---+--------master
## \
## --- A ---- B
##
## git-moveBranch.sh B from A to master
@OndraZizka
OndraZizka / ResourceUtils.kt
Created September 1, 2023 21:45
Kotlin - utilities for loading resources from the classpath.
import java.io.FileNotFoundException
import java.io.InputStream
import java.nio.file.Path
object ResourceUtils {
fun getCallingClassName(): String? {
var testUtilsSpotted = false;
for (stackItem in Thread.currentThread().stackTrace) {
if (stackItem.className == ResourceUtils::class.java.name) {
@OndraZizka
OndraZizka / jquery.snippet.css
Created June 2, 2016 00:05
jQuery Snippet syntax highlighter 2.0.0 source code (as fetched from http://www.timbermusicfest.com/winter/assets/js/snippet/)
.sh_acid{background:none; padding:0; margin:0; border:0 none;}.sh_acid .sh_sourceCode{background-color:#eee;color:#000;font-weight:normal;font-style:normal;}.sh_acid .sh_sourceCode .sh_keyword{color:#bb7977;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_type{color:#8080c0;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_string{color:#a68500;font-weight:normal;font-style:normal;}.sh_acid .sh_sourceCode .sh_regexp{color:#a68500;font-weight:normal;font-style:normal;}.sh_acid .sh_sourceCode .sh_specialchar{color:#f0f;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_comment{color:#ff8000;font-weight:normal;font-style:normal;}.sh_acid .sh_sourceCode .sh_number{color:#800080;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_preproc{color:#0080c0;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_symbol{color:#ff0080;font-weight:bold;font-style:normal;}.sh_acid .sh_sourceCode .sh_function{color:#046;font-weight:normal;font-style:normal;}.sh_aci
@OndraZizka
OndraZizka / fetchAllGitRepos.sh
Last active April 18, 2023 19:07
Fetch all Git repos in subdirectories
#!/bin/bash
## Run this in a directory to fetch all Git repos within it.
find -name .git | sed 's#.git##' | sort | xargs -t -n1 -I % git -C % fetch --all
## CRON job: You can also put this into `crontab -e` in order to keep all repos up-to-date automatically:
# # m h DoM mth DoW command
# */5 * * * * find /home/ondra/work -name .git | sed 's#.git##' | sort | xargs -t -n1 -I % git -C % fetch --all --tags --force
@OndraZizka
OndraZizka / startup.md
Created April 15, 2023 21:54 — forked from dsyer/startup.md
Notes on Spring Boot startup performance

Anatomy of Spring Boot Start Up Timing

When a Spring Boot app starts up with default (INFO) logging, there are some noticeable gaps (pauses). It's worth focusing on the gaps when looking for efficiency savings because of the amount of time they take, and because no-one bothered to log anything, so the chances are the app is doing something repetitive. We can tweak the logging levels to try and fill in the gaps and find out what is going on in there.

Basic empty web app with actuators has three such gaps:

0                                                                        1410ms
|------|---------------------------|-----|------|---------|--------|--------|
       |           578             |     |144(5)|         | 133(6) |