Skip to content

Instantly share code, notes, and snippets.


Carl Hörberg carlhoerberg

View GitHub Profile
# 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 /
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 / castle.rb
Last active Mar 30, 2016 integration
View castle.rb
require 'net/https'
require 'json'
class Castle
def self.api_key=(api_key)
@@api_key = api_key
# Usage
# Sinatra:
carlhoerberg / cookies.js
Created Sep 15, 2015
Cookies as a hash
View cookies.js
var cookies = document.cookie.split("; ").reduce(function(o, c) { var s = c.split("="); o[s[0]] = s[1]; return o; }, {});
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 /
Last active Sep 1, 2015
Spamassassin and postfix on Ubuntu 14.04


apt-get install spamassassin postfix

in /etc/postfix/ modify;

smtp      inet  n       -       -       -       -       smtpd
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 gist:0729156d1912fbd2af67
b = ENV.fetch 'CLOUDAMQP_URL', connection_timeout: 10
ch = b.create_channel # by default only one thread will be used per channel for processing messages
ch.prefetch 50
ch.queue('my-jobs', durable: true).subscribe(ack: true) do |delivery, headers, body|
data = JSON.parse body
ch.ack delivery.delivery_tag
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
View rpc_benchmark.rb
#!/usr/bin/env ruby
require 'securerandom'
require 'json'
require 'benchmark'
require 'bunny'
conn =
ch = conn.create_channel
x = ch.default_exchange
You can’t perform that action at this time.