Skip to content

Instantly share code, notes, and snippets.

@mw3i
mw3i / django-database-standalone.py
Last active April 23, 2024 11:48
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

@mw3i
mw3i / thesis.md
Last active May 28, 2022 17:11
Markdown + Latex Template for a Masters or Dissertation Thesis (following the guidelines of Binghamton University)

documentclass: book bibliography: ./path/to/bibfile.bib csl: .csl fontsize: 12pt classoption: oneside link-citations: true color-links: true

linkcolor: BrickRed

urlcolor: "blue"

# Creates ".bashtrash" directory if it doesn't exist; then it moves things to it
function trash {
if [ ! -d "$HOME/.bashtrash" ]
then
mkdir "$HOME/.bashtrash"
fi
mv "$@" "$HOME/.bashtrash"
}
@mw3i
mw3i / simple_shell.py
Created July 20, 2019 16:28
A simple shell in python
## Python Commander
class simple_shell():
def __init__(self):
while True:
self.listener()
## Listener Function (required)
def listener(self):
self.user_input = input('---\nuser: ').split(' ')
try:
@mw3i
mw3i / cnn_classifier_in_autograd.py
Created June 28, 2019 00:42
Convolutional Net in Autograd
## std lib
import sys, os
## ext req
import autograd.numpy as np
from autograd import grad
import autograd.scipy.signal as signal
## _ _ _ Get Model Output _ _ _