Skip to content

Instantly share code, notes, and snippets.

View robertknight's full-sized avatar

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / copy-button.diff
Created August 8, 2017 05:59
Add copy button to share dialog
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 August 4, 2017 06:50
eLife Hypothesis Config
{
"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 March 4, 2022 05:59
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
robertknight / using-nvda-in-a-windows-vm-on-mac.md
Created July 3, 2017 13:23
Testing the Windows screenreader NVDA on a Mac

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 June 16, 2017 15:40
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
robertknight / gist:854a07bff300214a75fd49144ede7501
Created June 13, 2017 13:23
Intermittent failure fetching ReadTheDocs URL
(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"
@robertknight
robertknight / shallowRender.js
Created April 1, 2017 09:15
Shallow rendering implementation for Preact
import { options, render } from 'preact';
import { ATTR_KEY } from 'preact/src/constants';
/**
* Returns the input properties that were passed to an element when it was
* rendered.
*
* See `shallowRender` documentation for usage example.
*/
@robertknight
robertknight / warn-on-undefined-expressions.js
Created March 23, 2017 15:46
Intercepting undefined variable accesses in expressions in Angular 1.x templates
'use strict';
/* global Proxy */
// Set of expressions for which warnings have been emitted
var warnedExpressions = {};
/**
* Return a proxy which warns on accesses to undefined properties in
* expressions.
@robertknight
robertknight / visible-anns.diff
Last active February 28, 2017 19:09
Computing visible annotation tags and notifying host page
diff --git a/src/sidebar/frame-sync.js b/src/sidebar/frame-sync.js
index 8a80563..6a505d7 100644
--- a/src/sidebar/frame-sync.js
+++ b/src/sidebar/frame-sync.js
@@ -2,6 +2,7 @@
var events = require('./events');
var bridgeEvents = require('../shared/bridge-events');
+var memoize = require('./util/memoize');
var metadata = require('./annotation-metadata');
@robertknight
robertknight / typo.ts
Created January 9, 2017 19:21
How TypeScript handles optional properties when checking for structural compatibility of types
type MyType = {
foo: string;
bar?: string;
}
function doStuffWithMyType(_: MyType) {}
function typoExample() {
doStuffWithMyType({
foo: 'herp',