Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@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',
@samuelcolvin
samuelcolvin / print-github-issues.js
Last active Apr 13, 2021
strict to run for the console to speedup and smarten up exporting github issues to PDF
View print-github-issues.js
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 Mar 12, 2021
switch to with master or main
View bashrc-extract.sh
gm() {
if git branch | grep -q '^[* ]*master$'; then
git checkout master
else
git checkout main
fi
}
@samuelcolvin
samuelcolvin / heroku_release_github_action.yml
Created Nov 3, 2020
push to heroku to deploy when you create a release in github
View heroku_release_github_action.yml
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 Oct 15, 2020
set version in python package in a github action using GITHUB_REF
View set-python-version.py
#!/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 Mar 28, 2020
check a package version matches the version from GITHUB_REF, used when deploying with github actions
View check_github_actions_tag.py
#!/usr/bin/env python3
"""
see https://gist.github.com/samuelcolvin/3b662d40e28213fbcd046743cb7068d8 for details
"""
import os
import re
import sys
from importlib import import_module
View Covid19.ipynb
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 Dec 20, 2019
partial implementation of a pydantic validator to enforce JSON types
View json_validator.py
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}