Sunday, January 11, 2015

Sample config for rabbitmq_auth_mechanism_ssl that works

This is a sample rabbitmq.config for enabling both client-side certificate and ssl authentication.

[
    {rabbit, [{auth_mechanisms, ['EXTERNAL']},
              {ssl_listeners, [5671]},
              {ssl_cert_login_from, common_name},
              {ssl_options, [{cacertfile,"/path/to/ca-cert"},
                             {certfile,"/path/to/client-cert"},
                             {keyfile,"/path/to/client-key"},
                             {verify,verify_peer},
                             {fail_if_no_peer_cert,true}                           
              ]}  
    ]}  
].

Notes:
  1. Make sure that you enabled rabbitmq_auth_mechanism_ssl plugin with 
    rabbitmq-plugins enable rabbitmq_auth_mechanism_ssl. It will be target for the EXTERNAL auth mechanim.
  2.  In your process of creating client certificate, set your rabbitmq client username as CN. i.e. CN=client_username. You don't need to provide client's login name anymore when creating rabbitmq connection in your client code.
Tested with RabbitMQ version 3.4.2

Wednesday, January 7, 2015

[Docker] Look inside running container

docker exec -t -i <container-name> /bin/bash

For looking inside an image, use

docker run -t -i <image-name> /bin/bash

Thursday, December 25, 2014

[Ruby] string to hex, hex to string

String to Hex

require 'digest'
Digest.hexencode(string)
string.unpack('H*').first
Hex to String

[hex].pack('H*')
Credit: http://stackoverflow.com/a/17223012 



Wednesday, December 3, 2014

Calculate sum of memory usage data with Awk

I don't know how to use awk, but I have a problem which I know it suits for.

I want to sum up memory usage data that come out from executing the command ps aux. I learned 2 usages of awk from this lesson.

Print value of a column with:
awk '{ print $COLUMN_NUMBER }'

Sum value of a column with:
awk '{ temp = temp + $COLUMN_NUMBER }END{ print temp }'

So I can get sum of memory usage of processes with certain name pattern like this:
$ ps aux | grep NAME_PATTERN | awk '{temp = temp + $6}END{ print temp }'

I still don't know awk, but at least I'm incrementally learning it.

Credits:
simple awk tutorial
Add up a column of numbers at the Unix shell

Wednesday, October 29, 2014

Get terminal to speak after finished a long processing command on OSX

Just append
 && say "Done"

For example;
 $ sleep 10 && say "Done"

This trick could be useful if you are running some tasks and want switch to work on something else while it's running but also want to get back to it immediately after it finished.

Source: How to make the hardware beep sound in Mac OS X 10.6


Wednesday, August 27, 2014

Really stop Clojure's infinite loop future with future-cancel

If you like me, executed future-cancel and the future is still running. This blog post is for you.

I suppose your code is something similar to this:
(def f (future (while true (your-function ... ))))
(future-cancel f)
All you have to do as describe in this SO comment is to replace true with (not (Thread/interrupted)). Example:
(future (while (not (Thread/interrupted)) (your-function ... )))
Because future-cancel will send interrupt signal to the future, Thread/interrupted will be changed to true. Now your future-cancel should work as expected.

Handy note from The Future of Ruby Performance Tooling talk

GoRuCo 2014 - The Future of Ruby Performance Tooling by Aaron Quint

It introduces a few numbers of promising Ruby performance tooling. I'll definitely refer back to this post when I do performance optimization.

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...