Skip to content

Instantly share code, notes, and snippets.

Chris Adams acdha

Block or report user

Report or block acdha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
acdha /
Created Feb 15, 2017
How to see the modules available in your current local namespace
import inspect
import math
print("all local variables:")
print("just the modules:")
print([name for name, value in locals().items() if inspect.ismodule(value)])
acdha / .gitattributes
Last active Jan 23, 2017
Example using Git attributes to make human-friendly output from custom file formats
View .gitattributes
bagit.xml diff=xml2rfc
acdha / .stylelintrc.json
Created Dec 19, 2016
Generate stylelint-order declaration-block-property-groups-structure lists from csscomb presets
View .stylelintrc.json
"plugins": [
"extends": "stylelint-config-standard",
"rules": {
"order/declaration-block-property-groups-structure": [
"emptyLineBefore": "always",
acdha / Results using Python 2.7.12
Last active Nov 8, 2016
Python sparse list memory / time benchmarks
View Results using Python 2.7.12
Testing size 100
⏱ allocate empty list 0.00001 seconds
Empty list size: 888
⏱ populate list with fake results 0.00003 seconds
“Populated” list size: 5848
⏱ allocate empty sparse list 0.00000 seconds
Empty list size: 808
⏱ populate sparse list with fake results 0.00003 seconds
“Populated” list size: 6776
acdha / homebrew-gdal-ctypes.traceback
Created Oct 3, 2016
Traceback from a crash introduced by a recent Homebrew update when Python ctypes tries to load gdal
View homebrew-gdal-ctypes.traceback
Traceback (most recent call last):
File "/Users/cadams/.virtualenvs/wdl/bin/django-admin", line 11, in <module>
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/core/management/", line 354, in execute_from_command_line
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/core/management/", line 328, in execute
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/", line 18, in setup
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/apps/", line 85, in populate
acdha /
Last active Dec 11, 2016
Django Haystack backend support for Solr's Collapsing query parser and Expand component
# encoding: utf-8
Experimental SearchQuerySet exposing Solr's Collapse filter and Expand component
sqs = sqs.collapse('item_grouping', sort='"score DESC, wdl_id ASC"')
sqs = sqs.expand(rows=2, fq='django_ct:core.file')
acdha /
Last active Apr 20, 2016
Quick and dirty scripts to measure performance of IIIF servers
#!/usr/bin/env python3
Collect test URLs using something like this::
for collection in{maps,photos,newspapers}/collections/; do
for item in $(http "${collection}?fo=json" | jq -r '.featured_items[] | .url'); do
http "$(echo $item | sed -e 's/^.*\/item/\/item/' )?fo=json" | extract-urls | grep -E '(iiif|[.]jp2)';
acdha / ga-record-chrome.loadtimes.js
Created Mar 11, 2016
Record first paint time from chrome.loadTimes (Chrome/Opera, IE11) to Google Analytics
View ga-record-chrome.loadtimes.js
(function ($) {
'use strict';
function recordTimeToFirstPaint() {
// Use Chrome's loadTimes or IE 9+'s msFirstPaint to record the time to render in milliseconds:
var firstPaintTime, timingSource;
if ('chrome' in window && $.isFunction( {
var loadTimes =;
acdha /
Created Mar 10, 2016
Quick and dirty utility to list all of the repositories which your account has access to
#!/usr/bin/env python3
from __future__ import (absolute_import, division, print_function,
import subprocess
from getpass import getpass, getuser
import keyring
from github3 import authorize, login
acdha / optimize-solr
Last active Feb 27, 2016
Crude but effective cron watchdog for Apache Solr
View optimize-solr
set -eu
exec >/dev/null
sleep $((120 + ($RANDOM % 1800)))
curl -s http://localhost:8986/solr/{ar,en,es,fr,pt,ru,zh}/update -H 'Content-Type: text/xml' --data-binary '<commit waitSearcher="true"/>'
curl -s http://localhost:8986/solr/{ar,en,es,fr,pt,ru,zh}/update -H "Content-Type: text/xml" --data-binary '<optimize/>'
You can’t perform that action at this time.