Skip to content

Instantly share code, notes, and snippets.


Kyle McDonald kylemcdonald

View GitHub Profile
kylemcdonald /
Created Aug 29, 2019
Example of multithreaded/multiprocess workers in Python.
from multiprocessing import Process as WorkerType
# uncomment this line to try multithreading instead
# from threading import Thread as WorkerType
from multiprocessing import Queue
from time import sleep
def job_loop(id, q):
print(id, 'ready')
kylemcdonald / Line Segment Intersection.ipynb
Created Jul 2, 2019
Python Line Segment Intersection example.
View Line Segment Intersection.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kylemcdonald / getUserMedia-setup.js
Last active May 30, 2019
Some things that can go wrong when setting up a camera with getUserMedia.
View getUserMedia-setup.js
function cameraReady(videoElement) {
console.log('cameraReady: checking...');
if (videoElement) {
if (videoElement.srcObject) {
let tracks = videoElement.srcObject.getVideoTracks();
if (tracks.length > 0) {
if (tracks[0].readyState == 'live') {
let w = videoElement.videoWidth, h = videoElement.videoHeight;
if (w > 0 || h > 0) {
console.log('cameraReady: live! ' + w + 'x' + h);
kylemcdonald /
Created Apr 19, 2019
GPT-2 completions for Mueller report


In a later November 2018 interview, Corsi stated that he thought that he had told people on a WND conference call about the forthcoming tape and had sent out a tweet asking whether anyone could contact Assange, but then said that maybe he had done nothing. The Office investigated Corsi's allegations about the events of October 7, 2016 but found little corroboration for his allegations about the day. However, the phone records themselves do not indicate that the conversation was with any of the reporters who broke the Access Hollywood story, and the Office has not otherwise been able to identify the substance of the conversation.


  1. According to a transcript of the October 7, 2016 interview posted on Wikileaks, Corsi said that he did talk about "the sexual assault case" that had emerged in the wake of Trump's election...
  2. The story also has new details about the relationship between WikiLeaks founder Julian Assange and the media. In a public statement, the WikiLeaks founder said that he ha
kylemcdonald / centerText.js
Created Apr 16, 2019
Draw centered text on a canvas, maximally filling a given maxWidth/maxHeight.
View centerText.js
function centerText(text, canvas, config) {
var ctx = canvas.getContext('2d');
var x = config.x;
var y = config.y;
var maxWidth = config.maxWidth || canvas.width;
var maxHeight = config.maxHeight || canvas.height;
var lineHeight = config.lineHeight || 1.2;
var fontFamily = config.fontFamily || 'sans-serif';;
var lines = text.split('\n');
kylemcdonald / tileText.js
Created Apr 16, 2019
Tile text across a canvas.
View tileText.js
function tileText(text, canvas, config) {
var fontSize = config.fontSize || 20;
var lineHeight = config.lineHeight || 1.2;
var fontFamily = config.fontFamily || 'sans-serif';
var pad = config.padding || fontSize;
var lineHeightPx = lineHeight * fontSize;
if (config.lineSnap) {
var textRows = Math.floor(canvas.height / lineHeightPx);
lineHeightPx = canvas.height / textRows;
kylemcdonald /
Last active Apr 28, 2021
DTW MSE numba function for use with UMAP.
# based on
# with modifications to be fully njit-able
import numpy as np
from numba import njit
def sqeuclidean(a, b):
return np.sum((a - b)**2)
kylemcdonald / hasVideo.js
Created Apr 8, 2019
Check if a browser has video input.
View hasVideo.js
async function checkVideo() {
const devices = await navigator.mediaDevices.enumerateDevices()
const hasVideo = devices.filter(device => device.kind === 'videoinput')
if (hasVideo.length) return true;
else return false;
checkVideo().then(e => console.log(e));
kylemcdonald / Earth Mover's Distance.ipynb
Created Apr 7, 2019
Faster 1d Earth Mover's Distance with numpy and numba.
View Earth Mover's Distance.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.