Skip to content

Instantly share code, notes, and snippets.

@evansd
evansd / get_bad_email_address.py
Created February 4, 2020 15:43
Use the flanker library to get all the bad email addresses included in the list supplied on stdin
#!/usr/bin/env python
# pip install flanker dnsq
#
# requirements.txt:
# attrs==19.3.0
# cffi==1.13.2
# chardet==3.0.4
# cryptography==2.8
# dnspython==1.16.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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.
#!/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