Skip to content

Instantly share code, notes, and snippets.

View tbnorth's full-sized avatar

Terry Brown tbnorth

View GitHub Profile
@tbnorth
tbnorth / shell_tricks.md
Created June 17, 2024 21:32
Collection of git / sed / command line tricks

jira tickets referenced between two commits

PROJ=factotum ; git log ^staging dev | sed -E 's/'$PROJ'-[0-9]+/\n&\n/gI' | sed -En '/'$PROJ'-[0-9]+/I p' | tr a-z A-Z | sort -u | sed 's%.*%https://jira.example.com/browse/&%'

@tbnorth
tbnorth / getdeps.md
Last active June 14, 2024 12:21
Get list of actual dependencies for a Python project

If you're requirements.txt file is the output of pip freeze then it's really a lock file, not a list of project dependencies. To get just the actual dependencies:

find . -name \*.py -type f | xargs sed -En '/^(import|from)/ {s/\S+ //; s/ .*//; s/\..*//; p}' | sort -u >reqs

This extracts foo from all import foo.bar... and from foo.bar import... lines, dropping local imports (starting with '.').

@tbnorth
tbnorth / citrix_i3.md
Last active February 5, 2024 21:13
Making Citrix Workspace client run in i3 window manager

Citrix Workspace client with i3 window manager

Update: works with 24.04(beta) too, and problem still exists in 24.04.

This is how I got the Citrix Workspace client to run in Ubuntu 23.10 in Jan. 2024

Prior to version 2311 Citrix client, this patch was unnecessary, but at 2311 Citrix stopped launching successfully at all in i3.

In XFCE Citrix runs with "proper" full screen support, covering three monitors but

# TNB mods
# bind -n == bind -T root == no prefix
set -g lock-after-time 0 # Seconds; 0 = never
bind -n C-Left select-window -p
bind -n C-Right select-window -n
bind -n M-S-Left swap-window -t -1
bind -n M-S-Right swap-window -t +1
bind C-a select-window -l
# Fix ERROR: readlink /data/docker/overlay2/l/7M5EN7M5OUETAW42LC63NZBNJA: no such file or directory errors
docker image ls | while read row; do
image_id=$(echo $row | sed -E 's/^(\S+\s+){2}(\S+).*/\2/')
docker inspect --format='{{.GraphDriver.Data.MergedDir}}' $image_id || \
(echo -e "Broken image:\n$row"; echo docker image rm $image_id)
done
@tbnorth
tbnorth / uptag.py
Created June 14, 2022 13:04
Update tags file based on paths in tags file
#!/usr/bin/env python
"""Scans file to find folders on which ctags was originally run."""
import subprocess
from pathlib import Path
dirs = set()
for line in Path("tags").open():
if line.startswith("!"):
continue
# extract 'tests' from
"""Three ways to read data from a stream.
Suggested input:
one
three
END
one
three
END
@tbnorth
tbnorth / partialize.py
Last active January 26, 2022 20:52
Possibly useless partial / delayed execution Python experiment
from functools import partial, wraps, update_wrapper
from time import sleep
def partialize(func):
@wraps(func)
def _partial(*args, **kwargs):
part = partial(func, *args, **kwargs)
update_wrapper(part, func)
return part
@tbnorth
tbnorth / er.sh
Last active December 5, 2021 16:06
With gnu screen and vim turn terminal content into quickfix list and open in running vim (Python Traceback)
screen -X hardcopy $HOME/.tmp.err
sed 's/^ File "//; s/", line /:/; s/,.*/: -/' < $HOME/.tmp.err > $HOME/.tmp.cop
vim --remote-send '<Esc>:cexpr system("cat $HOME/.tmp.cop") | copen<CR>G'
screen -X select "vim --servername VIM"
@tbnorth
tbnorth / movewin.py
Created July 24, 2021 15:54
Relocate Windows 10 windows with Python script
"""Restore window layout in Windows 10
One way of launching, git bash script .sh file:
eval "$('/c/Users/username/pkg/miniconda/Scripts/conda.exe' 'shell.bash' 'hook')"
python "C:/Users/username/scripts/movewin.py"
"""
import win32gui
import re
POSITIONS = [