Skip to content

Instantly share code, notes, and snippets.

from whitenoise import WhiteNoise
class WhiteNoiseIndex(WhiteNoise):
index_file = 'index.html'
def add_files(self, *args, **kwargs):
super(WhiteNoiseIndex, self).add_files(*args, **kwargs)
index_urls = [url for url in self.files.keys() if url.endswith('/' + self.index_file)]
@evansd
evansd / tpacpi-setup.sh
Created June 12, 2016 10:52
Thinkpad Battery Management Setup
sudo add-apt-repository ppa:morgwai/tpbat
sudo apt update
sudo apt install tpacpi-bat
# Start charging at 40%, stop charging at 80%
echo '[Unit]
Description=sets battery thresholds
[Service]
Type=oneshot
@evansd
evansd / mege_json.py
Created December 1, 2016 16:19
Merge nested JSON dictionaries
#!/usr/bin/env python
import collections
import json
import sys
MISSING = object()
class ConflictError(Exception): pass
from django.conf import settings
from django.core.exceptions import MiddlewareNotUsed
from django.http import HttpResponse
class BasicAuthMiddleware(object):
"""
Adds HTTP Basic Authentication site-wide
Useful for protecting staging/demo environments. Additionally, sets auth details
#!/bin/bash
set -eo pipefail
# https://stackoverflow.com/a/8574392/79992
contains_element () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
#!/usr/bin/env python
import csv
import itertools
import sys
import lmdb
import numpy
import pyarrow
import scipy.sparse
#!/usr/bin/env python
import time
import sys
import lmdb
import numpy
import pyarrow
import scipy.sparse
#import zstandard
@evansd
evansd / ncso_sql_for_bigquery.sql
Last active February 4, 2020 16:22
This is effectively the same SQL we use to calculate NCSO costings on the site, but adapted to be run on BigQuery
SELECT
ncso.date AS month,
vmpp.bnf_code AS bnf_code,
vmpp.nm AS product_name,
rx.quantity AS quantity,
rx.pct AS pct,
rx.practice AS practice,
dt.price_pence
* rx.quantity
* CASE WHEN
#!/bin/bash
# Converts JSON into a flat, line-by-line format
# Equivalent to https://github.com/soheilpro/catj
# Borrowed from this HN comment: https://news.ycombinator.com/item?id=20246957
exec jq -r '
tostream
| select(length > 1)
| (
@evansd
evansd / geojson_wrapper_template.json
Created June 26, 2019 09:43
Template for when you have a bunch of GeoJSON geometries that you need to wrap up as a valid GeoJSON document so you can plot it using e.g. https://geojson.io
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.