Skip to content

Instantly share code, notes, and snippets.

View michaelosthege's full-sized avatar

Michael Osthege michaelosthege

View GitHub Profile
@michaelosthege
michaelosthege / benchmark.py
Created July 6, 2017 12:05
Benchmarking helpers
import time
class Measurement(object):
def __init__(self, name):
self.name = name
return
def __enter__(self):
self.t_start = time.time()
return
@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 / 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 / weirdimport.py
Created March 7, 2017 22:04
import python stuff from any directory
def weirdimport(*paths):
import os, sys
fullpath = os.path.abspath(os.path.join(*paths))
global project
sys.path.append(os.path.dirname(fullpath))
try:
project = __import__(os.path.basename(fullpath))
sys.modules['project'] = project
finally:
del sys.path[-1]
@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"""