Skip to content

Instantly share code, notes, and snippets.

View tbnorth's full-sized avatar

Terry Brown tbnorth

View GitHub Profile
@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 = [
@tbnorth
tbnorth / gtp
Created March 1, 2021 17:27
git repo based file transfer
#!/bin/bash
# gtp put branch files
# gtp list
# gtp get # last branch
# gtp get branch
REPO=$HOME/gtp_repo
to_branch_name () {
#!/usr/bin/env python3
"""Create a repo auto_{dirname} on GitHub and add it as a remote for the
current repo. called 'auto'.
Expects GITHUB_USER and GITHUB_TOKEN in ~/.gh_auto:
GITHUB_USER = "gituser"
GITHUB_TOKEN = "647e67457e8e5e49ba56583fb6623cf0"
"""
import json
import os
import subprocess
@tbnorth
tbnorth / piwigo docker password reset .md
Last active August 8, 2020 21:17
piwigo docker password reset

Piwigo docker password reset

Most of the Piwigo password reset instructions assume you're familiar with MySQL or have access to phpAdmin. Here's how to reset a password in a docker deployment of Piwigo, without those assumptions.

  1. Get the MD5 hash of the password you want to use
    echo -n password1234 | m5dsum
@tbnorth
tbnorth / docker.sh
Last active October 3, 2022 14:10
Docker tricks
# compact docker ps
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}"
# *** START: MAINTENANCE ******************************
# remove non-running containers
docker rm $(docker ps -a -q -f status=exited -f status=dead)
# remove untagged images, selects column {2} (zero based) from lines starting with <none>
docker images | grep '^<none>' | sed -nE 's/^(\S+\s+){2}(\S+).*/\2/; p' | xargs docker image rm
# rebase "BRANCH" onto "MAIN", change these as needed
MAIN=main
BRANCH=tmp/docs
# should be no changed files before you start
[ -z "$(git status --porcelain --untracked-files=no)" ] || echo "Changed files in repo."
git checkout "$MAIN"
git pull
git checkout "$BRANCH" # before diff in case no local branch $BRANCH
git diff "$MAIN..$BRANCH" # just to inspect
# "compound 'compound .compound but not <spac>compound or compounds
cexpr system("find PATH -name \\*.py | xargs grep -n [.\\'\\\"]compound\\\\b")
# get list of files from a broken session
sed -n '/^cd / p; /^badd / {s/^badd [^ ]* //; H}; $ {x; s/\n/ \\\n/g; p}' /path/to/sessionfile.vim
# some paths will be relative to a folder, this prints the command to cd to the folder first
@tbnorth
tbnorth / config
Last active December 22, 2019 01:52
HP Intel laptop screen backlight control when xbacklight doesn't work
# i3 config
bindsym XF86MonBrightnessUp exec /home/tbrown/bin/undim # increase screen brightness
bindsym XF86MonBrightnessDown exec /home/tbrown/bin/dim # decrease screen brightness
# /home/tbrown/bin/undim
LVL=$(cat /sys/class/backlight/intel_backlight/brightness)
LVL=$(((LVL+20)%648))
echo $LVL >/sys/class/backlight/intel_backlight/brightness
# dim as above but -20
# check /sys/class/backlight/intel_backlight/max_brightness for % term
# sudo chown a+rw /sys/class/backlight/intel_backlight/brightness
@tbnorth
tbnorth / recgit.py
Created December 3, 2019 15:39
Show git status of all files in folder recursively.
#! /usr/bin/env python
"""
Show git status of all files in folder recursively.
Looks at files git status ignores because they're in
folders with no tracked files.
Handles nested repos.
"""