Skip to content

Instantly share code, notes, and snippets.

View michaelosthege's full-sized avatar

Michael Osthege michaelosthege

View GitHub Profile
@michaelosthege
michaelosthege / Leigh1968_harelynx.csv
Last active September 11, 2025 18:27
Hudson Bay company Lynx-Hare dataset from Leigh 1968, parsed from paper copy http://katalog.ub.uni-heidelberg.de/titel/66489211 (This is the entire Table II)
year hare lynx
1847 21000 49000
1848 12000 21000
1849 24000 9000
1850 50000 7000
1851 80000 5000
1852 80000 5000
1853 90000 11000
1854 69000 22000
1855 80000 33000
@michaelosthege
michaelosthege / compress_colors.py
Created December 7, 2022 19:33
Python script to convert PDF pages with grayscale content to grayscale color information.
# MIT License
# Copyright (c) 2022 Michael Osthege
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
"""Sampling parameters of a lorenz attractor.
The forward pass integrates the lorenz attractor ODE system using
tt.scan with a Runge-Kutta integrator. The predicted high-resolution
timecourse is interpolated down so it can be compared to low-density
observations.
"""
import abc
import numpy
import pymc3
@michaelosthege
michaelosthege / convert.py
Last active February 28, 2024 22:16
Convert MP4/AVI clips to GIF with a single Python function
import imageio
import os, sys
class TargetFormat(object):
GIF = ".gif"
MP4 = ".mp4"
AVI = ".avi"
def convertFile(inputpath, targetFormat):
"""Reference: http://imageio.readthedocs.io/en/latest/examples.html#convert-a-movie"""
@michaelosthege
michaelosthege / BroadcastReceiver.cs
Last active December 22, 2022 06:24
Unity UdpClient and UWP DatagramSocket for receiving UDP broadcasts.
using System.Text;
#if UNITY_EDITOR
using System.Net.Sockets;
using System.Threading;
#else
using Windows.Networking.Sockets;
using Windows.Storage.Streams;
using System.Threading.Tasks;
using System.IO;
using Windows.Networking;
@michaelosthege
michaelosthege / mypy_groupby.py
Created February 5, 2022 21:23
Reformats piped mypy output to group by the error code.
"""
Reformats piped mypy output to group by the error code.
Author: Michael Osthege
License: MIT
Usage
-----
mypy -p mypackage --show-error-codes | python mypy_groupby.py
"""
@michaelosthege
michaelosthege / DatagramSocketReceiver.cs
Created June 24, 2017 21:06
Unity UdpClient (#if UNITY_EDITOR) and UWP DatagramSocket (#if !UNITY_EDITOR) for receiving UDP broadcasts.
public class BroadcastReceiver : IDisposable
{
//OnMessageReceived
public delegate void AddOnMessageReceivedDelegate(string message, IPEndPoint remoteEndpoint);
public event AddOnMessageReceivedDelegate MessageReceived;
private void OnMessageReceivedEvent(string message, IPEndPoint remoteEndpoint)
{
if (MessageReceived != null)
MessageReceived(message, remoteEndpoint);
}
@michaelosthege
michaelosthege / linear_interpolation.py
Created July 20, 2017 13:25
vectorized linear interpolation in numpy
import numpy
from matplotlib import pyplot
def interpolate(x_fix, y_fix, x_var):
x_repeat = numpy.tile(x_var[:,None], (len(x_fix),))
distances = numpy.abs(x_repeat - x_fix)
x_indices = numpy.searchsorted(x_fix, x_var)
@michaelosthege
michaelosthege / _R0_regions.ipynb
Last active August 12, 2020 19:21
Analysis of Rt.live model estimates of R0 - a comparison between US regions (alternative link: https://nbviewer.jupyter.org/gist/michaelosthege/6cd14970dd789247176c4d4a1dd28051/_R0_regions.ipynb)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@michaelosthege
michaelosthege / install-pymc3.bat
Last active August 10, 2020 10:21
pymc3-installation
conda create -n pm3 python=3.7 pandas jupyter matplotlib mkl-service libpython m2w64-toolchain coverage xlrd openpyxl scipy -y
activate pm3
# install last release from PyPI
pip install pymc3
# or latest version directly from master:
pip install git+https://github.com/pymc-devs/pymc3
# or from master in editable mode:
git clone https//github.com/pymc-devs/pymc3 pymc3
cd pymc3