Skip to content

Instantly share code, notes, and snippets.

@mw3i
mw3i / README-CHAT
Last active March 21, 2025 16:48
200-line bash script to talk to an LLM prompted with your repo structure + any READMEs it finds (leveraging python and openai)
#!/bin/bash
# # # # # # # # # # # # # # # # # # # # # # # # # #
# SETTINGS
# # # # # # # # # # # # # #
TARGET_DIR="${1:-./}" # Default target directory
API_KEY="${2:-$OPENAI_API_KEY}" # Default API key path
MODEL="${3:-gpt-4}" # Default model
MAX_DEPTH="${4:-3}" # Default max depth for tree search
FILE_SIZE_LIMIT_MB="${5:-8}" # Default file size limit (MB) for the README
@mw3i
mw3i / automatic-templating-with-alpine.html
Last active March 21, 2025 16:47
absurdly minimal and straightforward approach to automatic templating with alpine.js
<!DOCTYPE html>
<!--
here's an absurdly easy way of automatic client-side templating with alpine js -- where the only thing that needs to be defined is (1) the api endpoint you pull the data from, and (2) the id of the template you want the data routed to.
we'll use client-side nunjucks in this example, but any client-side templating engine would work probably
this feels incredibly straightforward and useful, and there may be huge downsides but I can't think of them yet
also, alpine.js already makes it really easy to do templating, with x-text and other attributes. but with this approach you get the smooth syntax of a templating engine like nunjucks
@mw3i
mw3i / remote python.sublime-build
Last active March 21, 2025 16:49
Run a sublime text python build on a remote server using ssh.
// This build system connects to the server; cd's into the parent dir of the file, executes the script, and returns the result locally.
//
// It assumes you have the remote file loaded (e.g., via SSHFS) locally at `/path/to/sshfs/dir/` which has remote path `/remote/path/` (<-- replace those with your use case).
//
// Also note that you probably won't be able to type the ssh password, so you'll need to set up key-based authentication with ssh (e.g., `ssh-keygen -t rsa -b 4096 && ssh-copy-id [email protected]`).
// It doesn't flag the line in the sublime text pane unfortunately; I'm not sure how to do that
{
"cmd": ["ssh", "[email protected]", "cd", "'${file_path/path\\/to\\/sshfs\\/dir/remote\\/path/}'", "&&", "/remote/path/to/python/bin/python3", "'${file/path\\/to\\/sshfs\\/dir/remote\\/path/}'"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
@mw3i
mw3i / import_gist.py
Last active March 21, 2025 16:50
import a github gist in python
'''
Import a github gist as a python package
'''
import urllib.request
url = 'https://gist.githubusercontent.com/mw3i/998d21136363a10f600e925f236ca852/raw/9b3528fb54b62ac55ee265c5b3cc6eca42344da0/sqlachemy_convenience_wrapper.py'
with open('package.py', 'w') as file: file.write(urllib.request.urlopen(url).read().decode())
import package
@mw3i
mw3i / django-database-standalone.py
Last active April 13, 2025 19:38
Truly Standalone Django-ORM Wrapper
'''
Proof of Concept:
Django devs built an ORM that seems way more straightforward than many existing tools. This class lets you leverage the django-orm without any project settings or other aspects of a django setup.
There are probably weak points and functionality missing, but it seems like a relatively intuitive proof of concept
'''
import os
import django
from django.conf import settings
@mw3i
mw3i / df_upsert.py
Created September 7, 2023 15:04
Prototype: Dataframe Upsert
'''
Built with chatgpt; still in the process of testing
'''
import time
import pandas as pd
from sqlalchemy import create_engine, Table, MetaData, select, insert, update, bindparam
def upsert_dataframe_to_sql(dataframe, table_name, id_column="id", verbose=True):
"""
Upsert a Pandas DataFrame into a SQL table using SQLAlchemy.
@mw3i
mw3i / chatgpt api call with exponential backoff.py
Last active June 14, 2023 15:18
Make a single api call with chatgpt, with exponential backoff to mitigate rate limiting
'''
Build with the help of chatgpt
'''
import openai
openai.api_key = 'your_api_key_here'
def response(message):
retry_count = 0
max_retries = 4
wait_time = 7 # Initial wait time in seconds
@mw3i
mw3i / distilldb.py
Last active May 29, 2023 16:00
Distilled version of SQLAlchemy wrapped up in one class
'''
Name: Distilled (since it's sqlalchemy with the parts a normal person cares about distilled from the rest in one Database class)
Very basic wrapper around the sqlalchemy orm that tries to replicate the ease of use that you get with r's dbplyr. Namely:
- provide the database connection details (in this case ones that are stored in a config file)
- return a single object from which you can do everything you need to
Similar in spirit to the more developed library: [dataset](https://dataset.readthedocs.io/en/latest/install.html)
Rewrote an old version of this with help from chatgpt
@mw3i
mw3i / rundown.py
Last active March 9, 2023 13:49
Hastly thrown together way of executing all python codeblocks in a markdown file
#!/usr/local/bin/python3
'''
This site is very useful for regex testing: https://pythex.org/
'''
import re, argparse
args = argparse.ArgumentParser(description = 'Execute all the blocks in a markdown script')
args.add_argument('file_path', help = 'File you want to execute')
args = args.parse_args()
with open(args.file_path, 'r') as file:
@mw3i
mw3i / coverletter.md
Last active July 20, 2022 19:07
Pandoc Markdown -> Latex Template for a Cover Letter


\flushright

My Name

My Street Address My City, MY STATE my zip code (My) Phone-Number