Skip to content

Instantly share code, notes, and snippets.

View tkoz0's full-sized avatar

TKoz tkoz0

View GitHub Profile
@tkoz0
tkoz0 / multi_json.py
Created January 29, 2025 10:36
reading multiple json objects from a string
import json
def multi_json(s:str):
d = json.JSONDecoder()
i = 0
while i < len(s):
if s[i] in ' \t\n':
i += 1
else:
obj,i = d.raw_decode(s,i)
@tkoz0
tkoz0 / ansiesc.py
Created January 18, 2025 12:35
improved ansi escape codes for terminal color and text formatting
'''
basic utils for ansi escape codes in terminal
- foreground color
- background color
- font styles
- 8 bit color
- 24 bit rgb color
- cursor movement
- screen clearing
- scrolling
@tkoz0
tkoz0 / ansiesc.py
Created January 17, 2025 09:50
ansi escape codes for terminal color and other stuff
class _escm:
'''
internal class for ansi escape codes
only supports the 'm' command for text color/format
support concatenations with each other
support concatenations with strings
'''
def __init__(self, *l: int|list[int]):
self.l: list[int] = []
for n in l:
@tkoz0
tkoz0 / rsa.txt
Created November 1, 2024 05:11
rsa factoring challenge numbers semiprimes (taken from wikipedia)
RSA-100 = 1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139
RSA-100 = 37975227936943673922808872755445627854565536638199
× 40094690950920881030683735292761468389214899724061
RSA-110 = 35794234179725868774991807832568455403003778024228226193532908190484670252364677411513516111204504060317568667
RSA-110 = 6122421090493547576937037317561418841225758554253106999
× 5846418214406154678836553182979162384198610505601062333
@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