Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Colvin samuelcolvin

View GitHub Profile
View hypothesis_traceback.txt
➤ HYPOTHESIS_MAX_EXAMPLES=1000 pytest tests/test_hypothesis.py::test_recursive_cycles -s
Test session starts (platform: darwin, Python 3.10.5, pytest 7.1.2, pytest-sugar 0.9.4)
benchmark: 3.4.1 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=True warmup_iterations=100000)
rootdir: /Users/samuel/code/pydantic-core, configfile: pyproject.toml
plugins: benchmark-3.4.1, sugar-0.9.4, hypothesis-6.48.1, timeout-2.1.0, mock-3.8.1
timeout: 30.0s
timeout method: signal
timeout func_only: False
collecting ...
View pydantic-hunt-memory-leak.py
import os
from typing import TypeVar, Generic
import psutil
import pytest
from pydantic.generics import GenericModel
process = psutil.Process(os.getpid())
View fields-vs-methods.md

Differentiating between "fields" and library methods/attributes

(Samuel Colvin)

See this discussion.




View watch.py
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)
View hourglass_clocks.py
#!/usr/bin/env python3
import time
clocks = ['🕛', '🕐', '🕑', '🕒', '🕓', '🕔', '🕕', '🕖', '🕗', '🕘', '🕙', '🕚']
# moves the cursor to the beginning of the line
# (3 columns back in this case is always enough)
reset_cursor = '\033[3D'
i = 0
while True:
View codecov_colors_bookmarklet.js
javascript:(function(){
const set_color = (cls, col) => document.querySelectorAll(cls).forEach(el => {el.parentNode.style.backgroundColor = col});
set_color('.bg-ds-coverage-partial', '#ffa');
set_color('.bg-ds-coverage-uncovered', '#fdd');
})();
View README.md

Usage is simply

VERSION_PATH=<package name> python <(curl -Ls https://bit.ly/set__version__)

This will set the __version__ variable in `

@samuelcolvin
samuelcolvin / valid_id_start.py
Created Dec 18, 2021
List of Characters which are (amazingly) valid as the first character of identifiers.
View valid_id_start.py
This file has been truncated, but you can view the full file.
"""
Take the "Derived Property: ID_Start" section from https://www.unicode.org/Public/13.0.0/ucd/DerivedCoreProperties.txt
and save to "DerivedCoreProperties.txt"
"""
from pathlib import Path
def get_value(s: str) -> int:
@samuelcolvin
samuelcolvin / webauthn_client.js
Created Nov 17, 2021
demo of webauthn using FastAPI
View webauthn_client.js
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
View send-email.py
from pathlib import Path
from httpx import AsyncClient
from aioaws.ses import SesConfig, SesClient, SesRecipient, SesAttachment
async def ses_demo(client: AsyncClient):
ses_client = SesClient(client, SesConfig('<access key>', '<secret key>', '<region>'))
message_id = await ses_client.send_email(
SesRecipient('sende@example.com', 'Sender', 'Name'),
'This is the subject',