Skip to content

Instantly share code, notes, and snippets.

Avatar

Philip Kahn tigerhawkvok

View GitHub Profile
@tigerhawkvok
tigerhawkvok / prettifySql.py
Created Mar 1, 2022
Take in a dirty SQL file formatted who knows how and get it mostly formatted
View prettifySql.py
#!python3
"""
Quick and dirty SQL beautifier
"""
FILEPATH = "buildWDTables.sql"
TABSIZE = 4
#######################################################
@tigerhawkvok
tigerhawkvok / WSLmounter.sh
Created Aug 5, 2021
Mount a removable drive in WSL
View WSLmounter.sh
# 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 Jul 27, 2021
Optimize images in a directory to reasonable quality without killing space
View optimizeImages.py
#!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 Jul 5, 2021
Webify a directory of images
View pyproject.toml
[tool.poetry]
name = "webImages"
version = "0.1.0"
description = "Scales all images in a directory and preps for web use"
authors = ["Philip Kahn <tigerhawkvok@gmail.com>"]
license = "MIT"
[tool.poetry.dependencies]
python = "^3.7"
scikit-image = "~0.19.0"
View names_regex.md

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 — forked from joechrysler/who_is_my_mummy.sh
Find the nearest parent branch of the current git branch
View .gitconfig
[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 Jul 1, 2021
Clean up a directory of Git projects
View cleanupGitHere.py
#!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
@tigerhawkvok
tigerhawkvok / ImageDeTiler.py
Last active Apr 26, 2022 — forked from will-hart/README.md
Stitch together tilemaps into a single image
View ImageDeTiler.py
#!python3
"""
A simple script which converts all the images in
the folder it is run from into a single image.
Images should be in a directory <searchDir>, with
the tiles binned into folders based on their
Y-axis identity, named as their X-axis identity.
In other words, they should be folders of rows
containing column-items for that row of images.
@tigerhawkvok
tigerhawkvok / smoothSignal.py
Last active Mar 17, 2020
Smooth an input signal
View smoothSignal.py
#!python3
import numpy as np
from typing import Union
def smooth(inputSignal:Union[list, np.ndarray], windowLength:int= 11, window:str= 'flat') -> np.ndarray:
"""
Smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
@tigerhawkvok
tigerhawkvok / poetry-convert.py
Last active Aug 13, 2019
Convert a requirements.txt file to a Poetry project
View poetry-convert.py
#!python3
"""
Convert a requirements.txt file to a Poetry project.
Just place in the root of your working directory and run!
"""
sourceFile = "./requirements.txt"
import re
import os