Skip to content

Instantly share code, notes, and snippets.

Avatar

Carl Hörberg carlhoerberg

View GitHub Profile
@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 / .profile
Created Dec 14, 2011
Bootstrap a torquebox server
View .profile
#....
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'
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 / 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
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
'app1'
end
end
@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 / 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 = Pathname.new(context.logical_path).parent
data.gsub /url\(['"]?([^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/ do |url|
return url if URI.parse($1).absolute?
@carlhoerberg
carlhoerberg / Rails.txt
Created Mar 31, 2012
Heroku JRuby Server benchmark
View Rails.txt
# https://github.com/carlhoerberg/heroku-jruby-example/tree/puma
$ siege -b -c 100 -t 60S http://jruby-puma.herokuapp.com/
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
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 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
You can’t perform that action at this time.