Skip to content

Instantly share code, notes, and snippets.

View eskil's full-sized avatar

Eskil Heyn Olsen eskil

View GitHub Profile
(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);
@eskil
eskil / prettyretarded
Created May 18, 2012 20:07
Emacs config to use the right tabs for yelp codes...
(defun my-yelp-python-mode-hook ()
(setq tab-width 4)
(setq py-indent-offset 4)
(setq indent-tabs-mode (or (string-match "/pg/yelp-main/" (buffer-file-name))
(string-match "/pg/yelp_conn/" (buffer-file-name))
(string-match "/pg/yelp_lib/" (buffer-file-name))
(and (string-match "/pg/services/" (buffer-file-name))
(not (or (string-match "/zygote/" (buffer-file-name))
(string-match "/google/" (buffer-file-name))
)
@eskil
eskil / m2crypto-certificates.py
Created April 8, 2012 17:07
Example of generating CA certs and CA signed certs using python m2crypto.
"""
Tools for creating a CA cert and signed server certs.
Divined from http://svn.osafoundation.org/m2crypto/trunk/tests/test_x509.py
The mk_temporary_xxx calls return a NamedTemporaryFile with certs.
Usage ;
# Create a temporary CA cert and it's private key
cacert, cakey = mk_temporary_cacert()