This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uintptr_t base; | |
const uintptr_t height = 100000000; | |
std::mt19937 rng; | |
[[gnu::constructor]] void init_malloc() { | |
base = (uintptr_t) sbrk(height); | |
} | |
void* malloc(size_t) { // parameter ignored, we don't need it | |
return (void*)(base + rng() % height); // odds of any collision is like, low | |
} | |
void free(void*) {} // no-op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> class enumerate { | |
T& iteratable; | |
public: | |
enumerate(T& iteratable) : iteratable(iteratable) {} | |
template<typename I> class iterator { | |
I it; | |
int i = 0; | |
public: | |
iterator(I it) : it(it) {} | |
iterator operator++() { let i = *this; operator++(0); return i; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cmath> | |
#include <cassert> | |
#include <type_traits> | |
template<typename T> int sign(T t) { | |
return t < 0 ? -1 : 1; | |
} | |
template<typename T> class range { | |
typedef typename std::make_signed<T>::type ST; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// brainf interpreter code golf | |
// collaboration by some folks on discord and myself | |
#include <stdio.h> | |
#define r(c) ;i++;goto w;case c: | |
i;t[99];s;p=1024;char b[2048];main(int j,char**a) { | |
fread(b,1,p,fopen(a[1],"r")); | |
w: switch(b[i]) { | |
r(45) b[p]-- | |
r(43) b[p]++ | |
r(60) p-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 137 char mandelbrot code golf | |
// collaboration by myself and others on a programming discord server | |
y=40,x;main(i){for(;y--;puts(""))for(x=170;x--;printf(L" .'-+=%@#"+i/12))for(typeof(0.i)z=i=0;cabs(z)<2&i++<99;z=z*z-x/50.+y/20.i+1+1i);} | |
// 130 char, lower-detail: | |
y=40,x;main(i){for(;--y;puts(""))for(x=170;x--;printf(L" *"+i/99))for(typeof(0.i)z=i=0;cabs(z)<2&i++<98;z=z*z-x/50.+y/20.i+1+1i);} | |
// compiler: gcc, may need -lm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def main(): | |
filedict = {} | |
for path, dirs, files in os.walk(sys.argv[1]): | |
for f in files: | |
full_path = os.path.join(path, f) | |
l = full_path.lower() | |
if l not in filedict: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
# Script to parse minecraft server logs and add up users' playtime. | |
# Usage: python3 playtime.py path/to/logs | |
# | |
# Rifkin 2020 | |
import datetime | |
import gzip | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a program to filter photos with ifunny watermarks. | |
# I wrote this script for personal use to separate saved ifunny memes from other photos on my phone. | |
# The script is fully parallelized and is able to make good use of technologies like Intel | |
# hyperthreading because substantial program time is spent in IO. Bottleneck will be IO. | |
# | |
# Watermark false positive rate appears to be < 1/500 | |
# Watermark false negative rate appears to be ~ 1/500 | |
# False positive / negative rate checked with manual spot check sample size = 500. | |
# | |
# Rifkin 2020 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import shutil | |
import sys | |
import random | |
def pick_random(src, dest, N): | |
all_files = [] | |
for path, dirs, files in os.walk(src): | |
for f in files: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# definition recursive ackermann | |
def A(m, n): | |
if m == 0: | |
return n + 1 | |
elif n == 0: | |
return A(m - 1, 1) | |
else: | |
return A(m - 1, A(m, n - 1)) | |
# non-recursive ackermann |