Skip to content

Instantly share code, notes, and snippets.

View voronaam's full-sized avatar

Lex Vorona voronaam

View GitHub Profile
@voronaam
voronaam / balancemodel.py
Last active March 5, 2024 05:17
Model for an unbalanced game
#!/usr/bin/env python3
import argparse
import random
LADDER_PLAYERS = 1000
LADDER_GAMES = 1000000
TOURNAMENTS = 20
def win_probability(race1, race2, imbalance, rematch):
@voronaam
voronaam / example.rs
Created April 27, 2022 21:28
Poor man's specialization in Rust
macro_rules! assert_impls {(
#[rustc_on_unimplemented(message = $message:expr $(,)?)]
$T:ty : $($trait:tt)+
) => (const _: () = {
#[allow(unused)]
use __poormans_specialization::Fallback as _;
mod __poormans_specialization {
pub(super)
struct Wrapper<T : ?::core::marker::Sized>(T);
@voronaam
voronaam / mousewarp.py
Created June 9, 2021 16:48
Python script to warp the mouse comfortable around adges of a vertical display
#!/usr/bin/env python3
from Xlib import display
from time import sleep
from os import system
# My screen setup has a vertical display with a large dead zone:
#
# +----------------+
# | |
# DEAD | |
@voronaam
voronaam / background.go
Last active December 3, 2019 00:31
Benthos background processor
package processor
import (
"fmt"
"time"
"github.com/Jeffail/benthos/v3/lib/log"
"github.com/Jeffail/benthos/v3/lib/metrics"
"github.com/Jeffail/benthos/v3/lib/processor"
"github.com/Jeffail/benthos/v3/lib/types"
package org.sample;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
@voronaam
voronaam / nhl-rank.py
Last active April 26, 2020 19:55
An utility to rank games by a team in a certain year without revealing the game results.
#!/usr/bin/env python3
"""nhl-rank.py: An utility to rank games by a team in a certain year without revealing the results.
The data source and its copyright: https://sportsdatabase.com/
"""
__author__ = "Lex Vorona"
import sys, getopt
@voronaam
voronaam / MyBenchmark.java
Last active July 6, 2016 22:04
JMHing difference between chained and unchained calls
package org.sample;
/**
* Results:
* Benchmark Mode Cnt Score Error Units
* MyBenchmark.testChain avgt 200 0.019 ± 0.001 us/op
* MyBenchmark.testNoChain avgt 200 0.019 ± 0.001 us/op
*/
import org.openjdk.jmh.annotations.Benchmark;
@voronaam
voronaam / SaveObjectToFile.java
Created December 4, 2015 23:09
A quick implementation of the object dump query for Eclipse Memory Analizer (MAT)
package org.eclipse.mat.ui.snapshot.actions;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashSet;
@voronaam
voronaam / FindBenchmark.java
Created March 5, 2015 22:30
OlognBenchmark
package com.test;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
/**
* This is a benchmark to gauge if there is any performance hit into using Option.apply() in Scala.
* Use JMH to build it: http://blog.vorona.ca/measuring-scala-performance-with-jmh.html
*/
package org.sample
import org.openjdk.jmh.annotations._
import java.util.concurrent.TimeUnit