Skip to content

Instantly share code, notes, and snippets.

View acdha's full-sized avatar

Chris Adams acdha

View GitHub Profile
@acdha
acdha / .stylelintrc.json
Created December 19, 2016 16:41
Generate stylelint-order declaration-block-property-groups-structure lists from csscomb presets
{
"plugins": [
"stylelint-order"
],
"extends": "stylelint-config-standard",
"rules": {
"order/declaration-block-property-groups-structure": [
[
{
"emptyLineBefore": "always",
@acdha
acdha / Results using Python 2.7.12
Last active November 8, 2016 21:59
Python sparse list memory / time benchmarks
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
acdha / homebrew-gdal-ctypes.traceback
Created October 3, 2016 21:26
Traceback from a crash introduced by a recent Homebrew update when Python ctypes tries to load gdal
Traceback (most recent call last):
File "/Users/cadams/.virtualenvs/wdl/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
django.setup()
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/cadams/.virtualenvs/wdl/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
@acdha
acdha / collapsed.py
Last active February 20, 2023 14:39
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
See https://cwiki.apache.org/confluence/display/solr/Collapse+and+Expand+Results
Usage::
sqs = sqs.collapse('item_grouping', sort='"score DESC, wdl_id ASC"')
sqs = sqs.expand(rows=2, fq='django_ct:core.file')
@acdha
acdha / generate-iiif-test-urls.py
Last active April 20, 2016 20:38
Quick and dirty scripts to measure performance of IIIF servers
#!/usr/bin/env python3
"""
Collect test URLs using something like this::
for collection in https://www.loc.gov/{maps,photos,newspapers}/collections/; do
for item in $(http "${collection}?fo=json" | jq -r '.featured_items[] | .url'); do
http "https://www.loc.gov$(echo $item | sed -e 's/^.*\/item/\/item/' )?fo=json" | extract-urls | grep -E '(iiif|[.]jp2)';
done;
done
"""
@acdha
acdha / ga-record-chrome.loadtimes.js
Created March 11, 2016 13:11
Record first paint time from chrome.loadTimes (Chrome/Opera, IE11) to Google Analytics
(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(window.chrome.loadTimes)) {
var loadTimes = window.chrome.loadTimes();
@acdha
acdha / github-list-repos.py
Created March 10, 2016 19:38
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,
unicode_literals)
import subprocess
from getpass import getpass, getuser
import keyring
from github3 import authorize, login
@acdha
acdha / optimize-solr
Last active February 27, 2016 14:36
Crude but effective cron watchdog for Apache Solr
#!/bin/bash
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/>'
@acdha
acdha / check-akamai-status.js
Last active February 12, 2017 17:24
Load a page using PhantomJS and log Akamai CDN cache diagnostic information for every requested resource
#!/usr/bin/env phantomjs --disk-cache=false
/*
Load one or more URLs requesting Akamai CDN diagnostic information for every resource
and list resources which are configured not to be cached:
phantomjs check-akamai-status.js https://www.microsoft.com/ http://www.state.gov https://www.wdl.org/en/
Additional timing information will be displayed to easily distinguish between requests
made before DOMContentLoaded or the full load event.
*/
@acdha
acdha / rewrite-wdl-links.sh
Last active January 15, 2016 21:07
🔒 Use pywikibot replace.py to rewrite WDL.org links to use HTTPS