Skip to content

Instantly share code, notes, and snippets.

View jeremy-rifkin's full-sized avatar
🐉

Jeremy Rifkin jeremy-rifkin

🐉
View GitHub Profile
int x;
#pragma once
#include <stdio.h>
#pragma once
@jeremy-rifkin
jeremy-rifkin / test.hpp
Last active August 25, 2024 21:48
test
#pragma once
@jeremy-rifkin
jeremy-rifkin / ftime-trace-aggregator.py
Last active March 13, 2024 04:49
very hacky -ftime-trace aggreggator, aggregating by instantiation time
import json
import copy
path = "..."
# hacky but whatever
def filter_templates(s: str):
out = ""
depth = 0
for c in s:
@jeremy-rifkin
jeremy-rifkin / optional.hpp
Created September 16, 2023 18:31
C++11 optional implementation
#ifndef OPTIONAL_HPP
#define OPTIONAL_HPP
#include <memory>
#include <new>
#include <stdexcept>
#include <type_traits>
#include <utility>
struct nullopt_t {};
@jeremy-rifkin
jeremy-rifkin / discord-ansi.py
Created September 16, 2022 15:12
Turns a copypasta into something ridiculous for discord
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
@jeremy-rifkin
jeremy-rifkin / typename.hpp
Created September 8, 2021 03:05
Short utility to get the name of a type in C++
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);
@jeremy-rifkin
jeremy-rifkin / c++numbers.re
Created August 27, 2021 03:33
regular expressions for c++ numeric literals
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]?)
@jeremy-rifkin
jeremy-rifkin / add.cpp
Last active August 8, 2021 02:33
Very simple idiomatic C++ program to add two numbers together
#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))));
}
@jeremy-rifkin
jeremy-rifkin / pi.c
Created July 21, 2021 21:03
A program to print pi which has *absolutely no* UB whatsoever
#include <stdio.h>
#include <math.h>
char s[100000];
prime(p,r,i,m,e) {
for(e=sizeof(s),r=e/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2/2*2; r<e>>1; r++)
for(i=r+r-r+r; i<e; i+=r)
s[+i]++;
for(m=(m=2,p=p^m,m=p^m,p=p^m,m); m+m+m+m; p++)
!s[p]&&m--;
return--p;