Skip to content

Instantly share code, notes, and snippets.

View phrz's full-sized avatar

Paul Herz phrz

  • Dallas
View GitHub Profile
@phrz
phrz / s3_files.py
Created April 1, 2024 00:40
lets you treat an S3 (Spaces) bucket like a normal folder, sort of?
from boto3 import session
from botocore.client import Config
import os
import os.path
from collections import namedtuple
class Space:
def __init__(self, region_name, endpoint_url, aws_access_key_id, aws_secret_access_key, bucket_name):
self._sess = session.Session()
self._client = self._sess.client(
@phrz
phrz / QBO-clean.css
Created November 20, 2023 18:13
QuickBooks Online Clean Userstyle
@-moz-document domain("app.qbo.intuit.com") {
/* ==UserStyle==
@name 4/17/2023, 6:33:24 PM
@namespace github.com/openstyles/stylus
@version 1.0.0
@description QuickBooks Online - Compact and Legible
@author phrz
==/UserStyle== */
/* hide unused sidebar items */
@phrz
phrz / split_amount.py
Created November 12, 2023 19:30
Divide a dollar amount roughly evenly amongst `n` parties accounting for amounts that cannot be divided evenly.
import decimal
Decimal = decimal.Decimal
def split_amount(dec, n):
splits = [(dec/Decimal(n)).quantize(Decimal('0.01'), decimal.ROUND_DOWN)]*n
while (error_cents := int((dec - sum(splits)) * 100)) != 0:
for i in range(error_cents):
splits[i] += Decimal('0.01')
@phrz
phrz / cache_to_file.py
Created December 28, 2022 01:54
Caching to file with a decorator
def cache_to_file(file_name):
def decorator(f):
try:
cache = json.load(open(file_name, 'r'))
except (IOError, ValueError):
cache = {}
def new_func(*args, **kwargs):
cache.update({ps:f(*args,**kwargs)}) if (ps := param_string(args, kwargs)) not in cache else (json.dump(cache, open(file_name, 'w')))
return cache[ps]
return new_func
@phrz
phrz / xSearch.json
Last active June 1, 2022 17:22
Search settings for xSearch for Mac (custom bang search for Safari)
[
{
"title" : "Model Rules of Professional Conduct",
"shortcuts" : [
"mrpc"
],
"mobile" : "https:\/\/www.americanbar.org\/search\/?q=%s&hl=on&hl.fl=title%2Cdescription&wt=json&start=0&rows=10&fq=(id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fgroups%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fadvocacy%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Ftopics%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fproducts%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fevents-cle%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fnews%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fmembership%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Fcareercenter%2F*%20OR%20id%3A%5C%2Fcontent%2Faba-cms-dotorg%2Fen%2Finitiatives%2F*%20OR%20id%3A%5Chttp%5C%3A%2F%2Fwww.abajournal.com%2F*%20OR%20id%3A%5C%2Fcontent%2Fdam%2Faba%2Fpublications%2F*%20OR%20id%3A%5C%2Fcontent%2Fdam%2Faba%2Fpublishing%2F*)&defType=edismax&mm=75%25&fl=id%3Aid%2Cscore%3Ascore%2Ctitle%3Atitle_s%2Cde
@phrz
phrz / work.py
Last active January 25, 2019 15:57
Tool to sum hours sheet at work
import time
print('SCHEDULE ENTRY', '='*50, sep='\n')
print('[Input schedule lines "HHMM <task>". Ends when <task> is "end"]\n')
sums = {}
last_start = None
t = lambda s: int(s[:2])*60*60 + int(s[2:4])*60 # HHMM to seconds since previous 00:00
while True:
@phrz
phrz / read-binary-types.cpp
Created September 21, 2018 17:33
Helpers for reading binary file formats in C++.
#include <fstream>
#include <iostream>
#include <array>
// creates a new instance of the type
// and reads data into it. Good for single
// value types.
template<typename T>
T STLParser::readBinary(std::ifstream& ifs) {
T out;
@phrz
phrz / stationery2018.tex
Last active September 21, 2018 17:32
phlogo.pdf is the logo used in this document.
% !TEX TS-program = XeLaTeX
% DOCUMENT FORMATTING
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{fancyhdr} % better looking title
\usepackage[all]{nowidow}
% MATH FORMATTING
\usepackage{amsmath}
@phrz
phrz / .bash_profile
Created September 21, 2018 17:29
Bash Config
# You need this: git/contrib/completion/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
source ~/.git-prompt.sh
export PS1='\[\033[38;5;9m\]\h\[$(tput sgr0)\]\[\033[38;5;15m\]:\[$(tput sgr0)\]\[\033[38;5;14m\]\W\[$(tput sgr0)\]\[\033[38;5;15m\]$(__git_ps1 ":git<%s>"):\\$ \[$(tput sgr0)\]'
alias aplay="mplayer -cache 1024 -really-quiet -rawaudio samplesize=1:channels=1:rate=8000 -demuxer rawaudio -"
# You need the version of LLVM that haskell wants installed, `brew install llvm@__`.
@phrz
phrz / preferences.sublime-settings
Last active December 23, 2018 03:06
Sublime Text 3 (ST3) Preferences
{
"bold_folder_labels": true,
"color_scheme": "Packages/Tron Color Scheme/Tron.tmTheme",
"drag_text": false,
"draw_white_space": "all",
"font_face": "FiraCode-Regular",
"font_size": 15,
"ignored_packages":
[
"Vintage"