Skip to content

Instantly share code, notes, and snippets.

View valsteen's full-sized avatar

Vincent Alsteen valsteen

View GitHub Profile
@valsteen
valsteen / Cargo.toml
Last active September 12, 2022 19:49
Self-feeding processing stream proof of concept
[package]
name = "processing_stream"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
futures = "0.3.24"
tokio = { version = "1.21.0", features = ["full"] }
@valsteen
valsteen / pointercontraint.go
Created August 8, 2022 14:18
Go: constraint a generic type to implement an interface with a pointer receiver
package main
// Demonstrates how to constraint a generic type to implement an interface with a pointer receiver
// inspired by this SO answer: https://stackoverflow.com/a/71444968
import (
"fmt"
"strconv"
"strings"
)
@valsteen
valsteen / concurrency_limit.py
Last active August 30, 2025 07:44
How to limit concurrency with Python asyncio?
import asyncio
from typing import Awaitable, Callable, Coroutine, Iterator
from asyncio_pool import AioPool
import pytest as pytest
from more_itertools import peekable
"""
Different approaches to "How to limit concurrency with Python asyncio?"
https://stackoverflow.com/questions/48483348/how-to-limit-concurrency-with-python-asyncio/48484593#48484593
@valsteen
valsteen / task_executor_with_queue_size_limit.py
Created May 28, 2021 12:23
Task queue executor with queue size limit
import random
from concurrent.futures import ThreadPoolExecutor
from queue import Queue
from time import sleep
class ThreadPoolExecutorWithQueueSizeLimit(ThreadPoolExecutor):
# limiting queue size allows to keep under control the memory used by the producer
# inspired by https://stackoverflow.com/a/48327162/34871
def __init__(self, max_queue_size: int, *args, **kwargs):
@valsteen
valsteen / .gitignore
Last active May 25, 2021 18:54
Example of concurrent processing with rate limit and cancellation with async-std
/target
@valsteen
valsteen / adventofcode2020_day23_part_2.rs
Created February 28, 2021 19:43
Advent of code 2020 day 23 part 2
/*
solution to the second part of https://adventofcode.com/2020/day/23
it executes in less than a minute in release mode, but it ain't pretty
main points:
- double linked list to easily insert/split/remove
- the nodes are not individual values, but ranges instead
- because looking up a value in a linked list takes so long, there is a hashmap pointing to the
slices for each value. everytime a slice is added or changed, all the values of the slice
@valsteen
valsteen / Main.java
Last active November 9, 2020 11:36
java enterprise ternary operator
package com.company;
/**
java -cp . com.company.Main "4" "3" "2"
4 is even
3 is not even
2 is even
*/
@valsteen
valsteen / reorder.py
Created April 22, 2016 12:24
stupid utility that receives timestamped lines in any order and various formats, then outputs them reordered
import dateutil.parser
import re
import sys
import pytz
tz = pytz.timezone("Europe/Vienna")
res = []
for line in sys.stdin:
@valsteen
valsteen / adventofcode23.py
Created December 23, 2015 15:58
Python solution for Advent of Code day 23 http://adventofcode.com/day/23
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import re
from collections import defaultdict
from functools import partial
i = """jio a, +18
inc a
tpl a
@valsteen
valsteen / controlsurface.py
Created September 20, 2015 16:34
MIDI to sysex
def reply_sysex(self, message):
from array import array
try:
raw = array('B')
raw.fromstring(message.encode('utf-16-le'))
raw = raw.tolist()
raw.insert(0, 240)
raw.append(247)
self._send_midi(tuple(raw), False)