Skip to content

Instantly share code, notes, and snippets.

View kdungs's full-sized avatar
🇦🇶
Nett hier. Aber waren Sie schon mal in Baden-Württemberg?

Kevin Dungs kdungs

🇦🇶
Nett hier. Aber waren Sie schon mal in Baden-Württemberg?
View GitHub Profile
@kdungs
kdungs / candies_hps.py
Created May 19, 2013 13:54
Analysis of the relation between eaten candies and HP gain in "Candy box!" (http://candies.aniwey.net/).
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import linregress
# Set nice options for plots and use of LaTeX.
from matplotlib import rc
rc('text', usetex=True)
rc('font', family='serif')
#include <iostream>
int main() {
float a = -12;
unsigned int b = *reinterpret_cast<unsigned int*>(&a);
b <<= 1;
b >>= 1;
a = *reinterpret_cast<float *>(&b);
std::cout << a << std::endl;
@kdungs
kdungs / logistic_map.py
Created April 8, 2014 22:51
Implementation of logistic map in Python. Used for comparing the runtime to the C++11-solution.
#!/usr/bin/env python
from itertools import repeat
import numpy as np
NUM_RUNS = 1000
def logistic_map(xn, r):
return r * xn * (1 - xn)
@kdungs
kdungs / pi.cc
Created April 12, 2014 15:44
MC approximation of π.
#include <algorithm>
#include <iostream>
#include <random>
#include <utility>
#include <vector>
typedef float Number;
typedef std::pair<Number, Number> Point;
typedef std::mt19937 RandomGenerator;
@kdungs
kdungs / pi_benchmark.cc
Created April 17, 2014 08:09
Benchmark two different versions of MC-based π approximation. A result looks like this: Loop: (7.431e+07 ± 140019) ns Vector: (8.50605e+07 ± 159916) ns.
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <random>
#include <utility>
#include <vector>
@kdungs
kdungs / mean_and_sem.cc
Created April 18, 2014 14:13
Calculate mean and standard error of the mean.
template <typename T>
std::pair<T, T> MeanAndError(const std::vector<T> &v) {
using namespace std;
T mean = accumulate(begin(v), end(v), T(0)) / v.size();
vector<T> diff(v.size());
transform(begin(v), end(v), begin(diff), std::bind2nd(minus<T>(), mean));
T sq_sum = inner_product(begin(diff), end(diff), begin(diff), T(0));
T sem = sqrt(sq_sum / (v.size() * (v.size() - 1)));
return make_pair(mean, sem);
}
CXX=clang++
CXXFLAGS=-std=c++11 -stdlib=libc++
CXXFLAGS+=-O3 -DNDEBUG
CXXFLAGS+=$(shell pkg-config --cflags eigen3)
all: kalman kalman_eigen
clean:
rm -f kalman
rm -f kalman_eigen
@kdungs
kdungs / Makefile
Created June 22, 2014 18:56
A Makefile for LaTeX with intermediate running of biber.
PROJECT=main
build/${PROJECT}.pdf: build/${PROJECT}.bbl
lualatex --output-directory=build ${PROJECT}
build/${PROJECT}.bbl: build/${PROJECT}.bcf
biber build/${PROJECT}
build/${PROJECT}.bcf: ${PROJECT}.tex
lualatex --output-directory=build ${PROJECT}
@kdungs
kdungs / hlt1muonflowcharts.py
Created November 28, 2014 08:57
Extract streamer information for LHCb HLT1 Muon Streamers from TCK. The resulting JSON is put into https://github.com/kdungs/lhcb-hltflow via the `--config` option.
#!/usr/bin/env python
import json
import TCKUtils.utils as ut
TCK = 0x6A1710
streamers = [
'Hlt1TrackMuonUnit',
'Hlt1DiMuonHighMassStreamer',
@kdungs
kdungs / higherorder.cc
Last active August 29, 2015 14:19
Code for my blog post on Higher Order Functions in C++.
#include <cassert>
#include <functional>
//
// Classical Function Definition
//
int add(int x, int y) {
return x + y;
}