Skip to content

Instantly share code, notes, and snippets.

View arseniiv's full-sized avatar
🌜

Arsenii A. arseniiv

🌜
View GitHub Profile
@arseniiv
arseniiv / README.md
Last active February 23, 2016 09:05
Performance test for different implementations of `letter`

On my computer, results are as follows (several runs):

Implementation 1: 0.51096861 s
Implementation 2: 0.08305151000000001 s

Implementation 1: 0.49112112700000005 s
Implementation 2: 0.06993395000000001 s

Implementation 1: 0.5380552780000001 s

Implementation 2: 0.083535994 s

import ceylon.collection {
ArrayList,
Stack
}
shared abstract class ComplexTrampoline<Type>()
of ComplexReturn<Type> | ComplexCall<Type> {
shared formal Type result;
}
@arseniiv
arseniiv / README.md
Last active February 28, 2021 20:55
(The great) snail evaluation campaign, fixed once

(The great) snail evaluation campaign

Behold!

Then write a snail strategy and evaluate it for good measure. We need more of actually competent ones.

Okay, I don’t currently have any plans for maintaining this so just take it and may it make your day more interesting.

This uses Python 3, the latest. You can downport it if you want!

@arseniiv
arseniiv / lazy_var.py
Created March 2, 2021 21:38
Lazy variables in Python 3 (static types included)
"""
Lazy wrappers: `Lazy` and `LazyMut`.
In case you have a class with many lazy fields, consider
using `functools.cached_property` for each of them implemented as methods.
That will free you from writing `val` everywhere, and make the code clearer.
"""
from __future__ import annotations
from typing import Callable, TypeVar, Generic
@arseniiv
arseniiv / integer_fit.py
Last active November 28, 2022 16:12
Multiplying a list of floats by the best number to fit to integers
from dataclasses import dataclass
from typing import Sequence
import numpy as np
@dataclass
class Fit:
error: float
multiplier: float
result: tuple[int, ...]
"""
sfzdefiner.py
a tool to dump all contents of files linked to
specified SFZ file(s) into self-contained results;
replaces variables with values too
basic usage: (python3 | py) sfzdefiner.py (source-file-name)+
usage help: (python3 | py) sfzdefiner.py --help
@arseniiv
arseniiv / replacenotes.py
Created October 3, 2023 18:59
replacenotes.py
'''
Replaces notes with flats with enharmonic sharps in SFZ and DSPRESET files.
'''
from pathlib import Path
from typing import Final
import re
DS_EXTS: Final = frozenset(['.dspreset'])
SFZ_EXTS: Final = frozenset(['.sfz'])
@arseniiv
arseniiv / scale_approx.py
Created December 23, 2023 19:43
Approximate a scale with a periodic scale with specific step pattern
"""
Fitting a scale to have a given pattern of steps between notes.
Install `sympy` and `more_itertools`.
"""
from typing import Sequence
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
@arseniiv
arseniiv / edo_confluence.py
Created December 27, 2023 18:59
List intervals in various edo/edX scales that are close to each other
from collections import defaultdict
from dataclasses import dataclass
from fractions import Fraction
from itertools import pairwise
from typing import Final, Sequence
@dataclass
class EdIntervals:
ed_fractions: list[Fraction]
sources: dict[Fraction, list[int]]
@arseniiv
arseniiv / subdivide_scale_best.py
Created February 18, 2024 23:25
Sorting subdivided scales by avg variety, filtering out rotated variants
from __future__ import annotations
from collections import defaultdict
from typing import Final, Iterable, Iterator, Mapping, Sequence
import operator
from dataclasses import dataclass
from itertools import accumulate, permutations, product
from math import prod
from fractions import Fraction as F
def avg_variety(scale_steps: Sequence[F]) -> float: