Skip to content

Instantly share code, notes, and snippets.

@gchait
gchait / android-debloat.sh
Last active December 15, 2025 21:12
Debloat matching packages via ADB without root
#!/bin/bash -eu
set -o pipefail
readonly USER_ID=0
list_packages() {
local flags="${1:-}"
local cmd=(adb shell cmd package list packages --user "${USER_ID}")
[[ -n "${flags}" ]] && cmd+=("${flags}")
@gchait
gchait / spark-cpu-ms.sh
Created December 14, 2025 18:23
Sum the CPU time an Apache Spark Application took
curl -s https://xxx.yyy.com:18080/api/v1/applications/app-zzz-123/stages | \
jq '[ .[] | .executorCpuTime // 0 ] | add / 1e6'
@gchait
gchait / aws-profile-from-acc.sh
Created December 13, 2025 13:25
Set AWS profile given an account ID
export AWS_PROFILE=$(grep -B20 "${ACCOUNT_ID}" ~/.aws/config | \
grep "^\[" | tail -1 | tr -d "[]" | awk '{print $NF}')
@gchait
gchait / git-dl.sh
Created December 13, 2025 13:15
Download a Git repository at a specific commit
mkdir -p xxx
cd ./xxx
git init -q
git remote add origin git@aaa.zzz.com:yyy/xxx.git
git fetch origin "${SHA}"
git checkout -q FETCH_HEAD
@gchait
gchait / inline-java.sh
Created December 13, 2025 13:05
Run Java stdlib from Bash without JShell
echo 'public class X{public static void main(String[]a)throws Exception{System.out.println(java.net.InetAddress.getLocalHost().getCanonicalHostName());}}' > X.java \
&& javac X.java && java X && rm X.java X.class
@gchait
gchait / provision-with-sudo.sh
Created December 13, 2025 12:50
Run many functions as root with injected environment variables
provision() {
xx() {
:
}
yy() {
:
}
zz() {
@gchait
gchait / msk-privatelink.tf
Created December 13, 2025 12:46
An old and involved way to PrivateLink MSK brokers
@gchait
gchait / uvicorn_filter.py
Created December 13, 2025 12:40
Hide an endpoint from Uvicorn access logs
class EndpointFilter(Filter):
"""A generic way to filter out web endpoints from the logs."""
# pylint: disable=too-few-public-methods
def __init__(
self,
path: str,
*args,
**kwargs,
@gchait
gchait / grype_exporter.py
Created December 13, 2025 12:28
Expose Grype-found vulnerabilities to Prometheus
from itertools import islice
from subprocess import run
from tempfile import NamedTemporaryFile
from time import sleep
from typing import NamedTuple
import kubernetes.client
import kubernetes.config
import prometheus_client
@gchait
gchait / clean-previous-images.sh
Created December 13, 2025 12:22
Keep only a specific tag from a Docker repository
# shellcheck disable=SC2086
docker images -q "${DOCKER_REPO_FULL}" | \
grep -v "$(docker images -q ${DOCKER_IMAGE})" | \
xargs --no-run-if-empty docker rmi -f