Archive | February 2015

RabbitMQ Library for Prolog

Recently I’ve started working on a new project that involves Prolog, C and Ruby. The objective is to implement a Prolog library to work with RabbitMQ. RabbitMQ is a message broker that implements the AMQP protocol, thats, Advance Message Queueing Protocol.

AMQP and RabbitMQ

Without going into much detail, RabbitMQ is a message broker that implements the AMQP protocol. RabbitMQ receives messages from producers and sends them to, possibly, predefined consumers. To do this, RabbitMQ uses two things, exchanges and queues.

Exchanges and queues are binded together. The exchanges are the parts of RabbitMQ that receive messages from producers has input and decide what to do with them. They may decide to simply ignore the message, store them in every queue binded to them, store them in some particular queue, etc. The type of exchange, and some added arguments in their declaration, determine their behavior. Consumers are programs that will look into specific queues and will read the messages in them.

To know more about the different types of exchanges read this article in Buny’s site.

Prolog Library

There are many libraries for RabbitMQ in many languages. Just the tutorial in RabbitMQ’s site is written for five different languages, which are Python, Java, Ruby, PHP, and C#. I myself have looked into Python’s Pika library, Ruby’s Bunny library, and also RabbitMQ-C for the C programming language. The project in here is the development of a similar thing but for Prolog.

The library in Prolog will work with a set of predicates. A predicate is, for example the following:

amqp_new_connection(Conn, localhost:5672).

In this example, the predicate will actually create a new connection using localhost on port 5672. Conn will be a term, which in this context works like the connection descriptor for the newly created connection. Most of the predicates in the library work/will work using this descriptor notion.

The library is being developed to work with YAP, (Yet Another Prolog). To achieve this implementation, the predicates are implemented in Prolog with some low level parts implemented in C using RabbitMQ-C. The predicates are being made to resemble the Bunny library, meaning that most predicates are actually mimicking Bunny’s API. For example, in Ruby, to declare a direct exchange you do:

ex ="myex")

Where ch is a channel, “myex” is the name of the exchange, and ex will be the new exchange. The Prolog equivalent is:

amqp_direct_exchange(Chn, "myex", [], Ex).

Where, Chn is the channel, “myex” is the name of the exchange, the third argument is an empty list of arguments, and Ex is the descriptor for the newly created exchange.

So, this project involves using Prolog and C to implement a Prolog Library based on a Ruby library for a message broker. Ruby and RabbitMQ are actually new to me, the other things are old news. This is actually being very interesting.

What Is Currently Done

Currently, it is already possible to implement a basic producer and a basic consumer in Prolog. There aren’t many options that can be used yet, such as different arguments for the various objects that get used around. Also, some underlining code is missing some error handling, like for example, there may be errors while connecting to a server, while sending a message, etc. The current implementation always assumes everything goes just fine. This obviously needs to be solved.

On my GitHub are examples of the basic producer and consumer in Prolog. Also on GitHub are the Ruby’s equivalent for a producer and a consumer using Bunny. Note that the Ruby example should execute if you have Buny installed. But the Prolog example shouldn’t run because the implementation isn’t released nor finished.

New Ubuntu Setup – not_so_blue

I’ve been using Linux… I’ve been using Ubuntu since 2008. I saw many visual changes made to Ubuntu over the years, in particular there was that big change that made Ubuntu move from GNOME to Unity.

When I discovered /r/unixporn I was shock at finding out how I was missing out in terms of customization, and particularly in how I was missing out on tilling windows managers. Since them, I’ve made two setups. In this post I describe my third setup.

Tiling Windows Manager

The first two setups I had that had tiling managers used XMonad. XMonad is a manager that is programmed in Haskell and uses Haskell for configuration. I was a bit tired of XMonad because it felt a bit slow. I could actually see the tiles getting redrawn every time I changed workspace and there was always a laggy flash when I changed the tiles’ orientation. Also, I’ve tried learning Haskell but after a few hours spent with it I got to the conclusion that it is an annoying language and I don’t like it. So, I’m not really into configuring XMonad.

I decided to drop XMonad and try another manager. I tried i3 and I liked it way better.

First, i3 lets the user split tiles and move them around at will. It doesn’t stick with a more strict structure. You can also take a bunch of tiles and make them tabbed or stacked for different usages. It very cool.

Second, the problems I was having with lag in XMonad are not present in i3. My PC is a bit old and it was never a high performance machine. But Common! I’m not exactly rendering 3D graphics in Full HD resolution at 60 fps. i3 runs smoothly!

Third, configuring i3 is not done with any programming language directly like other managers. But its configuration features is enough to respond to my immediate needs.

Fourth, the default command are better.

My configuration file for my i3 setup at GitHub.

i3bar, dmenu, and Other Details

In my first setup I used a simple text based bar. But it was a terrible experience. In my second setup I used GNOME’s panel that came with GNOME for Ubuntu, and it was better.

This time I’m using i3bar and it is even better!! I use it pretty much out of the box and didn’t look much into its configurations because what I have now suits me just fine. Its configuration file is at GitHub.

To start any program in the background without having to open a terminal I just use dmenu. I use it with the option to make it show up at the bottom because I prefer it like that. The rest is out of the box! I may change its font later.

As a network manager I just use the nm_applet program that comes with Ubuntu. It works just fine.

The terminal I’m using is the gnome-terminal. The shell I’m using is zsh with the oh-my-zsh. I’ve thought about using other terminal and terminal multiplexer and all that. But I’ve never gotten around to do that. Using tmux might be cool.

I use Vim for every programming and file editing need I’ve add for some time. I enjoy the modal editing notion of Vim and all its other features. Using Vim in these kinds of setups is a perfect combination because of how it fells, meaning that everything you do is done thought key binds that make sens and you never have to use the mouse, and how it looks, which is good.

Colors and Wallpaper

In my previous setup I used the Solarized has the set of colors for everything. I never made my own color pallet or my own themes for Vim, terminal and tiles. But Solarized just looks good, and it is popular. For this setup I’ve sticked with it.

I needed a new wallpaper. I was using a wallpaper with the world map with timezones. But now I wanted something different. I decided to make a python script that used matplotlib to draw three sine waves, sum them toggether and draw that result. I also placed some hexadecimal characters in the bottom right corner. The hexadecimal is just the following text: “This is a sample text. K”.

I used the Solarized colors for the wallpaper. It looks… cool. I like it like this. I may change a few things.


I tried using Conky in the passed but never really did anything with it. This time I looked into it, copied this configuration, changed it a bit and now have two simple Conky windows in the background.

One of the windows shows the processes running (top), and the other shows information on CPU, memory and swap usage. With the wallpaper they actually look pretty cool.

I may add a window to show information on the network on some other thing. But for now I like it like this.


Here are the results. Three screen shows, taken with scrot, one clean and two dirty. The first screen shows Vim and two terminal windows opened. The second shows screen fetch and the colors used.

clean dirty_1 dirty_2

I also recorded a 1 minute video to show this setup in usage.

I am very satisfied with this setup!