Skip to content

Instantly share code, notes, and snippets.

@giner
giner / enable-automatic-reboot-after-unattended-upgrade.sh
Created November 2, 2026 11:34
Ubuntu: Enable automatic reboot after unattended upgrade
#!/bin/sh
echo 'Unattended-Upgrade::Automatic-Reboot "true";' | sudo tee /etc/apt/apt.conf.d/99unattended-upgrades-custom
@giner
giner / grpc_health.sh
Last active July 27, 2026 06:30
Check GRPC health using bash and curl
#!/bin/bash
# grpc_health.sh
grpc_health() {
local max_time
local insecure=false
local connect_only=false
local args=()
@giner
giner / json-to-assoc-array.sh
Last active June 29, 2026 09:20
Convert a JSON object to a Bash associative array
#!/bin/bash
# json-to-assoc-array.sh: Convert a JSON object to a Bash associative array.
json_object_to_bash_assoc_array_usage() {
cat <<'EOF'
Usage:
json_object_to_bash_assoc_array [OPTIONS] JSON_OBJECT VAR_NAME
Convert a JSON object to a Bash associative array.
@giner
giner / bit-manipulation.jq
Last active June 22, 2026 05:44
jq bit manipulation functions
# Examples:
# [3, 5] | bitor -> 7
# [null, 3] | bitor -> 3
# [] | bitor -> null
def bitor:
map(select(. != null)) | unique |
if length == 0 then null
elif length == 1 then first
elif any(. == -1) then -1
else (map(. % 2 | abs) | max) + 2 * (map(. / 2 | floor) | bitor)
@giner
giner / gist:cbc8b0902a94f7ad6e50a1e83fa88a05
Last active April 6, 2026 03:39
Workflow to test Truthy and Falsy expressions in GitHub Actions conditionals
on:
push:
jobs:
test-github-actions-expressions-in-conditionals:
runs-on: ubuntu-latest
steps:
# Note that in conditionals, falsy values (false, 0, -0, "", '', null) are coerced to false and truthy (true and other non-falsy values) are coerced to true.
# See https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#literals
- run: "echo \"if: always() && 0 == false\""
@giner
giner / gist:dbf695c0a35ed948cf686820662508dd
Created March 22, 2026 13:50
Compile and install bccmd
curl -O https://www.kernel.org/pub/linux/bluetooth/bluez-5.55.tar.xz
tar -xf bluez-5.55.tar.xz
cd bluez-5.55
gcc tools/{bccmd,csr*,ubcsp}.c -o tools/bccmd -I. $(pkg-config --cflags --libs bluez)
mkdir -p ~/bin
cp tools/bccmd ~/bin/
@giner
giner / read-vars.sh
Last active December 9, 2025 18:19
Read values for specified environment variables from user input if they are not already set or not exported and print export commands
# Moved to https://github.com/giner/bash-libs/blob/main/read-vars.sh
@giner
giner / configure_bash_prompt_for_git.sh
Created January 30, 2025 03:44
Add Git info to Bash prompt
#!/bin/bash
set -eu
# Add Git info to Bash prompt
bash_prompt_configuration=(
'PS1="${PS1%\\$ }\$(__git_ps1)\\$ "'
'GIT_PS1_SHOWDIRTYSTATE=1'
)
@giner
giner / xorg_remap_play_to_micmute.sh
Last active November 30, 2021 03:46
Remap Play button to Mic Mute (primarily for Bluetooth Headsets)
#!/bin/sh
# NOTE: This change won't persist if package xkb-data is reinstaled or updated
sudo sed -i '/key <I208>/s/\bXF86AudioPlay\b/XF86AudioMicMute/' /usr/share/X11/xkb/symbols/inet
@giner
giner / HelloFeignmTLS.java
Last active March 2, 2025 14:10
Java: Feign Client mTLS (by enabling custom keystore and truststore for a specific enpoint)
// How to test
//
// Update uriPrefix, keystoreFile, keystorePassword, truststoreFile, truststorePassword with your values and run:
// curl -L -O https://repo1.maven.org/maven2/io/github/openfeign/feign-core/11.6/feign-core-11.6.jar
// java -cp feign-core-11.6.jar HelloFeignmTLS.java
// Feign
import feign.Feign;
import feign.RequestLine;