Skip to content

Instantly share code, notes, and snippets.

View birkin's full-sized avatar

Birkin James Diana birkin

View GitHub Profile
@birkin
birkin / replace_spaces_with_underscores.py
Last active August 14, 2025 02:48
uv run gist experimentation
# /// script
# requires-python = "==3.12.*"
# ///
"""
Just replaces spaces with underscores; that's all!
Part of experimentation for using `uv run THE-GIST-URL`
Usage:
@birkin
birkin / new_uv_pyprojecttoml_code_update_script.sh
Last active July 25, 2025 16:50
new-style uv/pyproject.toml code-update-script
## (server-name) DEV-SERVER code update script for '(project-name)' project -- using new uv-pyproject.toml architecture
## setup ------------------------------------------------------------
echo " "; echo "--------------------"; echo " "; echo "DEPLOY-START"; echo " "
echo ":: setting envars..."
GROUP="(the-group)"
LOG_DIR_PATH="/path/to/stuff/logs/"
PROJECT_DIR_PATH="/path/to/stuff/project/" # for `git pull`
STATIC_MEDIA_DIR_PATH="/path/to/html/django_media/(project)_media/"
@birkin
birkin / uv_workshop.md
Last active July 8, 2025 16:41
`uv` unconference workshop description

Introducing uv

Python is a friendly language, used by a wide-variety of folk in the Library -- from back-end developers to folk exploring digital-humanities text-mining and web-scraping to others exploring AI to others doing data-cleanup.

But too often there's friction in the process of getting code running because of the need to install:

  • various versions of python
  • a virtual-environment (venv)
  • various packages.

This workshop -- no programming experience required -- will introduce the python package-manager "uv", which has become incredibly popular because it removes lots of that friction, allowing people to focus more on their work/exploration/research, rather than "setup". It also helps collaboration, by making it easier for others using uv to use your scripts.

@birkin
birkin / load_gsheet_data.py
Created July 4, 2025 16:15
access public google spreadsheet
# /// script
# requires-python = "==3.12.*"
# dependencies = [
# "polars",
# "httpx"
# ]
# ///
"""
Example of accessing a public google-sheet ("Anyone with the link can view")
@birkin
birkin / secure_id_maker.py
Created May 11, 2025 02:25
unique strings
# /// script
# requires-python = "==3.12.*"
# ///
"""
Generates a secure unique ID
Usage:
uv run ./unique_id.py # default length is 10
uv run ./unique_id.py --length 20
@birkin
birkin / lxml_install_test.py
Created May 7, 2025 16:41
lxml old-server install test
# /// script
# requires-python = "==3.8.*"
# dependencies = ["lxml==4.9.1"]
# ///
"""
Script to test lxml installation on redhat-7 server.
Uses python PEP-723 inline-script-metadata to allow uv to run without venv installs.
@birkin
birkin / exempt_path_suggestion.md
Created April 22, 2025 14:50
thought about handling exempt-paths for django turnstile middleware.

exempt-paths refactor suggestion

idea

Based on thinking and research, below is a suggestion for handling exempt-paths in turnstile_middleware.py.

Some nice things about this...

  • the regex-compilation happens just once, when the webapp first loads, improving speed.
  • it allows us to change a .env setting easily, without deploying new code.
  • it allows the pattern-match code in turnstile_middleware.py to be simple, becase regex is handling the "starts-with" or "anywhere-within" check.
@birkin
birkin / pydantic_example.py
Last active March 14, 2025 18:07
pydantic example
# /// script
# requires-python = "==3.12.*"
# dependencies = ["pydantic==2.10.*"]
# ///
"""
Pydantic example
- Pydantic is a data validation package for Python. Using rust, it's fast.
- <https://docs.pydantic.dev/latest/>
@birkin
birkin / script_hack_django_sqlite.sh
Last active December 12, 2024 22:55
hack to get newish version of django to work with old version of sqlite.
#!/bin/bash
## Purpose:
## This script hacks Django's sqlite package to enable it to work with an old version
## of sqlite3 on an old version of RedHat.
##
## Flow:
## It checks if django and pysqlite3 and pysqlite3-binary are installed in the virtual environment.
## If the required packages are not found, the script alerts the user and exits.
## If the packages are found, it proceeds to update Django's `sqlite3/base.py` file.
@birkin
birkin / render_xml_via_template.py
Created November 15, 2024 19:23
example of rendering xml via django template
"""
Generates XML output using Django's template system.
Accepts command-line arguments to specify a person's name and role.
Usage:
$ uv run "./render_xml_via_template.py" --person "Birkin" --role "cheerleader"
Output:
<?xml version="1.0" encoding="UTF-8"?>
<root>