Skip to content

Instantly share code, notes, and snippets.

View jefftriplett's full-sized avatar
Living the dream

Jeff Triplett jefftriplett

Living the dream
View GitHub Profile
from django.db import connection
from django.db.utils import DatabaseError
def reset_sequences():
try:
with connection.cursor() as cursor:
# First get the sequences and their associated columns
cursor.execute("""
SELECT
n.nspname as schema_name,
# /// script
# dependencies = [
# "httpx",
# "typer",
# ]
# ///
import sys
import platform
from datetime import datetime
import httpx
@jefftriplett
jefftriplett / demo-mlx-whisper.py
Created December 2, 2024 22:26
Python + UV demo for using mlx_whisper.
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "mlx-whisper",
# "rich",
# "typer",
# ]
# ///
import json
import typer
@jefftriplett
jefftriplett / copy_templates.py
Created November 11, 2024 20:38
Django management command to flatten and copy templates into your projects templates folder
from difflib import unified_diff
from pathlib import Path
import filecmp
import shutil
import djclick as click
from django.apps import apps
from django.conf import settings
from djclick import pass_verbosity
from rich import print
@jefftriplett
jefftriplett / demo-duckdb.py
Last active August 22, 2024 03:31
An example of how to process a folder of json files that I pulled from YouTube using a bunch of python technology like: uv, duckdb, rich, and typer.
#
# To run this application, use:
# uv run demo-duckdb.py
#
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "duckdb",
# "rich",
# "typer",
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
from __future__ import annotations
import inspect
import djclick as click
from django import forms
from django.core.management.base import CommandError
from django.utils.module_loading import import_string
from rich import print
@jefftriplett
jefftriplett / 1_hello_in_vanilla_python.py
Last active December 8, 2023 19:22
What `hello.py world` looks like in vanilla python, as a django management command, and using the Typer library to show a basic example of using Python Types.
import sys
def main():
# Check if a name argument is provided
if len(sys.argv) > 1:
name = sys.argv[1]
else:
name = "World" # Default name if no argument is provided
print(f"Hello, {name}!")
@jefftriplett
jefftriplett / .pre-commit-config.yaml
Last active November 7, 2023 14:10
👕 How to get ruff to work with checking and formatting?
...
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
...
# https://medium.com/@dave1010/amazingly-alarming-autonomous-ai-agents-62f8a785e4d8
# https://github.com/dave1010/hubcap
# to run we need a few libraries:
# pip install rich typer
import os
import subprocess
import sys
import time