Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
<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 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 = '...'
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)
@samuelcolvin
samuelcolvin / python-people.md
Last active March 13, 2024 03:13
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.

#!/usr/bin/env bash
port=${1:-5001}
while true; do
until $(curl -q -so /dev/null http://localhost:$port/logs -I && true); do
printf .
sleep 0.1
done
curl -q -s http://localhost:$port/logs
for i in `seq 1 10`; do
from pathlib import Path
from watchfiles import watch
from devtools import debug
THIS_DIR = Path(__file__).parent
for changes in watch(THIS_DIR, debug=True):
debug(changes)
@samuelcolvin
samuelcolvin / aicli.py
Last active March 2, 2024 16:04
OpenAI powered AI CLI in just a few lines of code - moved to https://github.com/samuelcolvin/aicli
#!/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
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
import asyncio
import base64
import json
from pathlib import Path
from httpx import AsyncClient
from bs4 import BeautifulSoup
from devtools import debug
START_URL = 'https://github.com/pydantic/pydantic/network/dependents'
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()),