Skip to content

Instantly share code, notes, and snippets.

View robertknight's full-sized avatar

Robert Knight robertknight

View GitHub Profile
@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>`)
@robertknight
robertknight / vitalsource-local-hypothesis.md
Last active June 30, 2022 10:18
Testing VitalSource assignments with your local Hypothesis development environment

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 June 4, 2022 10:07
ImageBitmap orientation test
<html>
<title>Canvas drawImage EXIF orientation test</title>
<style>
#dropZone {
width: 300px;
height: 100px;
background-color: #aaa;
border: 1px solid #ccc;
}