Skip to content

Instantly share code, notes, and snippets.

View bloodearnest's full-sized avatar

Simon Davy bloodearnest

  • Bennett Institute for Appllied Data Science, Oxford University
  • Leeds, UK
  • X @bloodearnest
View GitHub Profile
#!/bin/bash
set -eu
_UID=$(id -u)
GID=$(id -g)
# give lxd permission to map your user/group id through
grep root:$_UID:1 /etc/subuid -qs || sudo usermod --add-subuids ${_UID}-${_UID} --add-subgids ${GID}-${GID} root
# set up a separate key to make sure we can log in automatically via ssh
# with $HOME mounted
@bloodearnest
bloodearnest / selfsigned.py
Last active April 23, 2024 15:23
Create a self-signed x509 certificate with python cryptography library
# Copyright 2018 Simon Davy
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
#!/bin/bash
#
# This script will create xenial and trusty lxd images that will be used by the
# lxd provider in juju 2.1+ It is for use with the lxd provider for local
# development and preinstalls a common set of production packages.
#
# This is important, as between them, basenode and layer-basic install ~111
# packages, before we even get to any packages installed by your charm.
#
# It also installs some helpful development tools, and pre-downloads some
@bloodearnest
bloodearnest / stream.py
Created March 22, 2022 09:52
streaming feather files
import time
import sys
import itertools
import os
import numpy as np
import pandas as pd
import pyarrow as pa
import psutil
@bloodearnest
bloodearnest / action-cli.py
Last active June 3, 2021 09:22
Example snippet for a reusable action cli parsing code, with optional validation
import argparse
import json
from pathlib import Path
class ActionConfig:
def __init__(self, validator=None):
self.validator = validator
@bloodearnest
bloodearnest / example.py
Last active April 20, 2021 14:54
Using python stdlib urllib to make requests and unit testing them
import json
from http import HTTPStatus
from urllib.request import HTTPError, Request, urlopen
def read_response_json(response):
if "application/json" in response.headers["Content-Type"]:
return json.loads(response.read().decode("utf8"))
OpenSAFELY Github actions
=========================
Central repository of github workflows that can be referenced from OpenSAFELY projects.
Note: these don't yet exist, I'm trying to figure out what we want.
| Study Actions | Description | Stage |
@bloodearnest
bloodearnest / gist:dbc5295eaec80d638da68c423123187f
Last active October 20, 2020 11:54
Proxy ghcr.io with auth realm rewrite
map $upstream_http_www_authenticate $auth_header {
~(.*)ghcr.io(.*) $1example.com$2;
}
server {
server_name example.com
...
from flask import Flask
from flask_socketio import SocketIO
import talisker.flask
app = Flask(__name__)
talisker.flask.register(app)
socketio = SocketIO(app)
.ONESHELL:
python: private SHELL=python
python:
for i in range(10):
print('OMG!')
def f(x):
print(x)
f('this is awesome')