Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle McDonald kylemcdonald

View GitHub Profile
@kylemcdonald
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';
ctx.save();
var lines = text.split('\n');
@kylemcdonald
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
kylemcdonald / dtw_mse.py
Last active Apr 28, 2021
DTW MSE numba function for use with UMAP.
View dtw_mse.py
# 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 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
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.
@kylemcdonald
kylemcdonald / ssl-mac.md
Last active Jan 22, 2021
Set up SSL server on Mac.
View ssl-mac.md

Update: Use mkcert instead

Based on this tutorial.

First set your location:

export COUNTRY="US"
export STATE="California"
export CITY="Los Angeles"
View stylegan.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View heaven.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / Camera2d.h
Created Jan 30, 2019
2D Zoomable Region for openFrameworks. Scroll to zoom. Left click and drag to translate.
View Camera2d.h
class Camera2d : public ofCamera {
private:
ofVec2f mouseStart;
ofVec2f startPosition;
float zoom;
float maxZoom = .01;
float minZoom = 1;
float zoomSpeed = 1. / 500;
public:
void setup() {