Skip to content

Instantly share code, notes, and snippets.

View eskil's full-sized avatar

Eskil Heyn Olsen eskil

View GitHub Profile
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit.hpp>
#include <boost/spirit/actor.hpp>
#include <string>
#include <map>
#include <stdexcept>
#include <algorithm>
using namespace std;
using namespace boost::spirit;
@eskil
eskil / bvi_group.erl
Last active August 29, 2015 14:20
Debt reduce solution for 2015 BVI Trip
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname bvi_group
%% escript ./bvi_group.erl
% Magic compiler directive to make reduce/1 be visible in main/1.
-mode(compile).
%% This is a variant of the debt reduce interview question that works
(define-minor-mode code-wrap-mode
"Visually wrap the buffer text to the previous lines indent, plus a tab."
:lighter ""
(if code-wrap-mode
(progn
(visual-line-mode 1)
(jit-lock-register #'indent-prefix-wrap-function))
(visual-line-mode 0)
(jit-lock-unregister #'indent-prefix-wrap-function)
(with-silent-modifications
class simple;
typedef statemachines::traits<my_state_type, threads::single_threaded> my_traits;
class simple : public statemachines::statemachine<simple, my_traits> {
public:
class generic_event : public event_t {};
class one_event : public event_t {
public:
one_event (std::string msg) : m_message (msg) {}
.----.-.
/ ( o \
'| __ ` ||
||| ||| -'
¯\_(ツ)_/¯
@eskil
eskil / fixbase
Last active December 16, 2015 13:59
Script to rebase -i origin/master and auto mark fixes as 'f'
#!/bin/bash
# Put in ~/bin/fixbaseedit.sh
# alias fixbase="EDITOR=~/bin/fixbaseedit.sh git rebase -i origin/master"
# You can also just make a script that does "git commit -a -m fix" and
# the rebase for you.
sed -i.old \
-e '2,$s/pick \(.*\) fixup/f \1 .../g' \
@eskil
eskil / flask-security unit testing.
Created January 4, 2013 07:24
Steps to run flask-security unit-tests on a mac.
To run flask_security unit-tests:
virtualenv --no-site-packages env/
. env/bin/activate
pip install nose simplejson Flask-SQLAlchemy Flask-MongoEngine Flask-Mail py-bcrypt Flask Flask-Login Flask-Principal itsdangerous passlib
Apply this diff to disable mongo tests and use sqlite instead of postgres:
diff --git a/tests/functional_tests.py b/tests/functional_tests.py
@eskil
eskil / gist:3628248
Created September 4, 2012 23:57
Example of templates computing object sizes for slab allocators
/*
Test that implements some template meta programming.
- two_to_the_power_of<Power> calculates 2^Power into it's ::value.
- rightshits<V> calculates how many times V can be rightshifted
until it's 1 or 0, result is in ::value.
- if_t<bool,A,B> places A or B in ::value, depending on the bool
@eskil
eskil / chunkserv.cc
Created July 10, 2012 20:27
C++ version of chunkservs TimeWindowedStats, using boost.python.
/*
C++11 version of chunkserv.util.TimeWindowedStats
A dumb test that feeds a ton of entries into both the python and C++ version shows that;
Python
- insert_events time 0.237569570541
- compute_stats time 19.1441180706
C++
- insert_events time 0.234213590622
@eskil
eskil / ctassert.h
Created July 10, 2012 01:18
Example of how to implement static assert using template specialisation.
template<bool> struct _compile_time_assert;
template<> struct _compile_time_assert<true> {};
#define ctassert(expr) if (0) { int flaming_goat_sausage = sizeof(_compile_time_assert<(bool)(expr)>); flaming_goat_sausage++; }
int main (int argc, char *argv[]) {
ctassert (sizeof (int) == 4);
ctassert ((sizeof (int) == 5) == false);
//BLAM
ctassert (sizeof (int) == 5);