Skip to content

Instantly share code, notes, and snippets.

View robertknight's full-sized avatar

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / hypothesis-export.py
Created October 28, 2024 13:09
Minimalist Hypothesis export script
import getpass
import json
import re
import sys
import requests
GROUP_URL_PATTERN = "https://hypothes.is/groups/([^/]+)/.*"
api_token = getpass.getpass(
@robertknight
robertknight / find_pyramid_routes.py
Created October 8, 2024 08:52
Pyramid route-finding script
# Analysis of Hypothesis Python app routes as part of
# https://github.com/hypothesis/playbook/issues/1797#issuecomment-2397242000.
import os
import ast
import sys
def find_py_files(root_dir):
excluded_dirs = ["node_modules", "build", "test", "tests", "third_party"]
@robertknight
robertknight / youtube_captions_api_test.py
Last active August 1, 2024 12:11
YouTube captions API test
# Script to fetch and print the transcript for a YouTube video using the
# YouTube Data API v3.
#
# 1. Create a project in the Google API Console
# 2. Enable the YouTube Data API v3 for the new project
# 3. Create credentials for a "Desktop" OAuth client. Download the JSON file
# containing the credentials at the end of the setup process.
# 4. Create a new virtualenv and install dependencies with:
#
# ```
@robertknight
robertknight / accelerate_gemv.cpp
Created March 14, 2024 08:58
Apple Accelerate sgemv benchmark
#include <algorithm>
#include <chrono>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>
#include <Accelerate/Accelerate.h>
#include <cblas.h>
@robertknight
robertknight / rectify.py
Last active March 2, 2024 09:48
Rectify a portion of an image using OpenCV
import cv2
import numpy as np
import argparse
def warp_quadrilateral(
input_path: str,
src_points: list[tuple[int, int]],
output_path: str,
output_size: tuple[int, int],
@robertknight
robertknight / rten_ndarray_conv.rs
Last active January 24, 2024 07:52
rten-ndarray conversion
use ndarray::{Array, Array2, ArrayView, Dim, Dimension, Ix, StrideShape};
use rten_tensor::prelude::*;
use rten_tensor::{NdTensor, NdTensorView};
/// Convert an N-dimensional ndarray view to an [NdTensorView].
///
/// Returns `None` if the view is not in the standard layout (see
/// [ArrayView::is_standard_layout]).
fn as_ndtensor_view<'a, T, const N: usize>(
@robertknight
robertknight / avx-512-gemm-kernel.s
Created December 29, 2023 18:20
Annotated AVX-512 gemm kernel
# At entry params are:
#
# tile_ptr (rdi)
# tile_row_stride (rsi)
# a (rdx, rcx)
# b (r8, r9)
# depth (stack)
# alpha (xmm0)
# beta (xmm1)
.section __TEXT,__text,regular,pure_instructions
//! Port of https://github.com/danieldk/gemm-benchmark/ for comparison of
//! matrix multiplication performance against other popular libraries.
use std::time::Duration;
use wasnn::gemm;
use wasnn_tensor::prelude::*;
use wasnn_tensor::NdTensor;
use rayon::iter::IntoParallelIterator;
@robertknight
robertknight / fetch-annotation-pages.py
Last active February 6, 2023 11:17
Script to page through annotations in a Hypothesis group
import os
import requests
search_after = ""
page_size = 200
group = os.environ["HYPOTHESIS_GROUP"]
access_token = os.environ["HYPOTHESIS_ACCESS_TOKEN"]
max_to_fetch = 10_000 # Max annotations to fetch before we stop
@robertknight
robertknight / hypothesis-canonical-links.md
Created July 7, 2022 10:37
How Hypothesis interacts with canonical links (`<link rel=canonical>`)