Skip to content

Instantly share code, notes, and snippets.

View smuuf's full-sized avatar

Přemysl Karbula smuuf

View GitHub Profile
@smuuf
smuuf / git-tidy-branch.sh
Last active February 23, 2026 14:18
git tidy-branch
#!/bin/bash
# Put this somewhere in your $PATH and git will automatically use it when you run "git tidy-branch".
echo "■ tidy-branch"
echo "■ Premysl Karbula, 2025"
echo
echo "■ Usage: git tidy-branch <parent branch>"
echo
echo "This will run interactive rebase of the current branch up to the first common commit with the specified parent branch."
echo "You should probably back up your current branch first."
@smuuf
smuuf / find_test_conflicts.py
Last active February 2, 2026 12:15
Python: Find conflicting tests with pytest (race conditions, dependency on order of tests)
"""
Runs repeatedly pytest with random ordering and tries to determine a minimal
set of tests that affect each other such that one of them fails because of
other tests being executed before it.
Usage:
$ python find_conflicting_tests.py path/to/tests/ [path/to/tests2/ ...] \
[... other pytest initial args, such as --random-order-seed=123]
Requirements:
@smuuf
smuuf / AesGcmCrypto.php
Last active May 30, 2025 23:22
AES-256-GCM encryption/decryption class in PHP
<?php
declare(strict_types=1);
class AesGcmCrypto {
private const CIPHER = 'aes-256-gcm';
/** 96-bit IV is standard for GCM. */
private const IV_LENGTH = 12;
@smuuf
smuuf / howto.md
Created February 23, 2025 16:47
WSL1 docker client with WSL2 docker daemon

WSL1 docker client with WSL2 docker daemon

  1. Install Docker engine in both WSL1 and WSL2.
  2. In WSL1: Create, configure and use new context:
    $ docker context create wsl2daemon
    $ docker context update --docker "host=tcp://[::]:2375" wsl2daemon
    $ docker context use wsl2daemon
    
  3. In WSL2: Configure the daemon in /etc/docker/daemon.json:
@smuuf
smuuf / darkize_git_gui.py
Last active November 27, 2025 10:17
git-gui dark theme patcher
#!/bin/env python
import os
import shutil
import optparse
import subprocess
from sys import stderr
FORCED_GIT_GUI_PATH=None
@smuuf
smuuf / gitdifffind.sh
Created January 13, 2023 09:27
Find string in git diff with info about function or class
#!/bin/bash
PREVIOUS="(@@.*function|class)" NEEDLE="getTraced" \
bash -c 'git diff | awk "(/$PREVIOUS/ && !/$NEEDLE/) {capture=1; buffer = \$0; next} capture==1 {buffer = buffer \$0 \"\n\"} (\$capture && /$NEEDLE/) {printf(\"%s\", buffer); capture=0}"'
@smuuf
smuuf / reorpyre.py
Created December 7, 2022 09:01
Re or Pyre2
import random
import logging
import re as module_re
import re2 as module_re2
USAGE_PROBABILITY = 0.5
USE_ONLY_PYRE2 = True
@smuuf
smuuf / settings.json
Last active March 23, 2025 19:37
Settings for vscode highlight extension
{
// PHP highlights for https://github.com/fabiospampinato/vscode-highlight
"highlight.regexes": {
"(NOTE:)\\s": {
"regexFlags": "g",
"filterLanguageRegex": ".*",
"decorations": [
{
"color": "#CFC8A6",
"backgroundColor": "#CFC8A440",
@smuuf
smuuf / psleep.sh
Last active June 2, 2022 14:16
Bash sleep with countdown
#!/bin/bash
function psleep {
S="$1"
O="$S"
while [ $S -gt 0 ]; do
echo -ne "\r$S s (from $O) "
sleep 1
((S--))
done
@smuuf
smuuf / git-add-regex.sh
Created May 26, 2022 22:53
Git add / stage lines matching regex
#!/bin/bash
# Put this into your .bashrc, or whatever.
function git-add-regex {
git diff -U0 | grepdiff -E "$1" --output-matching=hunk | git apply --cached --unidiff-zero
}