Skip to content

Instantly share code, notes, and snippets.

View tkoz0's full-sized avatar

TKoz[0] tkoz0

View GitHub Profile
@tkoz0
tkoz0 / cppcustomoperator.cpp
Created April 11, 2024 00:36
custom operator in c++/cpp not recommended
#define define const struct
#define operator(ReturnType, OperatorName, FirstOperandType, SecondOperandType) OperatorName ## _ {} OperatorName; template <typename T> struct OperatorName ## Proxy{public:OperatorName ## Proxy(const T& t) : t_(t){}const T& t_;static ReturnType _ ## OperatorName ## _(const FirstOperandType a, const SecondOperandType b);};template <typename T> OperatorName ## Proxy<T> operator<(const T& lhs, const OperatorName ## _& rhs){return OperatorName ## Proxy<T>(lhs);}ReturnType operator>(const OperatorName ## Proxy<FirstOperandType>& lhs, const SecondOperandType& rhs){return OperatorName ## Proxy<FirstOperandType>::_ ## OperatorName ## _(lhs.t_, rhs);}template <typename T> inline ReturnType OperatorName ## Proxy<T>::_ ## OperatorName ## _(const FirstOperandType a, const SecondOperandType b)
define operator(int, foo, int, int) {
return a + b;
}
#define foo <foo>
int main() {
@tkoz0
tkoz0 / yt-dlp.txt
Created March 23, 2024 15:09
yt-dlp notes common helpful options cheat sheet
YT-DLP helpful options cheat sheet
basics:
--version
-U,--update
-i,--ignore-errors
--flat-playlist (list videos, no download)
video selection:
--datebefore YYYYMMDD
@tkoz0
tkoz0 / NBT.txt
Created September 2, 2023 08:54
nbt format stuff relevant to minecraft
Named Binary Tag specification
NBT (Named Binary Tag) is a tag based binary format designed to carry large amounts of binary data with smaller amounts of additional data.
An NBT file consists of a single GZIPped Named Tag of type TAG_Compound.
A Named Tag has the following format:
byte tagType
TAG_String name
[payload]
@tkoz0
tkoz0 / modmersenne.c
Last active July 9, 2023 01:05
64 bit number modulo mersenne number (M61, 2^61-1) compiles with no multiplication or division with gcc 9.4 -O3
#include <stdint.h>
#define MP(p) ((1uLL << p) - 1)
uint64_t mod_m61(uint64_t a)
{
uint64_t tmp = (a & MP(61)) + (a >> 61);
if (tmp >= MP(61))
tmp -= MP(61);
return tmp;
@tkoz0
tkoz0 / mul64.c
Last active July 9, 2023 01:02
64 bit multiply with 128 bit result, compiles to native amd64 x86_64 instruction with gcc 9.4 -O3
typedef struct { uint64_t lo, hi; } mul64_t;
mul64_t mul64(uint64_t a, uint64_t b)
{
mul64_t ret;
__uint128_t c = (__uint128_t) a * (__uint128_t) b;
ret.hi = c >> 64;
ret.lo = c;
return ret;
@tkoz0
tkoz0 / bw.py
Created July 6, 2023 05:57
dumb script for optimizing $bw $boostwish rolls on mudae bot
rolls = 38
wpbase = 150 # wish percent boost
def wp(r):
ret = 0
if r > 15:
ret += 10*(r-15)
r = 15
if r > 5:
ret += 15*(r-5)
r = 5
@tkoz0
tkoz0 / tu_matrix.hpp
Created June 28, 2023 20:48
bit packing scheme for matrices or 0,1,-1 with detection for operations that show it is not TU (totally unimodular)
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <cstring>
// represents a totally unimodular matrix packing each number into 2 bits
// includes checking that operations never result in values other than -1,0,1
class TUMatrix
{
private:
@tkoz0
tkoz0 / foriio.txt
Last active September 22, 2023 14:06
notes for saving files from websites (includes: twitter)
open all the art images in new tabs
1. use developer menu to search ".jpg" and find the first image of importance to get the class name
2. paste this into the developer console (using the class name found)
[].slice.call(document.getElementsByClassName('WorkImage__StyledImage-gl8mvm-1')).forEach(a => window.open(a.src,'_blank'))
@tkoz0
tkoz0 / p1.py
Created June 24, 2023 21:07
scripts to test reading y-cruncher digit .ycd files
import sys
DIGITS = int(sys.argv[1])
assert DIGITS > 0 and DIGITS <= 6
outfile = open(sys.argv[2],'w')
# use sliding window of digits
offset = 1
window = sys.stdin.read(DIGITS)
assert len(window) == DIGITS
@tkoz0
tkoz0 / powersum.py
Created June 13, 2023 22:28
generate power sum formulas sequentially in exact rational arithmetic
from fractions import Fraction as Frac
import math
# each is a single variable polynomial
# list of fractions for x^0,x^1,x^2,... terms
# length must be >= 1, zero polynomial is a list containing only 0
# index p represents power sum with exponent p
formulas: list[list[Frac]] = []
formulas.append([Frac(0),Frac(1)]) # p = 0
#formulas.append([Frac(0),Frac(1,2),Frac(1,2)]) # p = 1