Skip to content

Instantly share code, notes, and snippets.

View darvil82's full-sized avatar
:fishsticks:
<- food

darvil darvil82

:fishsticks:
<- food
  • Spain
  • 08:20 (UTC +02:00)
View GitHub Profile
@darvil82
darvil82 / main.cpp
Last active September 29, 2023 18:58
Stupid logger thingamabob
#include "logger.hpp"
int bye() {
logger log("bye");
log << "byeee";
return 345;
}
int hihi() {
logger log("hi");
@darvil82
darvil82 / Menu.java
Last active March 22, 2023 15:29
A class for making menus a bit less tiresome.
import java.util.ArrayList;
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/** Class for making menus less tiresome. */
public class Menu {
public record MenuOption(int index, String info, Runnable func) { }
@darvil82
darvil82 / constexpr_range.cpp
Last active January 12, 2023 13:11
A shitty constexpr range thing in C++20
// Thanks craftablescience for some improvements!
#include <cstdio>
template<typename T = int>
class Range {
template<T start, T step>
class iterator {
T current = start;
public:
@darvil82
darvil82 / fun_with_.cpp
Last active March 29, 2024 02:48
funny c++
#include <iostream>
#include <inttypes.h>
struct Test {
int x = 55;
virtual void test() {
printf("hello %d\n", this->x);
}
};
@darvil82
darvil82 / event_handler.py
Last active December 17, 2022 15:13
C# style event handler
from typing import Callable, Generic, TypeVar
T = TypeVar("T")
class EventHandler(Generic[T]):
callbacks: list [Callable[[T], None]] = []
def __iadd__(self, callback: Callable[[T], None]):
self.callbacks.append(callback)
return self
@darvil82
darvil82 / british_python.py
Created July 25, 2022 18:59
British python
class BritishNaming(type):
def __new__(mcs, *args):
cls = super().__new__(mcs, *args)
cls.__init__ = cls.__innit__
return cls
class MyBritishClass(metaclass=BritishNaming):
def __innit__(self):
print("I am british now ig")
@darvil82
darvil82 / entry_point.py
Last active July 26, 2022 15:50
Finally non cringe entry points!
# utils.py
from sys import argv
from typing import Any, Callable
def entry_point(
func: Callable[[list[str]], Any] | Callable[[], Any]
) -> Callable[[], Any]:
new_func = lambda: func(argv) if func.__code__.co_argcount == 1 else func() # type: ignore
if func.__module__ == "__main__":
new_func()
@darvil82
darvil82 / python-decorators.md
Last active July 25, 2022 15:27
A very simple explanation about how python decorators work.

Small explanation about how decorators work.

Lets say decorator has this definition:

def decorator(func: Callable[[], Any]) -> Callable[[], Any]:
  def wrapper():
    ...
    func()
    ...