Skip to content

Instantly share code, notes, and snippets.

@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
# 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 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 / castle.rb
Last active March 30, 2016 12:25
Castle.io integration
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 September 15, 2015 08:05
Cookies as a hash
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 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 / a.md
Last active September 1, 2015 20:11
Spamassassin and postfix on Ubuntu 14.04

Install:

apt-get install spamassassin postfix

in /etc/postfix/master.cf modify;

smtp inet n - - - - smtpd
@carlhoerberg
carlhoerberg / instructions.md
Last active January 7, 2017 22:06
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
  • unblock-us.com or another DNS resolver

Steps:

  1. Tethering your computer through your phone, eg. connect to your wifi, and tether with USB.
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
#!/usr/bin/env ruby
require 'bunny'
require 'securerandom'
conn = Bunny.new
conn.start
class FibonacciClient
def initialize(conn, server_queue)
ch = conn.create_channel