Skip to content

Instantly share code, notes, and snippets.

@carlhoerberg
carlhoerberg / reconnect.js
Created May 13, 2015 14:45
How to build reconnect logic for amqplib
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 / sendfile.cr
Created June 27, 2023 11:40
sendfile implementation for crystal
require "socket"
lib LibC
{% if flag?(:linux) %}
fun sendfile(fd_out : Int, fd_in : Int, offset : OffT*, count : SizeT) : SSizeT
TCP_CORK = 3
{% else %}
struct SendfileHeader
headers : IoVec*
hdr_cnt : Int
@carlhoerberg
carlhoerberg / make_password.sh
Created October 26, 2011 16:12
Make a random password
#!/bin/bash
LANG='C'
cat /dev/urandom|tr -dc "a-zA-Z0-9"|fold -w 64|head
@carlhoerberg
carlhoerberg / Test.cs
Created December 22, 2010 15:01
Test IModel in RabbitMQ.Client
[TestFixture]
public class RabbitMQTest
{
[Test]
public void CanMockMQ()
{
// Arrange
var channelMock = new Mock<IModel>();
channelMock
.Setup(m => m.BasicConsume(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<IDictionary>(), It.IsAny<IBasicConsumer>()))
@carlhoerberg
carlhoerberg / .profile
Created December 14, 2011 11:13
Bootstrap a torquebox server
#....
export TORQUEBOX_HOME=/opt/torquebox-current
export JBOSS_HOME=$TORQUEBOX_HOME/jboss
export JRUBY_HOME=$TORQUEBOX_HOME/jruby
export PATH=$JRUBY_HOME/bin:$PATH
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)
super()
end
# Send a value to the channel.
def send(value : T)
while full?
@carlhoerberg
carlhoerberg / set_nofile_limit.c
Created October 10, 2013 07:11
Set nofile limit for a running process
#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
carlhoerberg / app.rb
Created January 26, 2012 20:55
Webrick ssl example
require 'sinatra/base'
require 'openssl'
require 'webrick'
require 'webrick/https'
class App1 < Sinatra::Base
get '/' do
'app1'
end
end
@carlhoerberg
carlhoerberg / README.md
Last active February 19, 2018 22:40 — forked from lukebakken/README.md
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
carlhoerberg / urlrewriter.rb
Created August 30, 2011 21:30
A sprockets processor which rewrites the relative urls in a css when concatenating css files
require 'sprockets'
require 'pathname'
require 'uri'
module Sprockets
class UrlRewriter < Processor
def evaluate(context, locals)
rel = Pathname.new(context.logical_path).parent
data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
return url if URI.parse($1).absolute?