Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / hypothesis-canonical-links.md
Created Jul 7, 2022
How Hypothesis interacts with canonical links (`<link rel=canonical>`)
View hypothesis-canonical-links.md
@robertknight
robertknight / vitalsource-local-hypothesis.md
Last active Jun 30, 2022
Testing VitalSource assignments with your local Hypothesis development environment
View vitalsource-local-hypothesis.md

VitalSource assignments in the LMS are different than other assignment types because the document is being displayed in a reader maintained by a third-party (VitalSource) rather than Via. This third-party reader always tries to load the production version of Hypothesis, whereas when Via is used to deliver a document, your local instance of Via will use your local Hypothesis client. A workaround for this issue to enable local testing is to redirect the request for the client's boot script to point to your local client, and modify the local client to ignore parts of the Hypothesis configuration in the page where the client's boot script is loaded.

The approach documented here can also be used in other situations where you want to subtitute the production Hypothesis client with the local one, in a page or web application where we can't modify the script tag that loads the client.

  1. Configure your browser to redirect requests for the client's boot script at https://hypothes.is/embed.js to http://localhost:5000
@robertknight
robertknight / orientation-test.html
Created Jun 4, 2022
ImageBitmap orientation test
View orientation-test.html
<html>
<title>Canvas drawImage EXIF orientation test</title>
<style>
#dropZone {
width: 300px;
height: 100px;
background-color: #aaa;
border: 1px solid #ccc;
}
@robertknight
robertknight / license-report.md
Created Jan 7, 2022
License report for Hypothesis project dependencies
View license-report.md
@robertknight
robertknight / private-memory-stats.py
Last active Jul 20, 2021
Estimate private memory usage of a list of processes
View private-memory-stats.py
import os
import sys
def process_private_memory(pid):
smaps_path = f"/proc/{pid}/smaps"
total = 0
for line in open(smaps_path, 'r'):
field, val = [val.strip() for val in line.split(':')]
if field != "Private_Dirty":
@robertknight
robertknight / generate-svg-components.js
Last active Jul 19, 2021
Generate Preact components that render SVG icons from SVG markup
View generate-svg-components.js
/* global process */
'use strict';
const fs = require('fs');
const { basename } = require('path');
const escapeHtml = require('escape-html');
const htmlParser = require('htmlparser2');
const prettier = require('prettier');
@robertknight
robertknight / hypothesis-client-wcag-a11y.md
Last active Feb 25, 2020
Hypothesis client remaining a11y work
View hypothesis-client-wcag-a11y.md

This is a brain-dump of remaining work to achieve a fully accessible [1] Hypothesis client.

[1] fully accessible means that you can use all the functionality with a keyboard (or keyboard-emulating input device) and screen reader (or other assistive tech) conveniently and that it meets (both in letter and spirit) all the WCAG criteria. That doesn't necessarily mean that everything is as fully optimized as it could be (eg. in terms of what keyboard shortcuts are available to speed up various workflows).

Development tasks:

  1. Make it possible to activate highlights with the keyboard
  2. Make it easier to execute Annotate / Highlight commands using the keyboard
@robertknight
robertknight / reviewing-dependency-updates.md
Last active Feb 3, 2020
How I review dependency updates
View reviewing-dependency-updates.md

How I review dependency updates

These are some notes on my process when I review dependency updates for both JavaScript and Python projects at Hypothesis.

Before you add a dependency

Before adding a dependency to a project, consider the impact on future maintenance. If what the dependency does for the project can be implemented with only a few lines of code, or can be implemented in an alternative way using dependencies the project already has, it may be a better choice to do that and avoid the dependency.

Dependency update process

@robertknight
robertknight / gen_charmap.py
Last active Nov 1, 2019
Optimized charmap generation
View gen_charmap.py
import sys
import time
import unicodedata
def gen_charmap_new():
current_cat = None
current_cat_start = None
ranges = []
@robertknight
robertknight / remove-future-imports.py
Created Oct 3, 2019
Remove __future__ imports from Python files
View remove-future-imports.py
import sys
files = sys.argv[1:]
for path in files:
print(f"Updating {path}")
out_lines = []
prev_line_was_future_import = False
with open(path) as file: