Skip to content

Instantly share code, notes, and snippets.

📈
Scaling

Simon Eskildsen sirupsen

📈
Scaling
Block or report user

Report or block sirupsen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sirupsen
sirupsen / ping_less.rb
Created Mar 7, 2019
Ping less patch for MySQL.
View ping_less.rb
# frozen_string_literal: true
# By default, ActiveRecord will issue a PING command to the database to check
# if it is active at various points. This overhead is unnecessary; we instead
# attempt to issue queries without checking the connection, then if the query
# returns an error and the connection was closed, try to reconnect.
# This also allows for reconnection during a single UoW, improving resiliency
# under transient connection failure (e.g. ProxySQL restarts).
#
# To avoid amplifying load when a database is intermittently down, the attempt
@sirupsen
sirupsen / book.rb
Last active Jul 26, 2019
Script to import books from Instapaper to Airtable. Will not work out of the box.
View book.rb
class Book < Airrecord::Table
class Endorser < Airrecord::Table
self.base_key = ""
self.table_name = "Endorser"
end
self.base_key = ""
self.table_name = "Books"
has_many :endorsements, class: 'Book::Endorser', column: 'Endorsements'
@sirupsen
sirupsen / setup.sh
Last active Aug 29, 2015
Script to set up development environment for ngx-lua
View setup.sh
WORKDIR="/home/vagrant/src"
clone_repo() {
local name=$1; shift
local repo=$1; shift
if [[ ! -d "$WORKDIR/$name" ]]; then
View gist:f3111d7f12f9d736d68a
def load_customer
if customer_id = session[:customer_id]
@customer = Customer.find_by_id(session[:customer_id])
end
# 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
end
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
end
end
View gist:3b3762c74355f42ac7bc
def load_customer
if customer_id = session[:customer_id]
@customer = Customer.find_by_id(customer_id)
end
end
@sirupsen
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
end
end
@sirupsen
sirupsen / resiliency.sh
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 …
View resiliency.sh
#!/bin/bash
if [[ -z $1 ]]; then
echo -e "\x1b[31mMust supply src + dest port"
exit 1
fi
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
sirupsen / gist:7ebd15c7e2e7469ce0e1
Created Aug 1, 2014
BTRFS statsd monitor script
View gist:7ebd15c7e2e7469ce0e1
#!/bin/bash
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 "system.btrfs.total:$TOTAL|g" > /dev/udp/127.0.0.1/8125
echo -e -n "system.btrfs.used:$USED|g" > /dev/udp/127.0.0.1/8125
echo -e -n "system.btrfs.allocated:$USED|g" > /dev/udp/127.0.0.1/8125
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
You can’t perform that action at this time.