Skip to content

Instantly share code, notes, and snippets.

Trass3r / foridx.cpp
Created Jul 28, 2020
C++17 range-for with index macro:
View foridx.cpp
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <math.h>
#define for_i(...) \
if (decltype(sizeof(0)) i_next = 0; true) \
for (__VA_ARGS__) \
if (auto i = i_next++; true)
Trass3r / stl.natvis
Last active Jul 22, 2020
libstdc++ natvis
View stl.natvis
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="">
<!-- gnu stl -->
<Type Name="std::initializer_list&lt;*&gt;">
<DisplayString>{{ size={_M_len} }}</DisplayString>
Trass3r /
Created Jul 13, 2020
Git hook that inserts the git branch name into the commit message, useful for ticket references
branchPath=$(git symbolic-ref -q HEAD) # refs/heads/branchName
branchName=${branchPath##*/} # get text behind the last /
# check that this is not an amend by checking that the first line is empty
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ; then
# insert template at the start of the commit message file
sed -i "1s/^/$branchName \n/" $1
Trass3r / enumflags.h
Last active Jul 28, 2020
proper enum flags based on conventional "Flags" suffix (try with -Wall -W -Og -std=c++14)
View enumflags.h
#pragma once
* Copyright (C) 2020 Andreas Hollandt
* Distributed under the Boost Software License, Version 1.0.
* See copy at
// requires clang 3.6, msvc 2017 or gcc 9 (
Trass3r / algorithms.h
Created Jul 10, 2020
useful algorithms
View algorithms.h
template <typename Container>
static void moveElementToFront(Container& c, const typename Container::value_type& e)
auto it = std::find(c.begin(), c.end(), e);
if (it != c.end())
std::rotate(c.begin(), it, it + 1);
// TODO: multi-element version and non-contiguous version using std::partition
template <typename Container>
Trass3r /
Last active Jul 22, 2020
copy executable with dependencies and fix rpath
set -e
mkdir -p $2 && cd $2
ldd $1 | grep "=> /" | awk '{print $3}' | xargs -I '{}' cp -v '{}' .
cp $1 .
patchelf --set-rpath '$ORIGIN/.' *
rm libc.* libgcc* librt.* libpthread* libdl.*
Trass3r / dll2lib.bat
Last active May 31, 2020
generate import library from a dll
View dll2lib.bat
@echo off
REM Usage: dll2lib [32|64] some-file.dll
REM Generates some-file.lib from some-file.dll, making an intermediate
REM some-file.def from the results of dumpbin /exports some-file.dll.
REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt.
REM Script inspired by
Trass3r / CMakeLists.txt
Created Mar 1, 2020
template for OpenGL with CMake, Conan, glad and glfw
View CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
for %f in (src/*.cpp) do clang-tidy -p buildNinja --config="{Checks: '-*,modernize-use-default-member-init', CheckOptions: [{key: UseAssignment, value: 1}]}" --header-filter=src src\%f --fix-errors
for %f in (src/*.cpp) do clang-tidy -p buildNinja --config="{Checks: '-*,cppcoreguidelines-pro-type-member-init', CheckOptions: [{key: UseAssignment, value: 1}, {key: IgnoreArrays, value: 1}]}" --header-filter=src src\%f --fix-errors
for %f in (src/*.cpp) do clang-tidy -p buildNinja --checks=-*,modernize-loop-convert --header-filter=src src\%f --fix-errors
for %f in (src/*.cpp) do clang-tidy -p buildNinja --config="{Checks: '-*,modernize-use-override', CheckOptions: [{key: IgnoreDestructors, value: 1}]}" --header-filter=src src\%f --fix-errors
# redundant casts
"C:\Program Files\Git\usr\bin\find.exe" src -name "*.cpp" | "C:\Program Files\Git\usr\bin\xargs.exe" clang-tidy -p buildNinja --checks=-*,google-readability-casting --header-filter=src --export-fixes=casts.yml
Trass3r / unique_resource.h
Created Nov 19, 2019
unique_resource tests
View unique_resource.h
#include <memory>
#include <stdio.h>
#include <type_traits>
template <typename T, typename D>
auto unique_resource(T* t, D&& d)
return std::unique_ptr<T, D>(t, std::forward<D>(d));
You can’t perform that action at this time.