Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Konfekt / git-autorebase.py
Created February 28, 2026 12:13
autorebase all feature branches onto main
#!/usr/bin/env python3
"""Autorebase feature branches onto main/master without switching your current branch."""
# Uses https://github.com/Timmmm/autorebase as a reference
from __future__ import annotations
import argparse
import os
import subprocess
import sys
@Konfekt
Konfekt / npv.sh
Last active February 25, 2026 16:24
Reverse tether a local VPN; requires gnirethet and adb
#!/usr/bin/env bash
# Ensure a single responsive adb server before running gnirehtet, and prevent
# hangs from stuck or duplicated adb server processes.
# Trace exit on error of program or pipe (or use of undeclared variable).
set -o errtrace -o errexit -o pipefail # -o nounset
# Optionally debug output by supplying TRACE=1.
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
if ((BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4))); then
shopt -s inherit_errexit
@Konfekt
Konfekt / firefox-screenshot.sh
Created February 24, 2026 10:58
Convert file to PNG using Firefox's headless screenshot feature
#!/usr/bin/env bash
# Render a local file (or URL) to PNG using Firefox headless screenshot.
# This is often a high-fidelity rasterizer for SVG/HTML/CSS compared to some converters.
set -o errtrace -o errexit -o pipefail
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
if [[ "${BASH_VERSINFO:-0}" -gt 4 || ( "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ) ]]; then
shopt -s inherit_errexit
fi
@Konfekt
Konfekt / find.vim
Created February 21, 2026 10:11
Set &findfunc to git-ls-files inside repo and fall back rg, ugrep or fd outside of it
" Purpose: Fast file finding via 'findfunc', with caching and git-aware file listing.
augroup vimrcFind
autocmd!
augroup END
" Scheduling niceness on Linux.
let s:scheduler = has('unix') && executable('chrt') && executable('ionice') ?
\ 'chrt --idle 0 ionice -c2 -n7 ' : ''
@Konfekt
Konfekt / mutt-view-html-with-images.py
Created February 20, 2026 20:55
View an HTML email with CID-embedded images in w3m from mutt/neomutt
#!/usr/bin/env python3
"""
View an HTML email with CID-embedded images in w3m from mutt/neomutt using a
macro in muttrc that pipes the whole message to this script such as
macro index l "<pipe-message>mutt-view-html-with-images.py<enter>" "View HTML with images"
Steps performed by the script:
1. Pipe the raw message to stdin.
@Konfekt
Konfekt / vim-compile.sh
Last active March 3, 2026 11:23
Compile Vim from source with dynamic Python 3 support for virtual environments
#!/usr/bin/env bash
# trace exit on error of program or pipe (or use of undeclared variable)
set -o errtrace -o errexit -o pipefail # -o nounset
# optionally debug output by supplying TRACE=1
[[ "${TRACE:-0}" == "1" ]] && set -o xtrace
if [[ "${BASH_VERSINFO:-0}" -gt 4 || ( "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ) ]]; then
shopt -s inherit_errexit
fi
@Konfekt
Konfekt / markdown_movement.vim
Created January 29, 2026 13:43
Drop-in Vim(9) Markdown text objects
if !has("vim9script") | finish | endif
vim9script
# Adapted from https://github.com/habamax/.vim/blob/7e2bac788a3a6de59356374ea60d90b5dec68b2e/after/ftplugin/markdown.vim
# Markdown header text object
# * inner object is the text between prev section header(excluded) and the next
# section of the same level(excluded) or end of file.
# * an object is the text between prev section header(included) and the next section of the same
# level(excluded) or end of file.
@Konfekt
Konfekt / aegis2pass.py
Created December 28, 2025 07:52
Import Android Aegis authenticator (encrypted) JSON export to pass; superseded by pass-import but left as stand-alone tool here
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "cryptography>=42",
# ]
# [tool.uv]
# exclude-newer = "2025-12-26 00:00"
# ///
@Konfekt
Konfekt / pyrefly_operator.vim
Created December 25, 2025 18:15
check Python code snippets on the fly with pyrefly
" Check Python code snippets on the fly with pyrefly.
" Put into ~/.vim/plugins` and use the mapping `g4` on a visual selection or a text object.
if exists('g:loaded_pyrefly_operator') | finish | endif
let g:loaded_pyrefly_operator = 1
if !executable('pyrefly') | finish | endif
let s:pyrefly_efm = join([
\ '%E%\s%#ERROR %m',
@Konfekt
Konfekt / c_compdb.vim
Last active March 6, 2026 14:59
Automatically generate compile_commands.json for clangd Language Server in Vim; put into ~/.vim/ftplugin/
" Generate compile_commands.json for clangd.
" Prefer CMake export, else Ninja compdb, else Bear + Make with optional append.
if exists('b:did_c_compdb_ftplugin') | finish | endif
let b:did_c_compdb_ftplugin = 1
let s:inflight = {}
augroup c_compdb
autocmd! * <buffer>