Skip to content

Instantly share code, notes, and snippets.

View johnowhitaker's full-sized avatar

Jonathan Whitaker johnowhitaker

View GitHub Profile
@johnowhitaker
johnowhitaker / custom.css
Created September 21, 2024 21:21
My Theme (WIP)
div#notebook {
font-family: sans-serif;
font-size: 13pt;
line-height: 170%;
color: #303030;
-webkit-font-smoothing: antialiased !important;
padding-top: 25px !important;
}
body,
div.body {
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
let context = null;
let canvas = null;
let video = null;
let lastSendTime = 0;
const throttleInterval = 1000; // 1 second in milliseconds
let throttleTimeout = null;
let pendingData = false;
htmx.onLoad(elt => {
// Find and process the canvas element
import requests, json, glob
# Set up
api_key = ...
GPT_MODEL = "gpt-4-1106-preview"
# Read the wordlist and solution from a file
def get_words(idx=0):
files = sorted(glob.glob("connections_data/*.json"))
f = open(files[idx])
@johnowhitaker
johnowhitaker / draw.py
Created June 11, 2024 18:51
Canvas demo direct
from fasthtml.all import *
import anthropic, base64
client = anthropic.Anthropic(
api_key="your_key_here",
)
canvas_js = """
const canvas = document.getElementById('drawingCanvas');
const context = canvas.getContext('2d');
@johnowhitaker
johnowhitaker / draw.py
Last active July 30, 2024 14:45
Canvas demo polling
from fasthtml.all import *
import anthropic, base64, time
client = anthropic.Anthropic(
api_key="your_key_here",
)
canvas_js = """
const canvas = document.getElementById('drawingCanvas');
@johnowhitaker
johnowhitaker / app.py
Created May 30, 2024 21:53
No htmx todo app
from starlette.responses import FileResponse, RedirectResponse
from fastcore.utils import *
from fastcore.xml import *
from fasthtml import *
from sqlite_utils import Database
from fastlite import *
from fastlite.kw import *
db = Database('todos.db')
import requests, json, uuid
from starlette.responses import FileResponse, RedirectResponse
from fastcore.utils import *
from fastcore.xml import *
from fasthtml import *
from oauthlib.oauth2 import WebApplicationClient
# Secrets + URLs
@johnowhitaker
johnowhitaker / sound_trigger.py
Created July 30, 2023 15:44
Quick script co-written with Bing AI that listens to mic input and triggers an action (pressing 'x' key) when a loud noise starts. Configure min_time and threshold to your liking. Fun as a controller for 'russian subway dogs' game!
# Import the required modules
import sounddevice as sd # For accessing the microphone
import pynput # For sending keypresses
import numpy as np # For numerical calculations
import time as tm # For measuring time
# Define a function that checks the loudness of the sound input
def check_loudness(indata, outdata, frames, time, status):
global prev_state, last_trigger
@johnowhitaker
johnowhitaker / make_rss.py
Created December 30, 2022 18:11
app to summarize an RSS feed and write to a new RSS feed
import trafilatura
import feedparser
import requests
from bs4 import BeautifulSoup
from feedgenerator import DefaultFeed, Enclosure
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
headers = {"Authorization": "Bearer HF_TOKEN"}