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 / 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 / property.hpp
Created March 10, 2021 12:26
C++ properties
#ifndef PROPERTY_PROPERTY_HPP
#define PROPERTY_PROPERTY_HPP
#include <functional>
template <typename T>
struct Property {
using setter_type = std::function<void(Property<T>&, T)>;
using getter_type = std::function<T *(Property<T>&)>;
typedef T element_type;
typedef T *pointer_type;
@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 / 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 / components.cpp
Last active September 16, 2023 23:16
tree-like structures between classes through template inheritance
#include <iostream>
#include <memory>
#include <ranges>
#include <source_location>
#include <vector>
#include "traits.hpp"
class Scene;
class Entity;
@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 / bindings.hpp
Last active May 5, 2025 09:21
late binding dynamic libraries
#include <dlfcn.h>
#include <format>
#include <memory>
#include <stdexcept>
#include <unordered_map>
struct dl_exception : std::runtime_error {
using std::runtime_error::runtime_error;
};
@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 {
@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>