override BIN := test | |
override SRC := test.c msg.c | |
override OBJ := $(SRC:%=%.o) | |
override DEP := $(SRC:%=%.d) | |
CFLAGS := -O2 -march=native -mtune=native -flto | |
$(BIN): $(OBJ) | |
$(CC) $(CFLAGS) -o $@ $^ |
#include <errno.h> | |
#include <stdio.h> | |
// We want a function that creates a couple files. Here's the naive approach: | |
int hardcoded_cleanup(const char *path1, const char *path2) { | |
FILE *file1 = fopen(path1, "w"); | |
if (file1 == NULL) { | |
return errno; | |
} |
C++20 takes yet another swing at its infamous initialization rules. The players involved this time are Aggregate initialization (type a{1, 2, 3}
) and direct initialization (type a(1, 2, 3)
). A common pitfall with aggregate init is:
std::vector<int> vec0(5, 9); // 9, 9, 9, 9, 9
std::vector<int> vec1{5, 9}; // 5, 9
So if you don't know what you're doing, {}
is potentially dangerous to use with types that might have both "real" constructors and such with std::initializer_list
. If you had your head in the sand for 10 11 years and always used ()
then you never were in danger.
Daniel Lemire https://lemire.me/en/
Experimental vs asymptotic software engineering, Ullman's essay
Denis' Book
# Clear all Android packages and user data via ADB, by @noseratio | |
# Run: powershell -f adb-clear-packages.ps1 | |
# To get ADB: https://community.chocolatey.org/packages/adb | |
# | |
# Q: Why not a factory reset? | |
# A: https://www.reddit.com/r/Android/comments/naetg8/a_quick_powershell_script_for_clearing_user_data/gxtaswl?context=3 | |
$confirmation = Read-Host "This will clear all packages data and user files. Are you sure you want to proceed? (y|n)" | |
if ($confirmation -ne 'y') { | |
return |
#include <array> | |
#include <iostream> | |
template<typename ...Args> | |
constexpr std::size_t ARG_SIZE() { return sizeof...(Args) + 1; } | |
template<typename From, typename To> | |
concept SameAs = std::is_same_v<From, To>; | |
template<std::size_t N, typename T, SameAs<T>... Ts> |
// x64 encoding | |
enum Reg { | |
RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, | |
R8, R9, R10, R11, R12, R13, R14, R15, | |
}; | |
enum XmmReg { | |
XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7, | |
XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, |
For the every-day programmer who needs to get shit done instead of fighting type errors.
If your application deals with times in any meaningful way, you should probably want to actually store time_points and durations and what-not; chrono has a pretty rich vocabulary for talking about time-related concepts using the type system. However, sometimes you just need to do something simple, like timing how long something takes, which is where chrono becomes overly complex, hence this cheat sheet.
All examples will assume #include <chrono>
.