Skip to content

Instantly share code, notes, and snippets.

@Len42
Len42 / pre-push
Last active March 24, 2024 18:28
git pre-push script to mirror pushed files to another directory
#!/bin/bash
# git pre-push script to mirror pushed files to another directory
destdir=/mirror-dir
if [ `git branch --show-current` != "main" ]; then
echo "pre-push: Not on main branch - skipping"
else
echo "pre-push: Mirroring to $destdir"
(git diff @{push} @ --diff-filter=ACMR --name-only | while read file; do
echo "pre-push: Copying $file"
install -D "$file" "$destdir/$file"
@Len42
Len42 / CmdLine.h
Created October 1, 2023 00:12
C++ command line processing class
#pragma once
#include <string>
#include <string_view>
#include <charconv>
#include <vector>
#include <span>
#include <ranges>
#include <concepts>
#include <type_traits>
@Len42
Len42 / ShowDecl.cpp
Created May 22, 2023 19:06
ShowDecl: Pretty-print an expression's decltype (C++)
// ShowDecl: Pretty-print an expression's decltype.
// Works with popular C++20 compilers.
// by Len Popp
// ref: Arthur O'Dwyer https://quuxplusone.github.io/blog/2018/08/22/puts-pretty-function/
#include <string>
#include <string_view>
#include <utility>
#include <iostream>
@Len42
Len42 / CMakeLists.snippet
Last active January 28, 2023 21:31
MakeVersionInfo - Update a project's version based on the latest git tag (CMake & Python)
# Insert this in your CMakeLists.txt file, after add_executable():
# Update version info file from the latest git tag
set(VERSION_FILE "version.h") # CHANGE to whatever you want
target_sources(MyExecutableName PRIVATE ${VERSION_FILE}) # CHANGE MyExecutableName
set(CMD_PYTHON "py") # for Windows - CHANGE if necessary
#set(CMD_PYTHON "/usr/local/bin/python3.11") # for macOS, Linux
set(VERSION_TEMP_FILE "${PROJECT_BINARY_DIR}/version-temp")
set(VERSION_INFO_FILE "${PROJECT_BINARY_DIR}/version-info")
add_custom_target(MakeVersionFile
@Len42
Len42 / CritSec.h
Last active May 25, 2022 19:36
CritSec - Critical section helper class for Raspberry Pi Pico SDK (RP2040)
// CritSec - Critical section helper class for Raspberry Pi Pico SDK
// by Len Popp
//
// Usage
//
// #include "CritSec.h"
//
// {
// CritSec<AnyType>::init();
// /* ... */
@Len42
Len42 / DataTable.h
Last active May 25, 2022 20:13
DataTable - Compile-time calculation of data lookup tables in C++
// DataTable - Compile-time calculation of data lookup tables
// by Len Popp
// Ref:
// https://github.com/AshleyRoll/cppcon21/blob/main/code/table_gen_1.cpp - Ashley Roll
// https://tinyurl.com/constexpr2021 - Jason Turner
#include <array>
#include <algorithm>
#include <ranges>