Skip to content

Instantly share code, notes, and snippets.

View bradhilton's full-sized avatar

Brad Hilton bradhilton

View GitHub Profile
@bradhilton
bradhilton / gpt.py
Last active November 30, 2023 22:58
GPT magic functions
import codecs
from IPython import get_ipython # type: ignore
from IPython.core.magic import register_line_cell_magic
from IPython.display import clear_output, display, Markdown, update_display # type: ignore
from openai import OpenAI
from openai.types.chat import ChatCompletionMessageParam
from openai.types.chat.completion_create_params import Function
import os
import re
import requests
// Retrieves and recasts the body of an enum
func body<T, U>(of value: inout T) -> U {
return withUnsafePointer(to: &value) {
$0.withMemoryRebound(to: U.self, capacity: 1) {
$0.pointee
}
}
}
struct Todo {
let title: String
let completed: Bool
}
let storage = PostgreSqlTable<Todo>()
let app = CRUDApp<Todo>(storage: storage)()
let router = RESTAppRouter(app: app)
let server = HTTPSServer(router: router)
server.start()
import Foundation
protocol Mixin {
var storage: [String : Any] { get set }
}
protocol CanMoveMixin : Mixin {
var position: CGPoint { get set }
var speed: CGVector { get set }
GET /card_catalog/categories?depth=full // Gets full category heirarchy. Takes a few seconds. Would be nice if it were cached.
GET /card_catalog/cards?category={category_id} // Only returns 20 cards. Would like all cards for standard catalog categories.
Either cache all cards for a given category or cache all catalog cards with category ids included.
If the category type is CAT then we should cache it.