Skip to content

Instantly share code, notes, and snippets.

View kylemcdonald's full-sized avatar

Kyle McDonald kylemcdonald

View GitHub Profile
@kylemcdonald
kylemcdonald / a2-collections.py
Last active October 14, 2019 03:39
List a2p collections.
from urllib.request import urlopen
import json
from multiprocessing import Pool
traders = json.load(urlopen('https://a2p.bitmark.com/s/api/traders'))
id_to_alias = {}
tasks = []
for trader in traders['traders']:
id = trader['id']
id_to_alias[id] = trader['alias']
@kylemcdonald
kylemcdonald / Interprocess Queue Performance.ipynb
Created September 8, 2019 15:10
Testing the performance of Queue-based IPC in Python 3.7.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / threaded-worker.py
Created August 29, 2019 02:31
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
kylemcdonald / Line Segment Intersection.ipynb
Created July 2, 2019 18:49
Python Line Segment Intersection example.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / getUserMedia-setup.js
Last active May 30, 2019 01:38
Some things that can go wrong when setting up a camera with getUserMedia.
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
kylemcdonald / mueller-gpt-2.md
Created April 19, 2019 15:49
GPT-2 completions for Mueller report

Seed

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.

Output

  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
kylemcdonald / centerText.js
Created April 16, 2019 23:46
Draw centered text on a canvas, maximally filling a given maxWidth/maxHeight.
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';
ctx.save();
var lines = text.split('\n');
@kylemcdonald
kylemcdonald / tileText.js
Created April 16, 2019 23:45
Tile text across a canvas.
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
kylemcdonald / dtw_mse.py
Last active April 28, 2021 16:28
DTW MSE numba function for use with UMAP.
# based on https://github.com/kylerbrown/ezdtw
# with modifications to be fully njit-able
import numpy as np
from numba import njit
@njit
def sqeuclidean(a, b):
return np.sum((a - b)**2)
@kylemcdonald
kylemcdonald / hasVideo.js
Created April 8, 2019 20:25
Check if a browser has video input.
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));