This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
OlderNewer