Skip to content

Instantly share code, notes, and snippets.

@iwconfig
iwconfig / bdecode.py
Created December 8, 2025 01:11
bencode decoder
import sys
import json
def bdecode(bencoded_bytes):
def decode_int(b, i):
j = b.find(b'e', i)
return int(b[i:j]), j + 1
def decode_bytes(b, i):
colon = b.find(b':', i)
@iwconfig
iwconfig / bdecode.sh
Last active December 8, 2025 01:06
bencode decoder vibe coded in bash. it's slow :)
#!/bin/bash
# ==============================================================================
# Pure Bash Bencode to JSON Converter
# ==============================================================================
# Usage: curl ... | bash bdecode.sh
# Dependencies: od, tr, sed (Standard POSIX tools)
# ==============================================================================
set -e
@iwconfig
iwconfig / inotify.py
Created November 22, 2025 17:13
Pure-python inotify
#!/usr/bin/env python3
# Minimal pure-Python inotify example (no external packages)
import ctypes
import ctypes.util
import os
import struct
import sys
import errno
import selectors
@iwconfig
iwconfig / ncatfun.sh
Created October 27, 2025 03:09
simple directory tree browser
ncat -lk -p 8000 --sh-exec '
{
read request
url_path=$(echo "$request" | awk "{print \$2}" | sed "s|//\+|/|g")
current_path=${url_path%/}
echo $current_path > /dev/stderr
html=$(tree "$url_path" -H .)
@iwconfig
iwconfig / batch-process-rclone.sh
Created October 7, 2025 10:47
run rclone copy/sync/whatever in batches of ≤ N files
# batches of 200 with a ~5-180 seconds delay
# the `cat "{}" >/dev/null &` pre‑caches the vfs, reducing telegram io load and speeding rclone.
find /some/dir -type f -printf '%P\n' -exec sh -xc 'cat "{}" >/dev/null &' \; |
xargs -n200 -d '\n' bash -c '
printf "%s\n" "$@" |
rclone -v sync --check-first --transfers 4 -PM --files-from - \
/some/dir/ some-remote:some/remote/dir/ --error-on-no-transfer &&
{ s=$((RANDOM % 176 + 5)).$RANDOM; echo sleeping $s seconds; sleep $s; }
' _
@iwconfig
iwconfig / asdf.sh
Last active June 22, 2025 13:38
executes a set of commands in sequence and each output can be wrapped in html <details> code. useful for reproducing stuff in GH issues. WIP: will perhaps make it usable for anything thus not hardcode stuff
#!/usr/bin/env bash
# reproduce commands and wrap output in spoilers
set -eu
export LC_ALL=C
# defaults:
FILE=test.txt
DIR=/tmp
REMOTE=teldrive-testbench:
@iwconfig
iwconfig / no-subscription-nag.sh
Created May 6, 2025 20:52
This removes the no-subscription reminder in Proxmox VE/BS, adapted from the helper-script. I ended up not needing it, so I'm dumping it here.
#!/bin/bash
echo "Supporting the software's development team is essential."
echo "Check their official website's Support Subscriptions for pricing."
echo "Without their dedicated work, we wouldn't have this exceptional software."
if ! dpkg -V proxmox-widget-toolkit | grep -q '/proxmoxlib\.js$'; then
sed -i '/data\.status.*{/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js
echo "Disabled subscription nag. Please reload your browser cache."
fi
@iwconfig
iwconfig / pipx-bin.py
Created April 30, 2025 21:15
Modified `pipx` executable for use within a Flatpak environment, setting up necessary environment variables to isolate `pipx` from the host system. Replace the content of `pipx` with `pipx-bin.py`.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import os
import sys
if __name__ == '__main__':
BASE_DIR = f'{os.environ['HOME']}/.var/app/com.vscodium.codium-insiders'
os.environ['PIPX_HOME'] = f'{BASE_DIR}/data/pipx'
@iwconfig
iwconfig / paste-to-file.py
Created April 18, 2025 20:56
A simple utility for quickly scaffolding files without having to manually create directory structures or files beforehand. It lets you paste text where the very first line (a # comment) specifies the file path. It then writes the rest of the text into that file, automatically creating any necessary directories.
import os
def main():
print("Paste your text (end with an EOF signal: Ctrl-D on Unix/Mac, Ctrl-Z then Enter on Windows):")
try:
# Read multiline text from standard input until EOF
input_text = []
while True:
line = input()
input_text.append(line)
@iwconfig
iwconfig / hashbench.py
Created April 8, 2025 11:59
Compare performance of SHA-256 and BLAKE2 on your CPU. Useful for choosing encryption mode for Borg repositories, for example.
import hashlib
import time
data = b'a' * (10**6) # 1 MB of data
# Benchmark SHA-256
start = time.time()
for _ in range(1000):
hashlib.sha256(data).hexdigest()
print("SHA-256 time:", time.time() - start)