Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Colvin samuelcolvin

View GitHub Profile
View pycon_lt_analyse_data.py
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')])
View test_broken.py
"""
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
@samuelcolvin
samuelcolvin / python-people.md
Last active March 8, 2023 20:55
An incomplete list of people in the Python community to follow on Twitter and Mastodon.
View python-people.md

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 / insert_assert.py
Last active May 10, 2023 17:45
auto-generate assert statements in pytest
View insert_assert.py
"""
License: MIT
Copyright (c) 2022 Samuel Colvin.
See https://twitter.com/adriangb01/status/1573708407479189505
## Usage
Once installed just add
View ansi-to-html.browser.js
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeHTML = exports.decodeHTMLStrict = exports.decodeXML = void 0;
var entities_json_1 = __importDefault(require("./maps/entities.json"));
var legacy_json_1 = __importDefault(require("./maps/legacy.json"));
var xml_json_1 = __importDefault(require("./maps/xml.json"));
@samuelcolvin
samuelcolvin / README.md
Last active September 15, 2022 14:42
Check version script used before release.
View README.md

To use simply run

VERSION_PATH='<your package dir>/version.py' python <(curl -Ls https://gist.githubusercontent.com/samuelcolvin/4e1ad439c5489e8d6478cdee3eb952ef/raw/check_version.py)
View dependents.py
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'
View pydantic_core_pyodide.html
<style>
main {
display: flex;
}
pre {
margin: 0;
padding: 0;
}
code, #output {
white-space: pre-wrap;
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())