Skip to content

Instantly share code, notes, and snippets.

View jampekka's full-sized avatar

Jami Pekkanen jampekka

View GitHub Profile
def project_to_ground(pos, camera, height=0.0):
matWorldInverse = np.array(camera['matrixWorldInverse']).reshape(4, 4).T
matWorld = np.linalg.inv(matWorldInverse)
proj = np.array(camera['projectionMatrix']).reshape(4, 4).T
origin = matWorld[:,3][:-1]
deproj = np.dot(matWorld, np.linalg.inv(proj))
direction = np.dot(deproj, (pos[0], pos[1], 0.5, 1.0))
direction = direction[:-1]/direction[-1]
direction -= origin
import numpy as np
import scipy.interpolate
import scipy.signal
def match_sampled_brutal(ts1, haystack, ts2, needle, minlen=100):
dt = np.median(np.diff(ts1))
ts1_base = ts1[0]
ts1 = ts1 - ts1_base
@jampekka
jampekka / activity.py
Created April 2, 2017 20:56
/r/place activity animated heatmap
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats
import pyximport; pyximport.install()
from pixcount import pixcount
import scipy.ndimage
data = np.load('diffs.npy')
ts = data[:,0]
frames = 1000
gistup
/*
* GStreamer
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
* Copyright (C) 2017 Jami Pekkanen <jami.pekkanen@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
#include <opencv2/opencv.hpp>
#include <string>
using namespace cv;
int main(int argc, char **argv) {
int camno = 0;
if(argc > 2) {
camno = std::atoi(argv[1]);
}
@jampekka
jampekka / gist:61685ec5a0d8180f5ad54de937335283
Last active May 27, 2021 16:28
Historian lopun havinat
Loppuiko historian loppu:
Historian loppuun (1992)
Lätkän MM-kultaan (1995)
Sokalin tapaus (1996)
Dot-com-romahdukseen (1995)
Dianan kuolema (1997)
WTO-iskuihin (1999)
WTC-iskuihin (2001)
Pentagon-iskuihin (2001)
import numpy as np
import matplotlib.pyplot as plt
def compensatory_radius(estimate_dispersion, R):
cosarg = estimate_dispersion/R**2
# Cos will go negative when arg > pi/2. arg < 0 makes no sense, so no need to worry about that.
# Trigonometry breaks down for this at pi/2? Could probably have some sort of analytical
# continuation if needed, however pi/2 dispersion leading to center seems implausible for a
# model.
r_2 = R*np.cos(cosarg)
import pandas as pd
hs_poll_perc = {
'kok': 19.6,
'ps': 18.0,
'sdp': 17.9,
'kesk': 12.7,
'vihr': 11.1,
'vas': 8.2,
'rkp': 4.6,
@jampekka
jampekka / mind.py
Last active November 4, 2021 09:40
Simple The Mind type game
import random
import selectors
import sys
total_cards = 100
cards_per_player = 3
deck = list(range(1, total_cards + 1))
random.shuffle(deck)