Skip to content

Instantly share code, notes, and snippets.

#!/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 / 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
#!/usr/bin/env python
import time
import sys
import lmdb
import numpy
import pyarrow
import scipy.sparse
#import zstandard
#!/usr/bin/env python
import csv
import itertools
import sys
import lmdb
import numpy
import pyarrow
import scipy.sparse
#!/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
}
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
@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
@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
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)]
# make a quick 30-second gif screencast
alias gifcast='byzanz-record -v -c -d 30 --delay 5 screencast.gif'