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)
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
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 / emojis.py
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('https://api.github.com/emojis')
import polars as pl
pl.Config.set_tbl_rows(30)
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+)', ''))
.groupby(pl.col('path'))
.agg([pl.count().alias('count')])
"""
pydantic-core: 01fdec6d2242fdf7205663d566be5ba990d1d459 - the custom-dataclass-validator branch
and pydantic: 519800fa5167a57681ba3b202503751aa0f17347 - the dataclasses-v2 branch
"""
from typing import TypeVar
import pytest
from pydantic import BaseModel, ValidationError