Skip to content

Instantly share code, notes, and snippets.

View dcragusa's full-sized avatar

David Ragusa dcragusa

  • L4 Software Engineer at Google
  • San Mateo
View GitHub Profile

A set of scripts for an internal Pokemon game - here for archival only.

@dcragusa
dcragusa / quick_test.sh
Created March 8, 2022 23:09
A zsh script to quickly run a test in any part of a repository by any part of its name. Prompts for input when multiple matches are found.
test() {
# strip test_ and .py from input
stripped=$(echo "$1" | sed "s/^test_//;s/\.py$//")
# declare empty array
test_matches=()
# pipe matches from find command into array
# exclude tests in venv dirs
while IFS= read -r -d $'\0'; do
@dcragusa
dcragusa / update_migrations.py
Created March 8, 2022 22:57
A script to automatically resolve migration conflicts when merging in updates from other devs.
import os
import re
import sys
import shlex
import subprocess
REPO_DIR = os.environ.get("REPO_LOCATION", None)
MIGRATIONS_DIR = os.path.join(REPO_DIR, 'core', 'migrations')
MAX_MIGRATION = os.path.join(MIGRATIONS_DIR, 'max_migration.txt')
@dcragusa
dcragusa / rename_migration.py
Created March 8, 2022 22:54
A script to rename the last migration in the core migrations directory, also updating the max_migration file from django-linear-migrations.
import os
import sys
REPO_DIR = os.environ.get("REPO_LOCATION", None)
MIGRATIONS_DIR = os.path.join(REPO_DIR, 'core', 'migrations')
MAX_MIGRATION = os.path.join(MIGRATIONS_DIR, 'max_migration.txt')
def get_migration_number(migration: str) -> str:
"""Return the number part of a migration name."""
@dcragusa
dcragusa / voicemeeter.ahk
Created August 6, 2019 01:19
Various hotkeys to control Voicemeeter Banana
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
WinWait, ahk_exe voicemeeterpro.exe ; wait for voicemeeter
DllLoad := DllCall("LoadLibrary", "Str", "C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")
@dcragusa
dcragusa / shadow-warrior.ahk
Created June 1, 2019 00:21
A way to trigger skills in Shadow Warrior with single buttonpresses instead of movement key combos. See https://steamcommunity.com/app/233130/discussions/0/1643164649202538416/ for further details.
#NoEnv
#Warn
#SingleInstance Force
#InstallKeybdHook
#UseHook On
SendMode Input
Release() {
Send {w up}
@dcragusa
dcragusa / profiler.py
Created September 20, 2018 14:49
A line by line profiler for Python
# Adapted from https://zapier.com/engineering/profiling-python-boss/
# Requires https://pypi.org/project/line_profiler/
def profile_func(follow=[]):
from line_profiler import LineProfiler
# simply decorate the function you want profiled
# add any functions called you want followed to []
def inner(func):
def profiled_func(*args, **kwargs):
profiler = LineProfiler()
@dcragusa
dcragusa / make_775_dir.py
Created September 20, 2018 14:01
Make a 775 directory on the filesystem (all perms for owner and group, read/execute for everyone else)
def make_775_dir(dir_fp: str):
original_umask = os.umask(0)
try:
os.makedirs(dir_fp, mode=0o775, exist_ok=True)
except IOError:
# weird folder permission issues
pass
finally:
os.umask(original_umask)
@dcragusa
dcragusa / pdf_to_text.py
Created September 19, 2018 15:39
Reads a PDF file into text
import subprocess
from typing import List as L
def pdf_to_text(fp: str, strip: bool = True) -> L[str]:
proc = subprocess.Popen(['pdftotext', '-layout', fp, '-'], stdout=subprocess.PIPE)
raw_output = proc.communicate()[0].decode()
if strip:
res = [i.strip() for i in raw_output.split('\n') if i]
else:
@dcragusa
dcragusa / decimal_utils.py
Created September 19, 2018 12:03
Quick and easy access to the Decimal module, with number of d.p.'s
# Avoid 'D = decimal.Decimal' crud
from decimal import Decimal
from typing import Union as U
def decimalize(num: float, digits_str: str) -> Decimal:
return Decimal(num).quantize(Decimal(digits_str))