Skip to content

Instantly share code, notes, and snippets.

Avatar

Samuel Colvin samuelcolvin

View GitHub Profile
@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}
@samuelcolvin
samuelcolvin / Makefile
Created Aug 29, 2019
if expression in Makefile
View 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
View docker-logs.sh
#!/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