Skip to content

Instantly share code, notes, and snippets.

View abingham's full-sized avatar

Austin Bingham abingham

View GitHub Profile
@abingham
abingham / .coveragerc
Last active October 31, 2022 08:48
Gunicorn server hooks for coverage analysis of a Flask app
[run]
parallel=True
omit =
test_*.py
@abingham
abingham / aiohttp_png_example.py
Created March 29, 2021 06:21
Example of serving a PNG from aiohttp
from pathlib import Path
from aiohttp import web
from aiohttp.web_response import Response
async def index(request):
# This just demonstrates how the HTML can reference another endpoint in this server.
return Response(
text='<html><body><img src="/image"></body></html>',
@abingham
abingham / find_dominating.py
Created March 22, 2021 08:38
Find dominating file name
def find_dominating(filename: str, start_path: Path):
"""Look for `filename` in `start_path` or any of its ancestor directories.
Args:
filename: The filename to look for
start_path: The directory in which to start the search
Returns: The dominating path
Raises:
@abingham
abingham / backup.sh
Created March 6, 2018 20:56
Duplicity backup script
#!/bin/bash
# This does a simple local-to-local duplicity backup with no encryption. It keeps backups for a year.
export LOGFILE=<path to log file>
export SOURCE=<path to source directory>
export DEST=<path to destination directory>
# Without this, duplicity gets upset.
ulimit -n 1024
@abingham
abingham / rope_rename.py
Created October 11, 2017 06:32
Basic programmatic use of rope
from rope.base import libutils
import rope.base.project
from rope.refactor.rename import Rename
project = rope.base.project.Project('.')
resource = libutils.path_to_resource(project, './sample.py')
renamer = Rename(project, resource, 81) # offset=81
changes = renamer.get_changes('Fnord')
project.do(changes)
@abingham
abingham / trim_svg_whitespace.sh
Created February 23, 2017 13:47
Script to trim whitespace from around an SVG using inkscape
inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileQuit $1
# inkscape --export-height=75 --export-png=$1.png $1
@abingham
abingham / all_pdfs_to_png.sh
Last active March 4, 2016 09:25
Recipes for working with Leanpub
for i in *.pdf; do basename="${i%.*}"; sips -s format png -s dpiWidth 300 -s dpiHeight 300 --resampleWidth 1500 ${basename}.pdf --out ${basename}.png; done
@abingham
abingham / capture_help.py
Last active May 22, 2023 20:55
How to capture the output of Python's help() function.
import io
import sys
# Temporarily redirect stdout to a StringIO.
stdout = sys.stdout
s = io.StringIO()
sys.stdout = s
help(sys.intern)
@abingham
abingham / python-test-flow.el
Last active April 28, 2017 17:25
Emacs routine for running python tests and displaying the results in a buffer.
(defun run-python-tests (root-dir test-subdir buffer-name)
(interactive)
(let ((default-directory root-dir)
(buff (get-buffer-create buffer-name)))
(display-buffer buff)
(shell-command (concat "python -m unittest discover " test-subdir) buff)
(with-current-buffer buff
(compilation-mode))))
; This hook runs the tests after each save, a TDD-esque workflow.