Skip to content

Instantly share code, notes, and snippets.

View samuelcolvin's full-sized avatar

Samuel Colvin samuelcolvin

View GitHub Profile

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 December 18, 2021 15:52
List of Characters which are (amazingly) valid as the first character of identifiers.
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:
return int(f'0x{s}', 0)
@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
@samuelcolvin
samuelcolvin / send-email.py
Created July 2, 2021 11:03
aioaws SES example
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',
@samuelcolvin
samuelcolvin / print-github-issues.js
Last active April 13, 2021 14:07
strict to run for the console to speedup and smarten up exporting github issues to PDF
const style = document.createElement('style')
style.innerHTML = '@media print {.no-print, .no-print *{display: none !important;}}'
document.querySelector('head').appendChild(style)
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function pending_images() {
const pending_images = Array.from(document.images).filter(img => !img.complete)
@samuelcolvin
samuelcolvin / bashrc-extract.sh
Last active March 12, 2021 18:25
switch to with master or main
gm() {
if git branch | grep -q '^[* ]*master$'; then
git checkout master
else
git checkout main
fi
}
@samuelcolvin
samuelcolvin / heroku_release_github_action.yml
Created November 3, 2020 12:32
push to heroku to deploy when you create a release in github
deploy:
needs:
- test
- lint
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
HEROKU_APP: <heroku app name>
@samuelcolvin
samuelcolvin / set-python-version.py
Last active October 15, 2020 12:47
set version in python package in a github action using GITHUB_REF
#!/usr/bin/env python3
"""
see https://gist.github.com/samuelcolvin/da2f521da5d2195fbfd65da3b8f58589 for details
"""
import os
import re
import sys
from pathlib import Path
@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