Skip to content

Instantly share code, notes, and snippets.

@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] == '"':
# see https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
import requests
from requests.adapters import HTTPAdapter, Retry
class TimeoutHTTPAdapter(HTTPAdapter):
DEFAULT_TIMEOUT = 30
def __init__(self, *args, **kwargs):
@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(
@nijave
nijave / migrate.sh
Last active October 31, 2022 18:51
Postgres database migration with pg_dump and logical replication
#!/bin/bash
export PGSSLMODE=prefer
DATABASE=postgres
USER=postgres
SOURCE_PASSWORD=postgres
SOURCE_HOST=$(docker inspect postgres-5433 | jq -r '.[0].NetworkSettings.IPAddress')
SOURCE_PORT=5432
@nijave
nijave / ssh-pod.sh
Last active July 16, 2022 00:12
Privileged k8s "ssh" pod
#!/usr/bin/env bash
pod_name=nick-ssh
# the first node
k8s_node=$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')
cat <<EOF | kubectl create -f -
apiVersion: v1
kind: Pod
@nijave
nijave / crystal-disk-mark-fio-bench.sh
Last active July 10, 2022 02:11 — forked from O1ahmad/crystal-disk-mark-fio-bench.sh
CrystalDiskMark-esque Disk Benchmark (using fio)
#!/bin/bash
LOOPS=3 # How many times to run each test
SIZE=10240 # Size of each test, multiples of 32 recommended for Q32 tests to give the most accurate results.
WRITEZERO=0 # Set whether to write zeroes or randoms to testfile (random is the default for both fio and crystaldiskmark); dd benchmarks typically only write zeroes which is why there can be a speed difference.
QSIZE=$(($SIZE / 32)) #Size of Q32Seq tests
SIZE+=m
QSIZE+=m
@nijave
nijave / jellyfin-contine-watching.sql
Created March 14, 2022 02:46
Jellyfin playbackPositionTicks info query
SELECT
key, COALESCE(ti.SortName, mi.sortname) SortName, COALESCE(ti.Path, mi.Path) Path
FROM UserDatas u
LEFT JOIN TypedBaseItems ti
ON
u.key = ti.UserDataKey
OR REPLACE(u.key, '-', '') = ti.PresentationUniqueKey
LEFT JOIN MediaItems mi
ON
REPLACE(u.key, '-', '') = mi.PresentationUniqueKey