Skip to content

Instantly share code, notes, and snippets.

Robert Knight robertknight

Block or report user

Report or block robertknight

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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:
@robertknight
robertknight / README.md
Last active Sep 12, 2019
Chrome range request + HTTP cache interaction issue
View README.md

Steps to reproduce:

  1. Save range-request.html locally and open it in Chrome
  2. Clear your browser cache by going to chrome://settings/clearBrowserData, checking "Cached images and files" and clicking "Clear data"
  3. Open the devtools and make sure that the "Disable cache" option is not checked in the Network tab.
  4. Click the "Fetch file with Range requests" button. Observe the console logs and wait for the complete file to be fetched.
  5. Click the "Fetch file with one request" button and observe the console logs.
  6. Click the "Fetch file with one request" button again and observe the console logs.

Expected result:

@robertknight
robertknight / google-drive-test.diff
Created Aug 22, 2019
Cross-site file fetching test in the Hypothesis LMS app
View google-drive-test.diff
diff --git a/lms/static/scripts/frontend_apps/components/FilePickerApp.js b/lms/static/scripts/frontend_apps/components/FilePickerApp.js
index 1e32c81..a040a75 100644
--- a/lms/static/scripts/frontend_apps/components/FilePickerApp.js
+++ b/lms/static/scripts/frontend_apps/components/FilePickerApp.js
@@ -91,9 +91,11 @@ export default function FilePickerApp({
try {
setLoadingIndicatorVisible(true);
const { id, url } = await googlePicker.showPicker();
+ await googlePicker.fetchFile(id);
await googlePicker.enablePublicViewing(id);
@robertknight
robertknight / delay.diff
Created Jul 29, 2019
Add a short delay to action dispatches
View delay.diff
diff --git a/src/sidebar/store/index.js b/src/sidebar/store/index.js
index 8051a738..1e725db5 100644
--- a/src/sidebar/store/index.js
+++ b/src/sidebar/store/index.js
@@ -71,6 +71,33 @@ function angularDigestMiddleware($rootScope) {
};
}
+/**
+ * Middleware which adds an artificial delay to all actions going through
@robertknight
robertknight / rate_limit_test.py
Last active Nov 16, 2018
Rate limiting test script
View rate_limit_test.py
#!/usr/bin/env python3
from binascii import hexlify
import time
from random import randint
import requests
regular_url = "http://localhost:5000/_status"
@robertknight
robertknight / putty-port-forwarding.png
Last active Oct 25, 2018
Testing and debugging Hypothesis on mobile devices and in virtual machines
@robertknight
robertknight / README.md
Last active Sep 18, 2018
Bookmarklet to toggle visibility of fixed overlays on screen
View README.md

This is a browser bookmarklet which hides annoying overlays on web pages that are positioned at fixed locations on the page and don't move as you scroll. This is particularly useful for smaller desktop screens (I have a 13" MacBook Pro). Examples include:

  • Cookie banners
  • Banners at the top and bottom of the page on Medium-powered blogs telling you to sign in
  • Navigation bars on web pages that don't scroll out of the way when you scroll down

Usage

  1. Create a new bookmark
  2. Copy the content of toggle-fixed-element.js
@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"
You can’t perform that action at this time.