Skip to content

Instantly share code, notes, and snippets.

View mwmuni's full-sized avatar

Matthew Muller mwmuni

  • Perth, Australia
View GitHub Profile
@mwmuni
mwmuni / example_python_concurrent_interpreters.py
Last active October 13, 2025 08:08
Runs a demo of Python’s experimental concurrent.interpreters module: spins up five sub-interpreters, pushes ten “Task N” messages through a shared queue, echoes completions back to the main interpreter, and then shuts everything down with sentinel None signals.
# /// script
# requires-python = ">=3.14"
# ///
import concurrent.interpreters as ci
from time import sleep
def consume_queue(qin: ci.Queue, qout: ci.Queue, id: int = 0):
while True:
item = qin.get()
if item is None: # Use None as a sentinel to stop the consumer
@mwmuni
mwmuni / input.txt
Created December 23, 2024 07:53
An implementation of finding the longest line in a file
abd
ccd
adadfsgsgs
sadagfa
@mwmuni
mwmuni / top-k-byte-counting.c
Created September 21, 2024 17:12
Top-K integer algorithm with O(N) time complexity and O(N) space complexity. Achieves this by using a counting strategy with a constant width of 4, and a constant depth of 256.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BINS 256
#define NUM_BYTES (sizeof(int) / sizeof(char))
#define K 3
void find_top_k(int *data, int n, int byte_pos, int k, int *top_k, int *current_k) {
if (n == 0 || *current_k >= k || byte_pos >= NUM_BYTES) {
@mwmuni
mwmuni / restore_from_torchscript.py
Last active August 8, 2024 16:27
Restore a torchscript model back into a torch module
from torch.nn import Sequential, Linear, ReLU, Tanh
# Model had an 'actor' attribute that was a Sequential type in this case
model = torch.jit.load(path)
model_modules = model.actor._modules._python_modules
def convert_module(module):
if module.original_name == "Sequential":
layers = []
for sub_key in module._modules._python_modules:
@mwmuni
mwmuni / torch_gaussian.py
Created May 31, 2024 09:58
Special retro gaussian
# Use torch to smooth the pixel art
import os
# Set environment QT_QPA_PLATFORM
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import cv2
@mwmuni
mwmuni / how-to-compile.md
Last active December 23, 2023 11:58
Animated Sine wave with OpenGL in C++

Compile the code with:

$ g++ sine_opengl.cpp -o sine-gl -lGL -lGLU -lglut

There will now be a sine-gl binary, which can be run:

$ ./sine-gl