Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@samuelcolvin
samuelcolvin / active.html
Last active January 1, 2025 16:43
checking if a page is active.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Am I active</title>
</head>
<body>
<input name="testing"/>
<div class="context" style="margin-bottom: 100px">
PointPydanticBaseModel v2.10.4: 538ns
PointPydanticTypedDict v2.10.4: 247ns
attrs v24.3.0: 551ns
import json
from dataclasses import dataclass
from typing import Annotated, Any, Callable, Union
import pydantic_core
import pytest
from inline_snapshot import snapshot
from pydantic import BaseModel, Field
from pydantic_core import PydanticSerializationError
@samuelcolvin
samuelcolvin / logfire_docs.json
Created October 24, 2024 12:33
Logfire docs JSON
[
{
"id": 0,
"parent": null,
"path": "roadmap.md",
"level": 1,
"title": "Roadmap",
"content": "Here is the roadmap for **Pydantic Logfire**. This is a living document, and it will be updated as we progress.\n\nIf you have any questions, or a feature request, **please join our [Slack][slack]**."
},
{
@samuelcolvin
samuelcolvin / logfire_example.py
Last active October 19, 2024 18:30
Logfire vs raw OTel
"""
To run install:
logfire[fastapi]
fastapi
uvicorn
"""
import time
import logfire
import uvicorn
from fastapi import FastAPI
@samuelcolvin
samuelcolvin / tinify.py
Created September 27, 2024 11:38
tinify a single image or all images in a directory
#!/usr/bin/env python3
import os
import subprocess
import sys
from pathlib import Path
import tinify
# TODO find a way to check if files have already been tinified before processing
tinify.key = os.getenv('TINIFY_KEY')
if not tinify.key:
@samuelcolvin
samuelcolvin / cargo_list.py
Last active July 6, 2024 08:48
Generate a CSV file of dependencies from Cargo.toml and Cargo.lock
from __future__ import annotations
import asyncio
import csv
import sys
from dataclasses import dataclass, asdict, fields
from pathlib import Path
from typing import Literal
import toml
from httpx import AsyncClient
<h1>Web worker demo</h1>
<h3>Write Code:</h3>
<textarea id="code" rows="10" cols="80">return "hello world";</textarea>
<button id="run">Run</button>
<h3>Output:</h3>
<pre id="output"></pre>
@samuelcolvin
samuelcolvin / cloudflare_page_delete_deployments.py
Last active October 31, 2024 03:32
Delete old CloudFlare Pages deployments to allow project deletion
import time
from datetime import datetime, timedelta, timezone
from httpx import Client, Response, HTTPError
ACCOUNT_ID = '...'
PROJECT_NAME = '...'
ENDPOINT = f'https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/pages/projects/{PROJECT_NAME}/deployments'
CF_API_TOKEN = '...'
EXPIRATION_BEFORE = datetime.now(timezone.utc) - timedelta(days=7)
import timeit
from pathlib import Path
import orjson
import pydantic_core
import ujson
import json
cases = [
('medium_response', Path('../jiter/benches/medium_response.json').read_bytes()),