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 / gol.pl
Created July 27, 2016 13:08
Conway's "Game Of Life" in Perl
#!/usr/bin/perl
# A damn nice "Conway's game of life".
# Taken from 'Coding for fun with Python' and translated into Perl.
#
# Thomas Lang, (c) 2016.
use strict;
use warnings;
use OpenGL qw/ :all/;
@langthom
langthom / crawlThem.pl
Created August 11, 2016 22:45
simple crawler for getting xkcd comics
#!/usr/bin/env perl
# A simple crawler for getting the nice comics from xkcd.com
#(c) Thomas Lang, 2016
#
# Yes, this is damn non-performant, but if it works, it ain't stupid.
use warnings;
use strict;
use LWP::Simple;
# Using defer i.e. calling a function when leaving scope.
# Neat trick for cleanup of resources.
#
# Copyright of lines 5-27 to @briandfoy_perl
use v5.10.1;
use strict;
use warnings FATAL => "all";
sub defer {
my ($sub) = @_;
@langthom
langthom / compileTimePrimeFactorization.cc
Created August 6, 2017 14:28
A simple compile time functionality for calculating the prime factorization of a number.
// Compile time prime factorization.
// (C) Thomas Lang, Aug 6th, 2017
#include <iostream>
// First, we create a basic list structure in a functional style:
struct NIL {
using Head = NIL;
using Tail = NIL;
};
@langthom
langthom / CTSieve.cc
Created October 5, 2017 16:02
A simple, and damn stupid compile-time Sieve of Erathostenes.
// A primitive compile-time Sieve of Erathostenes, (c) Thomas Lang, 2017
#include <iostream>
// First, the usual value-to-type wrapper for usage in type lists.
template<unsigned int V>
struct Value {
enum { value = V };
};
// And the ususal conditional.
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
// 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]
// 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.
@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> > {};
@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!");