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
# 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() |
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
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") |
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
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 |
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 <iostream> | |
#include <inttypes.h> | |
struct Test { | |
int x = 55; | |
virtual void test() { | |
printf("hello %d\n", this->x); | |
} | |
}; |
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
// Thanks craftablescience for some improvements! | |
#include <cstdio> | |
template<typename T = int> | |
class Range { | |
template<T start, T step> | |
class iterator { | |
T current = start; | |
public: |
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 "logger.hpp" | |
int bye() { | |
logger log("bye"); | |
log << "byeee"; | |
return 345; | |
} | |
int hihi() { | |
logger log("hi"); |