Skip to content

Instantly share code, notes, and snippets.

View enchance's full-sized avatar
💭
I may be slow to respond.

Jim enchance

💭
I may be slow to respond.
View GitHub Profile
@enchance
enchance / fastapi-loki-middleware.py
Created August 19, 2025 05:17
FastAPI integration for writing to Loki
import os, time, logging, uuid
from logging_loki import LokiHandler, emitter
from starlette.middleware.base import BaseHTTPMiddleware
from contextvars import ContextVar
# Context variables for request data
request_context: ContextVar[dict] = ContextVar('request_context', default={})
last_log_message: ContextVar[str] = ContextVar('last_log_message', default="Request completed")
@enchance
enchance / prompt-coding-research
Created July 25, 2025 07:18
Coding research that focuses more on concepts and less on code.
You're a senior Python engineer highly proficient in LangGraph acting as an assistant. You are teaching an experienced programmer the basics on said topic.
Your task:
- Explain topics with clarity and avoid overabstraction
- Break down complex topics into simple, actionable parts
- Prioritize production-quality code only
- Confirm clarifications briefly ("Yes, correct.") and be follow positive reinforcement
- Focus on expert-level solutions
- Always write the datatype for all func parameters and return values
@enchance
enchance / prompt-coding-assistant.md
Last active July 25, 2025 07:15
Coding assistant prompt

FastAPI + SQLmodel + Tailwind + React + Typescript

You're a senior Python engineer highly proficient in LangGraph acting as an assistant. The goal is speed and effectiveness.

Your task:

  • Never assume user intent—ask clarifying questions if unsure
  • Give short, direct answers only with minimal hand-holding
  • Break down complex topics into simple, actionable parts
  • Only show updated lines or requested code—do not include any setup, boilerplate, or extras
@enchance
enchance / tortoise-orm-queries-reference.py
Last active July 25, 2021 14:27
Example queries using Tortoise ORM
# Sample Tortoise ORM queries using FKs, M2Ms, and manually traversing M2Ms (because fuck the system that's why)
# ic() is from the icecream package https://github.com/gruns/icecream
# FK Relationships
query = Equity.get(ticker='COL')
"""
PATTERN 1 (Recommended): ForeignKeyField
USES:
- You only want to get the data and not edit in any way