Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@samuelcolvin
samuelcolvin / hackmonty.py
Last active April 20, 2026 15:29
CLI for hackmonty.com
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.14"
# dependencies = ["httpx", "pydantic", "rich"]
# ///
"""CLI for https://hackmonty.com.
Submits a local Python file to `/run/` and drives the pause/resume loop end to
end. A second local Python file may supply module-level names used to resolve
external function calls and name lookups the sandbox hands back to the client.
# /// script
# dependencies = [
# "pydantic-monty>=0.0.7",
# ]
# ///
import timeit
import pydantic_monty
code = "f'{get_greeting(tone='friendly')} {place}'"
@samuelcolvin
samuelcolvin / python-people.md
Last active February 19, 2026 08:26
An incomplete list of people in the Python community to follow on Twitter and Mastodon.

Python People

(Updated 2022-11-16 with suggestions from comments below, Twitter and Mastodon)

An incomplete list of people in the Python community to follow on Twitter and Mastodon.

With the risk that Twitter dies, I'd be sad to lose links to interesting people in the community, hence this list.

I would love you to comment below with links to people I've missed.

@samuelcolvin
samuelcolvin / motorola_camera_setup.md
Last active February 11, 2026 00:05
Hubble Motorola Focus 66-W Camera "CameraHD" setup

Use the Hubble app to get the camera connected to a wifi network.

Find the Camera's IP address:

> sudo arp-scan --interface=enp3s0 --localnet
Interface: enp3s0, datalink type: EN10MB (Ethernet)
Starting arp-scan 1.8.1 with 256 hosts (http://www.nta-monitor.com/tools/arp-scan/)
192.168.1.100	00:19:99:0f:6a:98	Fujitsu Technology Solutions
192.168.1.102	c4:6e:1f:53:f0:8b	(Unknown)
@samuelcolvin
samuelcolvin / webauthn_client.js
Created November 17, 2021 22:32
demo of webauthn using FastAPI
const log_el = document.getElementById('log')
function log(...messages) {
console.log(...messages)
log_el.innerText += '\n' + messages.map(m => JSON.stringify(m, null, 2)).join(' ')
}
function error(message) {
console.error(message)
log_el.innerText += '\n' + message
@samuelcolvin
samuelcolvin / asyncio_queue.py
Last active December 30, 2025 02:43
Asyncio concurrency
import asyncio
q = asyncio.Queue()
async def produce():
for i in range(10):
await q.put(i)
@samuelcolvin
samuelcolvin / datetime_toolbox.py
Created March 24, 2017 17:13
toolbox of useful methods for working with datetimes in python
"""
Useful utilities when working with datetimes, written for and tested with python 3.6
With other versions of python you're on your own.
(should work find with at least 3.5 though)
"""
from datetime import datetime, date, timedelta, timezone, tzinfo
def set_timezone(dt: datetime, tz: tzinfo) -> datetime:

Python HTTP clients

Results:

➤ uv run with_httpx.py  
time taken to make 10000 requests: 20.2337 seconds
Counter({200: 10000})

➤ uv run with_thread_pool.py 
@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]**."
},
{

The performance I got was:

request taken:  229745.32ms
model_construct taken:  33.59ms
model_validate_json taken:  13.34ms

Output tokens: 2707