Skip to content

Instantly share code, notes, and snippets.

Carl Hörberg carlhoerberg

Block or report user

Report or block carlhoerberg

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
View bm_improved_buffered_channel.cr
# Buffered channel, using a queue.
class Channel::Buffered2(T) < Channel(T)
def initialize(@capacity = 32)
@queue = Deque(T).new(@capacity)
super()
end
# Send a value to the channel.
def send(value : T)
while full?
@carlhoerberg
carlhoerberg / README.md
Last active Feb 19, 2018 — forked from lukebakken/README.md
Restart RabbitMQ TLS acceptors with new settings
View README.md

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
carlhoerberg / castle.rb
Last active Mar 30, 2016
Castle.io integration
View castle.rb
require 'net/https'
require 'json'
class Castle
def self.api_key=(api_key)
@@api_key = api_key
end
# Usage
# Sinatra:
@carlhoerberg
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
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
carlhoerberg / a.md
Last active Sep 1, 2015
Spamassassin and postfix on Ubuntu 14.04
View a.md

Install:

apt-get install spamassassin postfix

in /etc/postfix/master.cf modify;

smtp      inet  n       -       -       -       -       smtpd
@carlhoerberg
carlhoerberg / instructions.md
Last active Jan 7, 2017
How to see Netflix on a Chromecast abroad by tethering and redirecting all DNS traffic in OS X
View instructions.md

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
  • unblock-us.com or another DNS resolver

Steps:

  1. Tethering your computer through your phone, eg. connect to your wifi, and tether with USB.
View gist:0729156d1912fbd2af67
b = Bunny.new ENV.fetch 'CLOUDAMQP_URL', connection_timeout: 10
b.start
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
process(data)
ch.ack delivery.delivery_tag
end
View bunny_rpc_fib_client.rb
#!/usr/bin/env ruby
require 'bunny'
require 'securerandom'
conn = Bunny.new
conn.start
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 = Bunny.new
conn.start
ch = conn.create_channel
x = ch.default_exchange
You can’t perform that action at this time.