Skip to content

Instantly share code, notes, and snippets.

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / schema.py
Created Aug 27, 2018
Colander schemas for query string parsing
View schema.py
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"]),
missing="updated")
order = colander.SchemaNode(colander.String(),
validator=colander.OneOf(["asc", "desc"]),
missing="desc")
@robertknight
robertknight / using-dev-client-with-secure-websites.md
Last active Mar 5, 2018
Using the Hypothesis development client on secure websites
View using-dev-client-with-secure-websites.md
@robertknight
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 (
"bufio"
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"net/http"
@robertknight
robertknight / elife-notes-2017-09-05.md
Last active Sep 7, 2017
eLIFE tech discussion - 2017-09-05
View elife-notes-2017-09-05.md

eLife tech discussion

Present

  • chdorner
  • dthompson
  • robertknight

Agenda

@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 = 'https://via.hypothes.is/';
+function copyToClipboard(text) {
+ // Temporarily add a hidden input element and populate it with the text we
@robertknight
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
robertknight / info.md
Last active Dec 5, 2019
Promises + IndexedDB Test
View info.md

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
robertknight / using-nvda-in-a-windows-vm-on-mac.md
Created Jul 3, 2017
Testing the Windows screenreader NVDA on a Mac
View using-nvda-in-a-windows-vm-on-mac.md

How to test NVDA screen reader behaviour on a Mac:

  1. Download Microsoft Edge VM from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/
  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 nvaccess.org
  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
robertknight / uuids-to-hexids.py
Created Jun 16, 2017
Convert UUIDs from the annotations table in Hypothesis' database to annotation IDs as seen in the API
View uuids-to-hexids.py
#!/usr/bin/env python
import argparse
import base64
import binascii
import sys
import uuid
ES_FLAKE_MAGIC_BYTE = ['e', '5']
@robertknight
robertknight / gist:854a07bff300214a75fd49144ede7501
Created Jun 13, 2017
Intermittent failure fetching ReadTheDocs URL
View gist:854a07bff300214a75fd49144ede7501
(h) ~/h/r/h > curl -I 'https://h.readthedocs.io/en/latest/api/'
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.