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 <coroutine> | |
#include <format> | |
#include <deque> | |
#include <optional> | |
using namespace std; | |
deque<coroutine_handle<>> queue; | |
template<class T> |
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
# requires Python 3.9+ for unparse() | |
import ast | |
from typing import cast | |
class MyTransformer(ast.NodeTransformer): | |
def visit_Subscript(self, node: ast.Subscript) -> ast.AST: | |
result = node | |
name = cast(ast.Name, node.value) |
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 __future__ import annotations | |
from inspect import getattr_static, isclass | |
from typing import Callable, Generic, Iterable, List, TypeVar, overload | |
TSource_co = TypeVar('TSource_co', covariant=True) | |
TResult = TypeVar('TResult') | |
class Enumerable(Generic[TSource_co]): | |
def __init__(self, iter_: Iterable[TSource_co]) -> None: | |
super().__init__() |
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 <string> | |
#include <variant> | |
#include <tuple> | |
// https://gist.github.com/cleoold/df31c3789f2b2b8fe2cfa5022957ee06 | |
#include "lambda_traits.hpp" | |
template<class T> | |
struct decay_maybe { using type = T; }; |
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
/** | |
* Binary string and bitwise arithmetic entirely in TypeScript's type system | |
* (with template string types). | |
* | |
* Requires version >= 4.1.0 | |
* | |
* Hover on the types to see the results. | |
*/ | |
type A = '010101' |
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
// c++17 | |
#pragma once | |
#include <tuple> | |
#include <utility> | |
namespace detail { | |
template<class T, class F, size_t ...N> | |
auto constexpr tuple_map_impl(const T &t, F &&f, std::index_sequence<N...>) { | |
return std::make_tuple(std::forward<F>(f)(std::get<N>(t))...); |
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
// implements ultra simple mypromise | |
type Nullable<T> = T | null; | |
function defaultReject(err: any) { | |
throw Error(`uncaught promise rejection: ${err}`); | |
} | |
class MyPromise<T> { |
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
// g++ test.cpp -lpthread -llua5.3 -Wall | |
#include <array> | |
#include <atomic> | |
#include <chrono> | |
#include <future> | |
#include <iostream> | |
#include "lua.hpp" | |
namespace { |
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
// match case for c++11 | |
// avoids nested brackets as in std::conditional | |
template<bool Cond, class Tp> | |
struct Case {}; | |
template<class ...Cases> | |
struct Match; | |
template<class Case_1, class ...Cases> |
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
#pragma once | |
// source: Scott Meyers - Effective Modern C++-O'Reilly item 37 | |
// compile flag: -lpthread -Wall -std=c++20 | |
#include <thread> | |
#include <type_traits> | |
// RAII managed thread class | |
class thread_raii { | |
public: |
NewerOlder