This is a personal reference workflow for minimizing token usage while maintaining project continuity across Claude Code (Sonnet 4 with file access).
Claude loads CLAUDE.md automatically at session start.
| import uuid | |
| from collections.abc import AsyncGenerator, Generator | |
| from typing import cast | |
| import alembic.command | |
| import pytest | |
| from alembic.config import Config as AlembicConfig | |
| from sqlalchemy import URL, Connection, text | |
| from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker, create_async_engine | |
| from testcontainers.postgres import PostgresContainer |
| #!/bin/bash | |
| # MIT License | |
| # | |
| # Copyright (c) 2024 Ofee Oficsu | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy | |
| # of this software and associated documentation files (the "Software"), to deal | |
| # in the Software without restriction, including without limitation the rights | |
| # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.
Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!
Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly).
All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented.
This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog.
You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom
| # Add this code in any Django app's admin.py | |
| # Works for all Task Statuses; you can filter them in line 12. | |
| import ast | |
| import importlib | |
| import json | |
| from django.contrib import admin | |
| from django.contrib import messages | |
| from django.utils.safestring import mark_safe |
| /* | |
| The format for converting UUID's to integers is as follows | |
| CONV(LEFT(HEX(`uuid_from_bin` (`uuid_v5` (<a static uuid value>,<the uuid field>))),8),16,10) AS id | |
| MYSQL User Defined Functions | |
| uuid_from_bin | |
| and uuid_v5 | |
| DROP FUNCTION IF EXISTS uuid_from_bin; | |
| DROP FUNCTION IF EXISTS uuid_to_bin; | |
| DROP FUNCTION IF EXISTS uuid_v5; | |
| DROP FUNCTION IF EXISTS uuid_v4; | |
| DELIMITER // | |
| CREATE FUNCTION uuid_from_bin(b BINARY(16)) | |
| RETURNS CHAR(36) | |
| BEGIN |
| Step 1: Open file ~/.bashrc | |
| Step 2: Uncomment forece_color_prompt=yes | |
| # uncomment for a colored prompt, if the terminal has the capability; turned | |
| # off by default to not distract the user: the focus in a terminal window | |
| # should be on the output of commands, not on the prompt | |
| force_color_prompt=yes | |
| Step 3: Comment PS1 style. Add the following code to end of ~/.bashrc |
| # creating and testing permissions and test groups in django tests. | |
| from django.contrib.auth.models import User, Permission, Group | |
| from django.test import TestCase | |
| from django.test import Client | |
| class ExampleGroupPermissionsTests(TestCase): | |
| def setUp(self): | |
| #create permissions group |