Skip to content

Instantly share code, notes, and snippets.

View tamaskenez's full-sized avatar

Tamas Kenez tamaskenez

  • Aarhus, Denmark
View GitHub Profile
@tamaskenez
tamaskenez / switch_variant.h
Created December 15, 2022 19:44
Define switch_variant, helper for switch on variants.
/* Use switch_variant like this:
switch_variant(someVariant,
[](AlternativeWithoutData) { ... },
[](const AlternativeWithData& x) { ... },
...
[](auto) {} // default branch
};
*/
@tamaskenez
tamaskenez / std_vs_macro.cpp
Created November 29, 2022 19:58
Same complicated conditions with holds_alternative and macro
void std() {
skip = std::holds_alternative<XferMode::Target>(lumaMatchMode) &&
inColorspace == ColorspaceMode::RGB;
skip = skip || (!std::holds_alternative<XferMode::Target>(self.colorMatchMode) &&
std::holds_alternative<XferMode::Reference>(self.lumaMatchMode));
skip = skip || (std::holds_alternative<XferMode::Target>(self.contrastMatchMode) &&
std::holds_alternative<XferMode::Target>(self.lumaMatchMode) &&
!std::holds_alternative<XferMode::Reference>(self.colorMatchMode));
skip = skip || (std::holds_alternative<XferMode::Target>(self.colorMatchMode) &&
std::holds_alternative<XferMode::Reference>(self.lumaMatchMode));
@tamaskenez
tamaskenez / isa_macro
Created November 29, 2022 17:41
more readable macro to replace std::holds_alternative
/ IS_ / IS_NOT_ replacement of std::holds_alternative
// Inspiration: https://youtu.be/raB_289NxBk?t=1088
// Usage:
//
// if (someVariantVar IS_(AlternativeType)) { ...
// if (someVariantVar IS_NOT_(AlternativeType)) { ...
//
// Precedence: same as binary *
//
#define IS_(TYPE) *::clai::IsInitiator<TYPE, false>()
@tamaskenez
tamaskenez / .clang-format
Created March 5, 2020 19:19
ayx-clang-format
---
Language: Cpp
# BasedOnStyle: Microsoft
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
@tamaskenez
tamaskenez / error.txt
Last active October 2, 2019 15:39
udacity AI Pacman error
Question q2
===========
BFS problem.getStartState(): A
*** PASS: test_cases/q2/graph_backtrack.test
*** solution: ['1:A->C', '0:C->G']
*** expanded_states: ['A', 'D', 'C', 'B']
BFS problem.getStartState(): A
*** FAIL: test_cases/q2/graph_bfs_vs_dfs.test
*** graph:
@tamaskenez
tamaskenez / stackallocator.h
Last active June 14, 2017 08:16
concept for an memory allocator which works like a stack
class StackAllocator {
public:
StackAllocator(int capacity)
: storage(new char[capacity])
, free_storage(storage)
, storage_end(storage + capacity)
{}
~StackAllocator() { delete[] storage; }
void* malloc(size_t s) {
@tamaskenez
tamaskenez / clangformathelp.md
Created February 8, 2016 15:17
clangformathelp

Clang-format

A clang-format az LLVM/clang projekt C/C++ formázó toolja. Egyes más toolokkal ellentétben aggresszíven formáz, tehát nem csak néhány kulcsdolgot javít ki egy kézzel is nagyjából megformázott fileban, hanem teljesen újraformáz a beállítások alapján.

A formázás történhet az 5 beépített preset egyike alapján: LLVM, Google, Chromium, Mozilla vagy WebKit, vagy egy format-file alapján, ami alapértelmezetten a formázandó file mellett vagy felett (akárhány szintre)

@tamaskenez
tamaskenez / gist:ef98237fff654c6d28b5
Created January 25, 2016 09:19
CMakeExpandImportedTargets-fork.cmake
#.rst:
#
# This is a fork of the official CMakeExpandImportedTargets
# The official version is deprecated and won't be updated so
# we'll maintain a local copy here
#
# CMakeExpandImportedTargets
# --------------------------
#
# ::
@tamaskenez
tamaskenez / cmakex
Created December 9, 2015 00:50
Execute multiple `cmake` commands with a single `cmakex` command.
#!/bin/bash -e
#
# cmakex
# ======
#
# Execute multiple `cmake` commands with a single `cmakex` command.
# Also, enable the CMAKE_INSTALL_PREFIX environment variable
#
# SYNOPSYS
# --------
@tamaskenez
tamaskenez / make_config_modules_relocatable.cmake
Last active March 24, 2020 12:17
converts the absolute paths found in CMake config-modules to paths relative to the root of the install tree
# This script fixes the absolute paths, which reference a file within
# a tree (usually the install dir).
#
# It's only input parameter is the root directory (usually the dir set as
# CMAKE_INSTALL_PREFIX).
#
# First it globs all the *.cmake file within the directory.
# Scans them for the root dir.
# If found, introduces a new INSTALL_PREFIX_... variable in the script,
# derived from the location of that script and replaces all references to