Skip to content

Instantly share code, notes, and snippets.

@jemand2001
jemand2001 / Base.java
Created February 27, 2021 16:57
PseudoFinal methods (at runtime) (in java) (i hate myself for this)
package sprachen.notfinal;
public abstract class Base {
@PseudoFinal
void f() {
System.out.println("base class");
}
}
@jemand2001
jemand2001 / bench.py
Created March 22, 2021 19:44
different python loops benchmark
try:
import numpy
except ImportError:
# pypy
pass
to_run = []
def run(f):
fx = lambda: f(100_000)
fx.__name__ = f.__name__
@jemand2001
jemand2001 / range.hpp
Last active May 16, 2023 23:32
c++ range
namespace range {
class range {
int start = 0;
int step = 1;
int stop;
struct range_iterator {
int current;
bool operator != (range_iterator b) const {
return (start != b.start && stop != b.stop && step != b.step) || current < b.current;
}
@jemand2001
jemand2001 / ConditionalList.hs
Last active July 22, 2023 11:26
in-line include or exclude elements in a list depending on a condition
module ConditionalList where
-- largely curtesy of citrusMarmelade
import Control.Monad
import Data.Monoid
if_ :: Applicative f => f () -> Bool -> f ()
if_ = flip when
type Append a = Endo [a]
@jemand2001
jemand2001 / menu.html
Last active August 19, 2023 20:30
radial menu in html
<style>
button {
--size: 75px;
width: var(--size);
height: var(--size);
border-radius: calc(var(--size) / 2);
border: var(--color) 1px solid;
}
#main {
position: absolute;
@jemand2001
jemand2001 / threadpool.cpp
Created September 3, 2023 10:20
maybe a correct threadpool implementation in c++
#include <algorithm>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>
struct threadpool {
std::vector<std::jthread> threads;
@jemand2001
jemand2001 / expected_coro.cpp
Last active September 14, 2023 16:02
monadic std::expected using coroutines
#include <coroutine>
#include <expected>
#include <optional>
#include <iostream>
#include "return_object_holder.hpp"
using std::coroutine_traits;
template <typename R, typename E>
@jemand2001
jemand2001 / memory.cpp
Last active September 14, 2023 16:03
rudimentary shared_ptr implementation
#include <atomic>
#include <concepts>
#include <iostream>
#include <stdexcept>
#include <vector>
template <typename T>
class Badge {
friend T;
Badge() = default;
@jemand2001
jemand2001 / lazy.cpp
Last active September 14, 2023 16:04
lazy loading of data using initializer and a function to get the actual value
#include <variant>
#include <functional>
#include <iostream>
template <typename Info, typename Actual>
class Lazy {
struct info_holder {
Info x;
};
@jemand2001
jemand2001 / logging.hpp
Created August 6, 2023 19:45
tiny logging function (colors, source location, no macros)
#include <format>
#include <iostream>
#include <source_location>
#include <string_view>
#include <tuple>
#include <unordered_map>
enum class LogLevel { DEBUG, INFO, WARNING, ERROR, CRITICAL };
namespace CLIColors {