Skip to content

Instantly share code, notes, and snippets.


Carl Hörberg carlhoerberg

View GitHub Profile
carlhoerberg / reconnect.js
Created May 13, 2015
How to build reconnect logic for amqplib
View reconnect.js
var amqp = require('amqplib/callback_api');
// if the connection is closed or fails to be established at all, we will reconnect
var amqpConn = null;
function start() {
amqp.connect(process.env.CLOUDAMQP_URL + "?heartbeat=60", function(err, conn) {
if (err) {
console.error("[AMQP]", err.message);
return setTimeout(start, 1000);
carlhoerberg / .profile
Created Dec 14, 2011
Bootstrap a torquebox server
View .profile
export TORQUEBOX_HOME=/opt/torquebox-current
export JRUBY_OPTS='--1.9 -J-Xmx64m'
export JAVA_OPTS='-Xmx256m -Xms32m'
# Buffered channel, using a queue.
class Channel::Buffered2(T) < Channel(T)
def initialize(@capacity = 32)
@queue = Deque(T).new(@capacity)
# Send a value to the channel.
def send(value : T)
while full?
carlhoerberg / set_nofile_limit.c
Created Oct 10, 2013
Set nofile limit for a running process
View set_nofile_limit.c
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>
#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
} while (0)
carlhoerberg / app.rb
Created Jan 26, 2012
Webrick ssl example
View app.rb
require 'sinatra/base'
require 'openssl'
require 'webrick'
require 'webrick/https'
class App1 < Sinatra::Base
get '/' do
carlhoerberg /
Last active Feb 19, 2018 — forked from lukebakken/
Restart RabbitMQ TLS acceptors with new settings

Restarting RabbitMQ TLS Listeners with new TLS options

Edit your /etc/rabbitmq/rabbitmq.config and then reload the settings from there with:

sudo rabbitmqctl eval '{ok, [C]} = file:consult("/etc/rabbitmq/rabbitmq.config"), {rabbit, R} = proplists:lookup(rabbit, C), {ssl_options, O} = proplists:lookup(ssl_options, R), application:set_env(rabbit, ssl_options, O).'

Restart the TLS Listener on port 5671

carlhoerberg / urlrewriter.rb
Created Aug 30, 2011
A sprockets processor which rewrites the relative urls in a css when concatenating css files
View urlrewriter.rb
require 'sprockets'
require 'pathname'
require 'uri'
module Sprockets
class UrlRewriter < Processor
def evaluate(context, locals)
rel =
data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
return url if URI.parse($1).absolute?
carlhoerberg / Rails.txt
Created Mar 31, 2012
Heroku JRuby Server benchmark
View Rails.txt
$ siege -b -c 100 -t 60S
Transactions: 42918 hits
Availability: 100.00 %
Elapsed time: 60.18 secs
Data transferred: 3.40 MB
Response time: 0.14 secs
Transaction rate: 713.16 trans/sec
Throughput: 0.06 MB/sec
Concurrency: 98.90
carlhoerberg /
Last active Jan 7, 2017
How to see Netflix on a Chromecast abroad by tethering and redirecting all DNS traffic in OS X

Chromecast always uses Google's DNS servers so you can't just change DNS server on your local network, you have to redirect all DNS requests to another server. This guide will help you do so with a OS X computer and a phone.

Requirements for this guide:

  • Phone with tethering
  • OS X >=10.9
  • or another DNS resolver


  1. Tethering your computer through your phone, eg. connect to your wifi, and tether with USB.
View bunny_rpc_fib_client.rb
#!/usr/bin/env ruby
require 'bunny'
require 'securerandom'
conn =
class FibonacciClient
def initialize(conn, server_queue)
ch = conn.create_channel
You can’t perform that action at this time.