Skip to content

Instantly share code, notes, and snippets.

View kylemcdonald's full-sized avatar

Kyle McDonald kylemcdonald

View GitHub Profile
View benchmark-ipc-socket.py
import os
import socket
import time
import struct
from multiprocessing import Process
socket_path = "/tmp/ipc_benchmark_socket"
def run_server():
if os.path.exists(socket_path):
@kylemcdonald
kylemcdonald / FixedVideoDelay.h
Created December 19, 2023 10:12
Video delay for openFrameworks.
View FixedVideoDelay.h
#pragma once
#include <vector>
#include "ofImage.h"
class FixedVideoDelay {
private:
int delayAmount;
int totalFrames;
int readPosition;
@kylemcdonald
kylemcdonald / collector.py
Created December 11, 2023 15:43
PUSH-PULL pattern with ZMQ.
View collector.py
import zmq
context = zmq.Context()
socket = context.socket(zmq.PULL)
socket.bind("tcp://*:5558")
print("Collector started... collecting results.")
while True:
result = socket.recv_json()
print(f"Collected: {result}")
@kylemcdonald
kylemcdonald / threaded-pipeline.py
Created December 8, 2023 09:33
Example of a threaded pipeline in Python.
View threaded-pipeline.py
import threading
import queue
class ThreadedWorker():
def __init__(self):
self.input_queue = queue.Queue()
self.output_queue = queue.Queue()
self.should_exit = False
self.thread = threading.Thread(target=self.run)
@kylemcdonald
kylemcdonald / fixed_noise.py
Last active December 8, 2023 05:46
Monkeypatch diffusers to use fixed noise.
View fixed_noise.py
import types
import PIL
import torch
from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl_img2img import retrieve_latents
from diffusers.utils.torch_utils import randn_tensor
def prepare_latents(
self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None, add_noise=True, fixed_noise=True
):
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
@kylemcdonald
kylemcdonald / parse-heatmap.py
Last active January 21, 2024 08:05
Parse the ADSBX heatmap files.
View parse-heatmap.py
import numpy as np
import datetime
import re
from dataclasses import dataclass
def point_to_str(point):
hex = f"{point & 0xFFFFFF:06x}"
hex = ("~" + hex) if (point & 0x1000000) else hex
return hex
@kylemcdonald
kylemcdonald / download-heatmaps.py
Created November 6, 2023 22:26
Download ADSB Exchange data from the heatmap endpoint.
View download-heatmaps.py
import argparse
import datetime
import urllib3
import os
from ratelimit import limits, sleep_and_retry
from tqdm import tqdm
import random
import time
domain = "globe.adsbexchange.com"
@kylemcdonald
kylemcdonald / Process and upload captions.ipynb
Created October 12, 2023 19:43
Script for converting Google Spreadsheet to Vimeo captions and uploading them automatically.
View Process and upload captions.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / fluxus.ipynb
Created October 12, 2023 00:34
Charting the lives of Fluxus members.
View fluxus.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kylemcdonald
kylemcdonald / pyaudio-test.py
Created October 11, 2023 09:27
Show microphone level in realtime using pyaudio.
View pyaudio-test.py
import pyaudio
import audioop
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16,
channels=1,
rate=44100,
input=True,
frames_per_buffer=1024)