Skip to content

Instantly share code, notes, and snippets.

View winstxnhdw's full-sized avatar
⚠️
This user is a registered cybercriminal. Learn about GitHub Terms of Service.

Winston H. winstxnhdw

⚠️
This user is a registered cybercriminal. Learn about GitHub Terms of Service.
View GitHub Profile
@winstxnhdw
winstxnhdw / rank_fusion.py
Last active April 29, 2025 07:44
A performant function for fusing multiple ranked lists of documents into a single ranked list using Reciprocal Rank Fusion (RRF)
from collections.abc import Hashable, Iterable, Iterator
from itertools import chain
from numpy import argsort, dtype, float32, full, ndarray
from numpy import sum as np_sum
def rank_fusion[T: Hashable](*documents_args: Iterable[T], alpha: int = 60) -> Iterator[T]:
"""
Summary
@winstxnhdw
winstxnhdw / msgspec_discriminated_union.py
Created April 2, 2025 16:14
Discriminated tagged unions in `msgspec`.
from collections.abc import Sequence
from typing import Annotated, ClassVar, Literal
from msgspec import Meta, Struct
from uuid_utils import UUID, uuid7
from src.typedefs import Role
class Data(Struct):
@winstxnhdw
winstxnhdw / datastructures_benchmark.py
Last active April 29, 2025 19:24
A quick benchmark script for measuring creation and access times in CPython.
# ruff: noqa: T201
from collections import deque
from dataclasses import dataclass
from random import choice
from time import perf_counter_ns
from typing import Literal, NamedTuple, TypedDict
from uuid import uuid4
from msgspec import Struct
@winstxnhdw
winstxnhdw / http.py
Last active July 8, 2025 09:12
A dangerous but fast HTTP/1.1 server using socket primitives in Python, boasting a massive 7% latency improvement over Granian.
from argparse import ArgumentParser
from gc import disable
from logging import NOTSET, basicConfig, getLogger
from socket import (
AF_INET,
IPPROTO_TCP,
SO_REUSEADDR,
SOCK_STREAM,
SOL_SOCKET,
TCP_NODELAY,
@winstxnhdw
winstxnhdw / spam.sh
Last active January 29, 2024 09:33
A simple POSIX-compatible shell script to indefinitely execute short-lived functions with GNU Parallel and yes.
func() {
echo "Hello world!"
}
export -f func
yes '' | parallel -j 10 --delay 0auto func
@winstxnhdw
winstxnhdw / UnityNuGet.csproj
Created August 23, 2023 13:09
A .NET project file describing complex usage of MSBuild to extract binaries from gRPC.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PublishDir>../Assets/NuGet</PublishDir>
<TargetFramework>netstandard2.1</TargetFramework>
<UnityBuildArchitecture>win-x64</UnityBuildArchitecture>
<ProtobufClientDir>../Assets</ProtobufClientDir>
</PropertyGroup>
@winstxnhdw
winstxnhdw / sort3.py
Last active August 31, 2024 20:56
A generic typesafe in-place implementation of a sort3 algorithm in Python
from typing import Callable, Protocol
class Comparable[*T](Protocol):
"""
Summary
-------
a protocol for comparable types
"""
@winstxnhdw
winstxnhdw / quicksort.py
Last active August 31, 2024 20:57
A generic typesafe stack-based iterative in-place implementation of the Median-of-Three Quicksort algorithm in Python.
from random import sample
from typing import Callable, Protocol, TypeVar
class Comparable[*T](Protocol):
"""
Summary
-------
a protocol for comparable types
"""
@winstxnhdw
winstxnhdw / compose.yaml
Last active September 21, 2023 22:56
Docker Compose template for running Consul.NET's testing suite.
services:
consul:
container_name: consul
image: hashicorp/consul-enterprise:1.9.17-ent
network_mode: host
volumes: [./Consul.Test:/config:ro]
command: consul agent -dev -config-file config/test_config.json -log-level=error
healthcheck:
test: ['CMD-SHELL', 'curl localhost:8500/v1/status/leader']
interval: 1s
@winstxnhdw
winstxnhdw / tic_tac_toe.py
Last active August 30, 2024 17:55
An N-by-N tic-tac-toe game framework.
from enum import Enum
class Players(Enum):
"""
Summary
-------
an enum to represent the players
"""
NULL = 0