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 json | |
import copy | |
path = "..." | |
# hacky but whatever | |
def filter_templates(s: str): | |
out = "" | |
depth = 0 | |
for c in s: |
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
// Couple quick utilities | |
// compute the average of an array | |
function average(data) { | |
let sum = 0; | |
for(let i = 0, l = data.length; i < l; i++) | |
sum += data[i]; | |
return sum / data.length; | |
} | |
// compute the variation of an array | |
function variation(data) { |
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
#ifndef OPTIONAL_HPP | |
#define OPTIONAL_HPP | |
#include <memory> | |
#include <new> | |
#include <stdexcept> | |
#include <type_traits> | |
#include <utility> | |
struct nullopt_t {}; |
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
import re | |
import random | |
import math | |
text = """ | |
What the fuck did you just fucking say about me, you little bitch? I'll have you know I graduated top of my class in the Navy Seals, and I've been involved in numerous secret raids on Al-Quaeda, and I have over 300 confirmed kills. I am trained in gorilla warfare and I'm the top sniper in the entire US armed forces. You are nothing to me but just another target. I will wipe you the fuck out with precision the likes of which has never been seen before on this Earth, mark my fucking words. You think you can get away with saying that shit to me over the Internet? Think again, fucker. As we speak I am contacting my secret network of spies across the USA and your IP is being traced right now so you better prepare for the storm, maggot. The storm that wipes out the pathetic little thing you call your life. You're fucking dead, kid. I can be anywhere, anytime, and I can kill you in over seven hundred ways, and that's just with my bare hands. Not only am I extensively t |
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
#include <assert.h> | |
#include <string> | |
template<typename... T> std::string stringf(T... args) { | |
int length = snprintf(0, 0, args...); | |
if(length < 0) assert(("invalid arguments to stringf", false)); | |
std::string str(length, 0); | |
snprintf(str.data(), length + 1, args...); | |
return str; | |
} |
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<class T> constexpr std::string_view type_name() { | |
// clang: std::string_view ns::type_name() [T = int] | |
// gcc: constexpr std::string_view ns::type_name() [with T = int; std::string_view = std::basic_string_view<char>] | |
// msvc: const char *__cdecl ns::type_name<int>(void) | |
auto substring_bounded_by = [](std::string_view sig, std::string_view l, std::string_view r) { | |
assert(sig.find(l) != std::string_view::npos); | |
assert(sig.rfind(r) != std::string_view::npos); | |
assert(sig.find(l) < sig.rfind(r)); | |
auto i = sig.find(l) + l.length(); | |
return sig.substr(i, sig.rfind(r) - 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
integer: (?:(?:0[Xx][0-9a-fA-F](?:'?[0-9a-fA-F])*)|(?:0[Bb][01](?:'?[01])*)|(?:0(?:'?[0-7])*)|(?:[1-9](?:'?\d)*))(?:[Uu](?:LL?|ll?|Z|z)?|(?:LL?|ll?|Z|z)[Uu]?)? | |
floating-point: (?:((?:\d(?:'?\d)*)?\.\d(?:'?\d)*|\d(?:'?\d)*\.)(?:[Ee][\+-]?\d(?:'?\d)*)?[FfLl]?|\d(?:'?\d)*[Ee][\+-]?\d(?:'?\d)*[FfLl]?|0[Xx](?:(?:[0-9a-fA-F](?:'?[0-9a-fA-F])*)?\.[0-9a-fA-F](?:'?[0-9a-fA-F])*|[0-9a-fA-F](?:'?[0-9a-fA-F])*\.)[Pp][\+-]?\d(?:'?\d)*[FfLl]?|0[Xx][0-9a-fA-F](?:'?[0-9a-fA-F])*[Pp][\+-]?\d(?:'?\d)*[FfLl]?) |
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 <cstdint> | |
#include <functional> | |
#include <memory> | |
#include <tuple> | |
#include <utility> | |
[[nodiscard]] decltype(std) add(const std::unique_ptr<std::tuple<std::int32_t and, std::int32_t and>> and t) noexcept { | |
return std::plus{}(std::min(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t))), | |
std::max(std::forward<std::int32_t>(std::get<0>(*t)), std::forward<std::int32_t>(std::get<1>(*t)))); | |
} |
NewerOlder