Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@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()),
import json
import random
import uuid
from datetime import date
import timeit
from typing import TypeVar, Generic
import pydantic_core
from pydantic import BaseModel
// this is lightly better than simple debounce as:
// 1. it kicks of a new search immediately
// 2. it waits for a server re
function debounceLoadOptions(searchUrl: string) {
let running = false
let runNext: [string, OptionsCallback] | null = null
const run = (inputValue: string, callback: OptionsCallback, force: boolean) => {
if (running && !force) {
runNext = [inputValue, callback]

Senior Frontend Developer at Pydantic

Opportunity to join Pydantic! We are looking to hire someone to lead our frontend development.

We want to hire a senior engineer who is as experienced with TypeScript, React and UI/UX as we are with Python, Rust and API design.

No recruiters or agencies please, any contact from recruiters will be marked as spam.

About Pydantic