Skip to content

Instantly share code, notes, and snippets.

View tigerhawkvok's full-sized avatar

Philip Kahn tigerhawkvok

View GitHub Profile
#!python3
# https://stackoverflow.com/a/79108334/1877527
# cSpell: words creatordate, extensionless
from typing import Optional, List, Collection
import subprocess
import datetime as dt
import re
COMMIT_TAG_REGEX = r"((?:[a-f0-9]{7,40}|v(?:\d+\.)+\d+)(?:(?:[\-_\.][a-z0-9\.]+)|(?:a(?:lpha)?|b(?:eta)?|r(?:elease)?c(?:andidate)?)\d+)?)" # cSpell: disable-line
@tigerhawkvok
tigerhawkvok / unLFS.py
Last active October 31, 2024 02:51
Remove LFS from a directory
#!python3
"""
Remove LFS tracked files and change them to normal git
Python 3.8+, native code
For Python <= 3.7, move the Literal and Final imports from "typing" to third-party module "typing_extensions"
@author Philip Kahn
@url https://gist.github.com/tigerhawkvok/adb7905a2423312f237da1953d6a8eeb
@tigerhawkvok
tigerhawkvok / getChocoInstalledPath.py
Last active December 11, 2023 00:53
Get the installation path for a package installed by Chocolatey
#!python3
"""
Script and function to get the path of a chocolatey install
matching the `pathComponent`, or, if none provided, the
last installed path.
@author Philip Kahn
@date 20230614
@license MIT
@url https://gist.github.com/tigerhawkvok/aad3f184b37bb869df5bd337d4b4c22e
@tigerhawkvok
tigerhawkvok / prettifySql.py
Created March 1, 2022 00:02
Take in a dirty SQL file formatted who knows how and get it mostly formatted
#!python3
"""
Quick and dirty SQL beautifier
"""
FILEPATH = "buildWDTables.sql"
TABSIZE = 4
#######################################################
@tigerhawkvok
tigerhawkvok / WSLmounter.sh
Created August 5, 2021 18:34
Mount a removable drive in WSL
# Works in .bashrc too
# Mount the D: drive
test -r /mnt/d || eval "$(sudo mkdir /mnt/d)"
test -r /mnt/d/'System Volume Information' || eval "$(sudo mount -t drvfs D: /mnt/d)"
test -r /mnt/d/'System Volume Information' && echo 'D: successfully mounted' || echo 'Failed to mount removable drive'
@tigerhawkvok
tigerhawkvok / optimizeImages.py
Created July 27, 2021 23:24
Optimize images in a directory to reasonable quality without killing space
#!python3
"""
Opens all .jpg files in a folder and
downsamples them to maximum 1280 pixels wide
and quality level 75
"""
import glob
import os
from skimage.io import imread, imsave
@tigerhawkvok
tigerhawkvok / pyproject.toml
Last active July 5, 2021 04:56
Webify a directory of images
[tool.poetry]
name = "webImages"
version = "0.1.0"
description = "Scales all images in a directory and preps for web use"
authors = ["Philip Kahn <[email protected]>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.7"
scikit-image = "~0.19.0"
@tigerhawkvok
tigerhawkvok / names_regex.md
Last active May 28, 2021 06:30
Names Regex

Should work with most englishy names of folks - NOT suitable for international use - but just fine for "make sure people locally give me a full name"

The Pattern

^[a-zA-Z'\u00c0-\u01ff]+[ \t]+([a-zA-Z\u00c0-\u01ff]+\.?[ \t]+)?([a-zA-Z\u00c0-\u01ff]+([\-']|[a-zA-Z\u00c0-\u01ff](\. ?)?)?)+(?<!\.|-|')[ \t]*$"

Test Success

@tigerhawkvok
tigerhawkvok / .gitconfig
Last active May 27, 2021 00:08 — forked from joechrysler/who_is_my_mummy.sh
Find the nearest parent branch of the current git branch
[alias]
parentalt = "!git show-branch | grep '*' | grep -v \"$(git rev-parse --abbrev-ref HEAD)\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//' #"
parent = "!vbc=$(git rev-parse --abbrev-ref HEAD) && vbc_col=$(( $(git show-branch | grep '^[^\\[]*\\*' | head -1 | cut -d* -f1 | wc -c) - 1 )) && swimming_lane_start_row=$(( $(git show-branch | grep -n \"^[\\-]*$\" | cut -d: -f1) + 1 )) && git show-branch | tail -n +$swimming_lane_start_row | grep -v \"^[^\\[]*\\[$vbc\" | grep \"^.\\{$vbc_col\\}[^ ]\" | head -n1 | sed 's/.*\\[\\(.*\\)\\].*/\\1/' | sed 's/[\\^~].*//'"
@tigerhawkvok
tigerhawkvok / cleanupGitHere.py
Last active July 1, 2021 19:25
Clean up a directory of Git projects
#!python3
"""
Cleanup all top level git directories here.
Creates a powershell or bash script to then execute
https://gist.github.com/tigerhawkvok/2161ef3aead495420fc84588ec50b6a3
Python 3.7+
"""
#pylint: disable= line-too-long, invalid-name