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
@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)
#!/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
#!/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
def check(self, request):
"""Nagios health check"""
start = {}
def nagios_start(status, headers, exc_info=None):
# save status for inspection
start['status'] = status
start['headers'] = headers
response = self.app(request.environ, nagios_start)
# standard wsgi middleware
def some_wsgi_middleware(app):
def middleware(environ, start_response)
# here's the trick - set status/headers in the function scope
status = headers = None
def custom_start_response(status, headers, exc_info):
# they get overwritten here from func args
pass