This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) = @_; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> > {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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!"); |
OlderNewer