Skip to content

Instantly share code, notes, and snippets.

Robert Knight robertknight

View GitHub Profile
robertknight /
Created Aug 27, 2018
Colander schemas for query string parsing
class ColanderSearchParamsSchema(colander.Schema):
# Fields that affect search result number and ordering.
sort = colander.SchemaNode(colander.String(),
validator=colander.OneOf(["updated", "created", "id", "group", "user"]),
order = colander.SchemaNode(colander.String(),
validator=colander.OneOf(["asc", "desc"]),
robertknight /
Last active Mar 5, 2018
Using the Hypothesis development client on secure websites
robertknight / check-index-status.go
Last active Jan 19, 2018
Script to check for presence of annotations in an h Elasticsearch index
View check-index-status.go
package main
import (
robertknight /
Last active Sep 7, 2017
eLIFE tech discussion - 2017-09-05

eLife tech discussion


  • chdorner
  • dthompson
  • robertknight


robertknight / copy-button.diff
Created Aug 8, 2017
Add copy button to share dialog
View copy-button.diff
diff --git a/src/sidebar/components/share-dialog.js b/src/sidebar/components/share-dialog.js
index 652d1b8d..534597e4 100644
--- a/src/sidebar/components/share-dialog.js
+++ b/src/sidebar/components/share-dialog.js
@@ -2,6 +2,21 @@
var VIA_PREFIX = '';
+function copyToClipboard(text) {
+ // Temporarily add a hidden input element and populate it with the text we
robertknight / config.json
Created Aug 4, 2017
eLife Hypothesis Config
View config.json
"showHighlights": "whenSidebarOpen",
"branding": {
"accentColor": "#0288D1",
"appBackgroundColor": "white",
"ctaBackgroundColor": "#0288D1",
"ctaTextColor": "white",
"selectionFontFamily": "Georgia, Times, serif",
"annotationFontFamily": "Georgia, Times, serif"
robertknight /
Last active Dec 5, 2019
Promises + IndexedDB Test

This gist demonstrates a problem with IndexedDB & Promises in Firefox which makes using IndexedDB very unergonomic in some cases in Firefox.

The test below reads, updates & writes a counter value to an IndexedDB database 10 times in the same transaction and then prints the result. To make the code easier to read, it uses async + await, which requires converting the IndexedDB requests (IDBRequest objects) to promises with a simple helper.

In Chrome, multiple promise callbacks can be executed with auto-committing an IDB transaction, allowing read-modify-write steps to work. In Firefox however, the IDB transaction gets auto-committed before the promise callback is fired, which means that read-modify-write operations have to use callbacks rather than promises.

robertknight /
Created Jul 3, 2017
Testing the Windows screenreader NVDA on a Mac

How to test NVDA screen reader behaviour on a Mac:

  1. Download Microsoft Edge VM from
  2. Download Virtualbox and import the Edge VM image.

Then in the VM:

  1. Install guest addons in the VM
  2. Download & install latest NVDA from
  3. Download & install SharpKeys and use it to map left an alternative key (eg. Left Ctrl) to the Insert key. This is needed because Macs do not typically have an “Insert” key which is the prefix for many NVDA commands.
robertknight /
Created Jun 16, 2017
Convert UUIDs from the annotations table in Hypothesis' database to annotation IDs as seen in the API
#!/usr/bin/env python
import argparse
import base64
import binascii
import sys
import uuid
ES_FLAKE_MAGIC_BYTE = ['e', '5']
robertknight / gist:854a07bff300214a75fd49144ede7501
Created Jun 13, 2017
Intermittent failure fetching ReadTheDocs URL
View gist:854a07bff300214a75fd49144ede7501
(h) ~/h/r/h > curl -I ''
HTTP/1.1 200 OK
Server: nginx/1.10.0 (Ubuntu)
Date: Tue, 13 Jun 2017 13:20:52 GMT
Content-Type: text/html
Content-Length: 326
Last-Modified: Mon, 05 Jun 2017 09:11:35 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "59352047-146"
You can’t perform that action at this time.