Skip to content

Instantly share code, notes, and snippets.

@nijave
nijave / ubuntu-k8s.sh
Created March 27, 2024 22:09
Kubernetes and cri-o v1.29 repo setup for Ubuntu 22.04 (jammy)
K8S_VERSION_MINOR=1.29
# Repos for cri-o
curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/stable:/v${K8S_VERSION_MINOR}/deb/Release.key |
gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg] https://pkgs.k8s.io/addons:/cri-o:/stable:/v${K8S_VERSION_MINOR}/deb/ /" |
tee /etc/apt/sources.list.d/cri-o.list
# Repo for Kubernetes tools/components
curl -fsSL https://pkgs.k8s.io/core:/stable:/v${K8S_VERSION_MINOR}/deb/Release.key |
@nijave
nijave / tg-tldr.sh
Created December 13, 2023 22:18
Terragrunt pretty print
# 1. Find colored lines
# 2. Strip out useless lines
# 3. Strip empty "colored" lines
grep --color=never $'\x1b''\[[0-9;]*' \
| grep -vE 'Terraform has been|Initializing |use this backend unless the backend configuration changes|commands will detect it and remind you to do so if necessary|Refreshing state...|Read complete after |Reading...| copy_backend_before_init |Terraform has compared your real infrastructure|No changes.' \
| sed -E '/^'$'\x1b''\[0m'$'\x1b''\[32m/d'
sudo dnf install -y VirtualBox-server
# Make a vhd
qemu-img create -f vpc test.vhd 8G
virt-format -a test.vhd --partition=gpt --filesystem=ntfs
echo 'write /readme.txt "readme"' | guestfish -a test.vhd -m /dev/sda1
mkdir test
vboximg-mount --image $(pwd)/test.vhd --rw --root test
mkdir testfs
@nijave
nijave / dd-k8s-ns.sh
Created June 1, 2023 15:32
Docker Desktop Kuberentes Auto Provision Namespace
docker run --rm --privileged --pid=host ubuntu:22.04 \
nsenter -t 1 -m -u -n -i \
sh -c "sed -i '/enable-admission-plugins/{/NamespaceAutoProvision/b; s/$/,NamespaceAutoProvision/}' /etc/kubernetes/manifests/kube-apiserver.yaml"
python3 -c '
import json
import sys
from urllib.parse import urlparse, parse_qs
print(json.dumps(parse_qs(urlparse(sys.argv[1]).query)))
'
@nijave
nijave / borg-qdirstat.py
Last active April 27, 2023 00:24
Generates a qdirstat cache file from a borgbackup archive
"""
See section about "Reading and writing cache files" for how this works
with QDirStat https://github.com/shundhammer/qdirstat/blob/master/README.md?plain=1#L848
`borg list` should run without prompting for credentials. See borg docs for configuring
environment variables https://borgbackup.readthedocs.io/en/stable/quickstart.html#automating-backups
"""
import dataclasses
import datetime
import gzip
@nijave
nijave / fix_truncate_json.py
Last active April 24, 2023 18:29
Makes json parseable if the end got lopped off
def fix_truncated_json(err_json: str) -> str:
"""closes open delimiters so json is parseable"""
stack = []
expect_literal = False
last_literal = []
for i, c in enumerate(err_json):
if c == '"':
if i > 0 and err_json[i-1] == '\\':
continue
if stack[-1] == '"':
@nijave
nijave / directory-stats-watcher.py
Created December 28, 2022 18:19
Directory stats watcher. Collect file count and file size continually using inotify
#!/usr/bin/env python3
"""
Use inotify to monitor the file count and size of a given directory.
There may be small race conditions that lead to count/size errors
so output should be considered a close estimate.
* Requires only Python 3 stdlib & Linux
"""
@nijave
nijave / leekduck-box-scraper.py
Created December 28, 2022 04:18
Leekduck Pokemon Go Box Scraper
from bs4 import BeautifulSoup
import pandas as pd
import requests
import re
import json
search_url = "https://leekduck.com/boxsales/"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0",
@nijave
nijave / archive-org-capture-dates.py
Created December 28, 2022 03:40
Archive.org capture date dumper
import requests
search_url = "https://leekduck.com/boxsales/"
headers = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:108.0) Gecko/20100101 Firefox/108.0",
"Referer": "https://web.archive.org/web/*"
}
sparklines = requests.get(