Skip to content

Instantly share code, notes, and snippets.

View robertknight's full-sized avatar

Robert Knight robertknight

View GitHub Profile
@robertknight
robertknight / rten_ndarray_conv.rs
Last active January 24, 2024 07:52
rten-ndarray conversion
View rten_ndarray_conv.rs
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
View avx-512-gemm-kernel.s
# 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
View gemm_bench.rs
//! 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
View fetch-annotation-pages.py
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>`)
View hypothesis-canonical-links.md
@robertknight
robertknight / vitalsource-local-hypothesis.md
Last active June 30, 2022 10:18
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 June 4, 2022 10:07
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
Last active January 17, 2023 22:37
License report for Hypothesis project dependencies
View license-report.md
@robertknight
robertknight / private-memory-stats.py
Last active July 20, 2021 11:45
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 July 19, 2021 08:22
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');