Skip to content

Instantly share code, notes, and snippets.

View janhicken's full-sized avatar

Jan Hicken janhicken

  • STACKIT
  • Hamburg, Germany
View GitHub Profile
@janhicken
janhicken / update_uv_deps.sh
Created January 21, 2025 10:26
Update Python packages managed by uv one package at a time creating atomic commits
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
search_updates() {
if [[ $# -gt 0 ]]; then
for arg in "$@"; do
uv lock --dry-run --upgrade-package "$arg"
done
else
uv lock --dry-run --upgrade
@janhicken
janhicken / urldecode.sh
Created October 29, 2024 08:01
URL decoding in pure Bash
#!/usr/bin/env bash
set -o nounset
while read -r line; do
# Convert '+' to ' '
with_spaces="${line//+/ }"
# Decode hex-encoded stuff using \x backslash escapes
printf '%b' "${with_spaces//%/\\x}"
done
@janhicken
janhicken / urlencode.sh
Last active October 29, 2024 08:05
URL encoding in pure Bash
#!/usr/bin/env bash
set -o nounset
while IFS= read -r -n 1 char; do
case "$char" in
[-_.~a-zA-Z0-9])
printf %s "$char"
;;
*)
printf '%%%02x' "'$char"
@janhicken
janhicken / docker_cleanup.sh
Created October 29, 2024 07:59
Script to clean up disk usage of Docker daemon artifacts: dangling images, container structure test, volumes
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
filters=(
'dangling=true'
'reference=registry.structure_test.oci.local/image:*'
'reference=cst.oci.local/*'
)
for arg in "$@"; do
@janhicken
janhicken / sep.sh
Created October 29, 2024 07:57
Print a nice ASCII-style section header / separator
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
print_usage() {
printf 'Usage: %s [-p PREFIX] [-w WIDTH] [WORDS...]\n' "$(basename "$0")" >&2
}
width=80
@janhicken
janhicken / wait_for_listen_on_port.sh
Last active November 4, 2024 08:54
A Bash script that runs a co-process and waits until any process is accepting connections on a specific local TCP port.
#!/usr/bin/env bash
# A script that runs a co-process and waits until any process is accepting connections on a specific local TCP port.
#
# Upon successfully connecting to that given port, a SIGTERM is sent to the co-process.
# No timeout is applied while waiting, however this script can conveniently wrapped in a TIMEOUT(1) call.
#
# This script requires no external tools and will make use of Linux' /proc file system.
if [[ $# -lt 2 ]]; then
printf 'Usage: %s PORT COMMAND [ARGS...]\n' "$0" >&2
@janhicken
janhicken / CloudFunctions.scala
Last active November 29, 2024 11:51
Google Cloud Functions with Scala.js
package de.janhicken.cfwithscala
import scala.scalajs.js.annotation.JSExportTopLevel
object CloudFunctions {
@JSExportTopLevel("helloWorld")
val helloWorld: CloudFunction = (request, response) ⇒ {
response.status(200).send("Hello World!")
}
}