This file contains hidden or 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
def typecheck( | |
func=None, | |
*, | |
check_return=False, | |
): | |
""" | |
Perform a runtime type check of the function arguments and (optionally) its | |
return type. | |
All annotated arguments and keyword arguments will be typechecked. Known |
This file contains hidden or 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
#ifndef UT_ASSERT_ | |
#define UT_ASSERT_ | |
/** Usage: | |
* std >= C++20 (C++23) | |
* | |
* UT_ASSUME(cond) | |
* Low level primitive. Invokes undefined behaviour if `cond` is false. | |
* Uses [[assume]] if available. Compiler extensions otherwise. | |
* | |
* ut::unreachable() |
This file contains hidden or 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
#ifndef UT_TRIM | |
#define UT_TRIM | |
/** Usage: | |
* std >= C++20 | |
* Simple string_stream trimming (trims whitespace by default) | |
* | |
* #include <iostream> | |
* | |
* int main() { |
This file contains hidden or 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
# Extract speaker notes (with related headings) from a pandoc markdown document | |
# Produces valid markdown which can be compiled with pandoc | |
# Headings are also separated by hrules | |
# Example usage: | |
# awk -f get_notes.awk your_source.md | pandoc -f markdown -o your_notes.pdf | |
## Find the closing div for the notes |
This file contains hidden or 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
#ifndef UT_PAIR_HPP | |
#define UT_PAIR_HPP | |
// A std::pair replacement with no implicit (or any!) constructors. | |
// All conversions are done through either member functions or static functions | |
// Also you can use it in a range-based-for loop if the types of `first` and `second` are the same | |
/**Usage: | |
* | |
* int main() { |
This file contains hidden or 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
#ifndef UT_REALLOC_UNIQUE_PTR_HPP | |
#define UT_REALLOC_UNIQUE_PTR_HPP | |
#include <memory> | |
#include <utility> | |
/**Usage: | |
* std >= c++17 | |
* | |
* #include "realloc_unique_ptr.hpp" | |
* #include <cstdio> |
This file contains hidden or 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
#ifndef UT_SV_TO_NUM_HPP | |
#define UT_SV_TO_NUM_HPP | |
#include <charconv> | |
#include <concepts> | |
#include <optional> | |
#include <string_view> | |
/** Usage: | |
* int main() { | |
* for (std::string_view sv : {"123", "12.3", "12e3", "abc"}) { |
This file contains hidden or 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
#ifndef UT_PACK_LOOPS_HPP | |
#define UT_PACK_LOOPS_HPP | |
/* Usage: | |
* std >= c++17 | |
* | |
* XXX: **DO NOT RETURN FROM UT_PACK_FOR** it uses a lambda so you would only return from that lambda. | |
* If you do want to break the loop, use UT_PACK_BREAK instead of returning. | |
* | |
* template<std::size_t... sizes> |
This file contains hidden or 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
# When given a conf file, will look for key "[key]" and print the non-blank, | |
# lines until the next key or until the end of the file. | |
# | |
# All comments are removed as well as leading and trailing spaces | |
# | |
# Expects an input variable 'key' (can be passed using `awk -v key="your key here"`) | |
# | |
# | |
# Example: | |
# |
This file contains hidden or 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
#ifndef UT_DEFER_HPP | |
#define UT_DEFER_HPP | |
/* Usage: | |
* std >= c++17 | |
* | |
* Provides the `UT_DEFER` macro, which acts similarly to `defer` in Zig and `scope` in D. | |
* | |
* If `UT_DEFER_NO_PREFIX` is defined, `defer` can be used instead of `UT_DEFER`. | |
* |