Skip to content

Instantly share code, notes, and snippets.

@JacobHayes
JacobHayes / black_fmt_history.py
Last active January 30, 2024 06:22
Reformat python files in git history w/ Black (line=100, py3.7/3.8)
#!/usr/bin/env python3
#
# Modified from https://github.com/newren/git-filter-repo/blob/master/contrib/filter-repo-demos/lint-history
#
# pip3 install git-filter-repo black
# git pull
# git remote prune origin # clean up associated local branches too
# python3 black_history.py
# git remote add origin <url>
# git push -u origin --mirror --no-verify
@JacobHayes
JacobHayes / make.sh
Created March 30, 2017 15:49
`make` wrapper to find `Makefile` in parent directory
# Add to shell's profile/rc
make() {
base_dir="${PWD}"
(
while [ "${PWD}" != '/' ] && [ ! -e 'Makefile' ]; do
cd ..
done
if [ -e 'Makefile' ]; then
command make "${@}"
else;
@JacobHayes
JacobHayes / systemd_failed_units.sh
Created March 29, 2017 19:08
Show failed systemd units on login - tweaked from coreos script (removed locksmithd check)
#/etc/profile.d/systemd_failed_units.sh
#
# Only print for interactive shells.
if [[ $- == *i* ]]; then
FAILED=$(systemctl list-units --state=failed --no-legend)
if [[ ! -z "${FAILED}" ]]; then
COUNT=$(wc -l <<<"${FAILED}")
echo -e "Failed Units: \033[31m${COUNT}\033[39m"
awk '{ print " " $1 }' <<<"${FAILED}"
fi
@JacobHayes
JacobHayes / lazy_init.py
Created March 24, 2017 22:23
Python lazy initialization mixin and decorator
""" Provides a base class that allows lazy initialization
"""
from functools import update_wrapper
class LazyInit(object):
_wrapped_object = None
_wrapped_object_base = None
_wrapped_object_initialized = False
@JacobHayes
JacobHayes / branch_point.sh
Created February 5, 2016 16:52
Shows the commit where this branch forked from master.
diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1