Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
samuelcolvin /
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>
<pre id="output"></pre>
samuelcolvin /
Last active April 24, 2024 11:58
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 = '...'
ENDPOINT = f'{ACCOUNT_ID}/pages/projects/{PROJECT_NAME}/deployments'
CF_API_TOKEN = '...'
EXPIRATION_BEFORE = - 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

samuelcolvin /
Last active March 2, 2024 16:04
OpenAI powered AI CLI in just a few lines of code - moved to
#!/usr/bin/env python3
import os
from datetime import datetime, timezone
from pathlib import Path
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
import openai
from rich.console import Console
from rich.markdown import Markdown
samuelcolvin /
Created July 13, 2023 16:57
Pydantic parsing JSON and validating URLs vs. pure pyton
import timeit
import json
from urllib.parse import urlparse
import requests
from pydantic import TypeAdapter, HttpUrl
reps = 7
number = 100
r = requests.get('')
import polars as pl
ds = pl.read_parquet('page_views.parquet').sort('ts')
path_counts = (
ds.with_columns(pl.col('path').str.replace(r'^/(latest|dev-v\d|\d\.\d+)', ''))