Skip to content

Instantly share code, notes, and snippets.

View langthom's full-sized avatar

Thomas Lang langthom

  • Post-Doc at Fraunhofer EZRT
View GitHub Profile
@langthom
langthom / BrainfuckT.h
Created August 19, 2023 18:15
A toy parser for providing brainf*ck programs as string literals in C++.
/*
* MIT License
*
* Copyright (c) 2023 Dr. Thomas Lang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@langthom
langthom / CMakeLists.txt
Created June 1, 2023 21:55
Utility functions for in-memory conversion between OpenMesh meshes and vtkPolyData.
# Copyright 2023 Dr. Thomas Lang
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the “Software”), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
@langthom
langthom / 0x59EEC4.pl
Created August 28, 2019 18:25
Funny translator which translates invididual bytes into a string and lets the computer say that word.
#!/usr/bin/perl -w
use strict;
use PerlSpeak;
my @NAMES = (
[qw(oh one two three four five six seven eight nine ann bet christ dot ernest frost)],
[qw(ten eleven twelve thirteen forteen fifteen sixteen seventeen eighteen nineteen annteen betteen christeen dotteen ernesteen frosteen)],
[qw(- - twenty thirty forty fifty sixty seventy eighty ninety annty betty christy dotty ernesty frosty)]
);
@langthom
langthom / enhancedPointer.cc
Created June 23, 2019 16:55
Implementation of a unique_ptr which can store some additional bits with low overhead. Only for normal pointers, not array pointers.
#include <iostream>
#include <cstring>
#include <bitset>
#include <limits>
#include <memory>
#include <type_traits>
#define GENERATE_PRINT_FUNCTION
@langthom
langthom / Singleton.cc
Created May 22, 2018 18:58
Singleton design pattern implementation as presented by Andrei Alexandrescu in his book "Modern C++ Design".
// Singleton pattern as described by Andrei Alexandrescu in "Modern C++ Design"
#include <cassert>
#include <cstdlib>
#include <iostream>
////////////////////////////////////////////////////////////////////////////////
namespace singleton {
/// Singleton implementation.
@langthom
langthom / placeholders.cc
Created February 6, 2018 08:15
Playing around with meta-functions, understanding placeholders as they are defined in boost.
// Playing around with meta-functions, placeholders and stuff. Thomas Lang, 2018.
#include <iostream>
#include <typeinfo>
namespace placeholder_helper {
// Helper utility for finding the N'th argument in a template parameter pack.
template<int Current, int N, typename FirstArg, typename... Args>
struct find_arg {
static_assert(Current < N, "Invalid argument position!");
@langthom
langthom / Mixin.cc
Last active October 17, 2018 17:25
Exemplary demonstration of how Mixins could be implemented in C++.
// Simple mixins in C++. Thomas Lang, 2018.
#include <iostream>
#include <list>
namespace {
// add const reference to type.
template<typename T>
struct add_cref : std::add_lvalue_reference<std::add_const<T> > {};
// g++ -Wall -std=c++11 -o crtp CuriouslyRecurringTemplatePattern.cc
// Curiously Recurring Template Pattern (CRTP)
//
// When this is used, a child class inherits from a base class templated with the own class.
#include <iostream>
// Example 1: A Counter for a class instances.
// Short snippet for a custom iterator, taken from cppreference.
// Minimally adapted, just for the sake of showing it.
// clang++ -Wall -std=c++1z -o rangetest -O3 Range.cc
#include <iostream>
#include <iterator>
namespace range {
// A simple range [From .. To]
module SAT where
-- simple file for generating an SLD tree (TESTED ON ONE FORMULA ONLY!)
-- (c) Thomas Lang, 2017
import Data.List
-- A literal, can be either positive or negative
data Literal = L String
| NEG String