Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@samuelcolvin
samuelcolvin / check_github_actions_tag.py
Last active March 28, 2020 13:56
check a package version matches the version from GITHUB_REF, used when deploying with github actions
#!/usr/bin/env python3
"""
see https://gist.github.com/samuelcolvin/3b662d40e28213fbcd046743cb7068d8 for details
"""
import os
import re
import sys
from importlib import import_module
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@samuelcolvin
samuelcolvin / json_validator.py
Created December 20, 2019 12:24
partial implementation of a pydantic validator to enforce JSON types
from datetime import datetime
from typing import Dict
from uuid import UUID
from pydantic import BaseModel, validator
from devtools import debug
NoneType = type(None)
json_types = {int, float, bool, NoneType}
@samuelcolvin
samuelcolvin / Makefile
Created August 29, 2019 11:22
if expression in Makefile
.PHONY: lint
lint:
python setup.py check -rms
flake8 watchgod/ tests/
$(isort) --check-only
ifeq ($(shell python -c "import sys; print('{0.major}.{0.minor}'.format(sys.version_info))"),3.5)
@echo "black is not compatible with python3.5, not running"
else
$(black) --check
endif
#!/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
@samuelcolvin
samuelcolvin / rabbit_hole.py
Last active August 18, 2019 14:18
middleware style partials vs calling functions in a loop vs. calling each method vs. a single function, cythonized before running
from functools import partial
from typing import Any, Callable
StrCallable = Callable[[str], str]
def rabbit_hole_repeat(v: str) -> str:
return v * 2
@samuelcolvin
samuelcolvin / pull_pull_request.py
Last active August 4, 2022 09:12
Pull from and pushing to other people's pull requests
#!/usr/bin/env python3
"""
pull from and pushing to other people's pull requests
(might require an auth key for private repos)
"""
import os
import re
import sys
import requests
@samuelcolvin
samuelcolvin / profiling_pydantic.py
Created July 25, 2019 16:49
call with `kernprof -lv profiling_pydantic.py`, doesn't seem to work with cythonized source
import json
from datetime import datetime
from pathlib import Path
from typing import List
from pydantic import BaseModel, PositiveInt, compiled, constr, version, validate_model
from pydantic.validators import _VALIDATORS, IfConfig
print(f'pydantic {version.VERSION}, compiled: {compiled}')
@samuelcolvin
samuelcolvin / cases.json
Created July 23, 2019 10:21
cases.json for pydantic benchmarking
This file has been truncated, but you can view the full file.
[
{
"client_name": "GpQyYhDKoE\u00cejT\u00cfE'gnpPWGixFXkDbNJrUfH\u00e4JXRkZFmx+fEQfp\"zxMY\"Zkk-DXHj\u00a6avj\u00c2HMNrYs\u00ca lWMfTJjUOG)VUMHHnNVEREl&Hop\u00b9wq\u00e8PsDh\u00d0f-rcnO\u00c7hmAOfWb(tjWUHiTbnlLYjp,v\u00d4",
"client_phone": null,
"contractor": "227",
"grecaptcha_response": "YK\u00cbW$RkgocsI#jqgI'KtiJWH\u00feYYT\n\txlsKgoGbzYk/cSAgPCOLIG*FmWAF\u00ab+ZJy/RJrzGdKkuUbZmPM\u00f4\u00e0FenRSYh\u00f7HZYV\u00cffAYSb\u00f5\u00beC\u00a0XpA\u00c3ibsfOEiTyzB#BY\nXLfbeE'TMcOFgPTApNPdcGq+QVn\u00f4WiSlBICODTjOZYONIy$\u00e1NJimPl\u00c1Z\u00f7Xd'DLRlS\u00e3TGXG\u00cchbDeHrEuqxWdKBZ\u00b6Xu/GkpKIdRN'CUPGIW$\u00f1hnKGbKLdO\u00f6cWYUPOJWzitbWoH#ZqiNEcXR\u00cfqghnw\u00c6VoJiqHryohEJIoWQnOtNT(EFSUg\tteuJ.TciRh%ehZ+bq\u00f2fx\"qkCUwDVpRhx KWG\u00e3Nnbs\u00f3lK(eSm\u00c6\u00f3oGXCG#yP\u00d0\u00bbpwpVFUY\tDt\u00a6xy(t*\u00e1KnkZ)VFtnllGioTwoJ\nalmPCeVSVGfNg jJVOdIwDxJ.mym'K\u00c8fquJlTlFfsKbu)OveSxthu)BsP,gFHmpQf/pDPxOdVtXttRgGAHCiSaYyuFVd\u00c9ONXhkv\u00ceNqNO*'-hFdAXMFDwNykBzeEbyPuV$UInUpcGWSPeXaj