Skip to content

Instantly share code, notes, and snippets.


Simon Eskildsen sirupsen

View GitHub Profile
sirupsen / omg.c
Created Feb 14, 2014
Virtual memory to physical memory.
View omg.c
$ ps -o rss,command | grep ./omg | grep -v grep
488 ./omg
$ ps -o rss,command | grep ./omg | grep -v grep
10268 ./omg
sirupsen / gist:9961145
Created Apr 3, 2014
Ever-evolving light wrapper on Net::HTTP instead of always reaching for a cheatsheet.
View gist:9961145
require 'net/http'
require 'uri'
require 'json'
class ProperHTTP
def self.get(uri)
handle_response Net::HTTP.get_response(URI.parse(uri))
def, payload)
View gist:d2a3fd24ef6a605fc782
$ sudo apt-get install maven
The following extra packages will be installed:
ant ant-optional aspectj bsh fop java-wrappers junit junit4 libaether-java libaopalliance-java libapache-pom-java libasm3-java
libaspectj-java libasync-http-client-java libatinject-jsr330-api-java libavalon-framework-java libbatik-java libbsf-java libbsh-java
libcdi-api-java libcglib-java libclassworlds-java libcommons-beanutils-java libcommons-cli-java libcommons-codec-java
libcommons-collections3-java libcommons-configuration-java libcommons-digester-java libcommons-httpclient-java libcommons-io-java
libcommons-jexl2-java libcommons-jxpath-java libcommons-lang-java libcommons-logging-java libcommons-net2-java libcommons-parent-java
libcommons-vfs-java libdom4j-java libdoxia-java libeasymock-java libfop-java libganymed-ssh2-java libgeronimo-interceptor-3.0-spec-java
libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libguava-java libguice-java libhamcrest-java libhttpclient-java
libhttpcore-java libitext1-ja
sirupsen / gist:7ebd15c7e2e7469ce0e1
Created Aug 1, 2014
BTRFS statsd monitor script
View gist:7ebd15c7e2e7469ce0e1
TOTAL=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=size )\d+\.\d+')
USED=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=used )\d+\.\d+' | head -n1)
ALLOCATED=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=used )\d+\.\d+' | tail -n1)
FREE=$(echo "$TOTAL - $USED" | bc)
echo -e -n "$TOTAL|g" > /dev/udp/
echo -e -n "system.btrfs.used:$USED|g" > /dev/udp/
echo -e -n "system.btrfs.allocated:$USED|g" > /dev/udp/
sirupsen /
Created Sep 3, 2014
Script to set up port redirection and disable it again. The tricky thing here is that even when you disable the port redirect, traffic can still flow through the redirected port for already established socket sessions, but new connections can't be established. This, in addition to removing the redirect, gdbs into the process and closes the file …
if [[ -z $1 ]]; then
echo -e "\x1b[31mMust supply src + dest port"
exit 1
echo -e "\x1b[32mForwarded port $2 --> $1\x1b[33m"
sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport $2 -j REDIRECT --to-ports $1
sirupsen / gist:96326faaf94fc3051d0b
Created Jan 13, 2015
Example for blog post on resiliency
View gist:96326faaf94fc3051d0b
def test_section_a_resilient_to_data_store_b_being_down
Toxiproxy[:data_store_b].down do
get '/section_a'
assert_response :success
View gist:3b3762c74355f42ac7bc
def load_customer
if customer_id = session[:customer_id]
@customer = Customer.find_by_id(customer_id)
View gist:44f6c7293f25cf69382d
def test_storefront_resilient_to_sessions_down
Toxiproxy[:sessions_data_store].down do
get '/'
assert_equal 'Customer sign in is currently unavailable', flash[:notice]
assert_response :success
View gist:f3111d7f12f9d736d68a
def load_customer
if customer_id = session[:customer_id]
@customer = Customer.find_by_id(session[:customer_id])
# in reality e.g. a redis exception thrown from the driver
# could be raised from circuit breaker or semian as well (see later)
rescue Sessions::DataStoreUnavailable
flash[:notice] = 'Customer sign in is currently unavailable'
@customer = nil
sirupsen /
Last active Aug 29, 2015
Script to set up development environment for ngx-lua
clone_repo() {
local name=$1; shift
local repo=$1; shift
if [[ ! -d "$WORKDIR/$name" ]]; then