The Byte That Brought Things Down

Sometimes I review code and find some nitpicking issues like trailing white spaces, and missing new lines at the end of files, and they annoy me. I feel this is something that automatic tools should catch, but regardless of whether I should comment that on PR or not, I’d like to elaborate on why it bothers me.

This was a long time ago, circa 2014, I was working on a distributed system. This system was in charge of scanning and monitoring ERP servers, and its architecture was comprised of a main server (a web service), and several sensors which were other agents (in charge of the specific scanning and monitoring). These sensors reported the results back to the main server which contained all the data to display to the users.

Read more...

Running PostgreSQL in memory with docker

Introduction

Interacting with a database, can be a regular task of a developer, and for that we would like to ensure that we are developing and testing in situations close to a real implementation; therefore, using the same database as in production can help detecting issues early.

However, setting up an entire database server for development, can be cumbersome. Hopefully nowadays, modern operating systems like Linux have great tools and features that we could take advantage of.

Read more...

strncpy and strncat for copying strings in C

Recently, I've read an interesting article1, explaining why the strncpy function in C is not safer than strcpy. The post was very interesting, but what's more, it suggested an alternative idiom for copying strings in C, that might probably be the way to go.

Later, in another article2 that compared some functionality in C, Python and Go, one of the comments pointed out that very same idiom. That grabbed my attention, so I decided to try it in an example.

Read more...

Setting user permissions in KVM

In a previous article I mentioned how to install a library in Fedora, in order to make KVM virtualization easier, managing the NAT network configuration between the guest virtual machine and the host, by means of libvirt.

Besides that, while using KVM locally for development, I use virt-manager, a helpful application that manages the different virtual machines. This application, as well as the rest of the commands that interact with libvirt (virsh for example), require super user privileges, so it will prompt for the sudo password every time.

Read more...

Running RabbitMQ server on Docker

If you use RabbitMQ for development frequently, sometimes you might have found it uses too much resources (it's normal while programming to have a lot of queues or tasks being queued and that makes the CPU usage to spike).

Having RabbitMQ installed on the OS seems the perfect approach for production, but on development I'd rather do something different, in order to isolate the process. I know I could bound it (for example order it not to start automatically as a dæmon), by means of systemd but a few weeks ago I decided to try docker and see how it results.

Read more...

Find Options

Among the core-utils, find is one of the most useful commands. Though I use the basic functions most of the time, find has a wide range of parameters, and it comes in handy not only for finding files, but also for operating a bunch of them at once. Here is a very simple example.

Imagine you have to move many files to a directory, but they all call different so a glob is no use, and manually moving all of them is not an option. A possible approach would be to locate the first of the batch (for example by running ls -lrth). Suppose the first one of the batch is called /tmp/checkpoint (for this example let's assume the files reside at /tmp).

Read more...

Checking Python files with Vim

Vim is an excellent editor, and mastering it leads to more productivity. Even though is very extensible and allows to be configured by many plug-ins I rather keep it as simple as possible, trying not to use many plug-ins (neither packagers like Vundle, etc.).

However, I do make use of an extension that checks Python files for errors, PEP8, among other things: flake8. Because I do not use plug-in platforms for Vim, I install just this one manually, by making the command flake8 available system-wide1.

Read more...

Libvirt networking libraries

Fedora 21 workstation seems to come with a lot of virtualization features and most of the libvirt libraries installed. I only had to add the KVM virtual-manager which is the KVM application I am more familiar with. However, the new version of the libvirt* libraries have networking features that are great for the data centre environment, but maybe not the best option for a particular workstation, so I added the following packages in order to set up an easier network configuration for my local virtual machines.

Read more...

Vim commands for improved productivity


title: Introduction

I would like to describe my favourite Vim commands that I use on a daily basis, in order to share some tips that could help you if you are new in this editor, or to improve your experience even if you use it.

  • J : Useful when organizing code, this will join the line below to the current one.
  • ci) ("change inside ')'): Actually, the closing bracket could be changed by any other thing (like ']', '}', etc.). This will erase everything within the brackets and set you in insert mode (the c could also be changed for d for example if you just want to delete). Again, this is very useful when refactoring code, if you want to change the parameters of a function definition, or whatever is in a block, etc.
  • (select some code with visual mode and then) zf : will fold the selected code. zd for unfolding.
  • % : alone or along with some other operator, is useful for operating with matching brackets in the code. It will match the closing bracket of the one you have the cursor in.
  • C or D : if you want to change or delete from the current position up to the end of the line, respectively.
  • t, (or any other character instead of comma) will point you until that character. The good about this, is that is possible to chain it with other commands, for example: "ct," will change all the content until the next comma.
  • < or > will indent the code following the "arrow" direction (according to what is set in shiftwidth).
  • = Automatically indents code (useful when highlighting code in visual mode).
  • w, e or b will point you to the next word, to the end of the word, or back to the previous word, respectively. The nice thing about these operators is when they work combined with others, for example:
    • cw will change the next word.
    • db will delete the previous word.
  • { or } for moving up or down through paragraphs, respectively.

In addition, note that you do not need to know all possible commands, just those that will help you with your normal activities. This means that is could be enough with a small subset of all the features (the list I wrote is very short indeed). And this is precisely the idea behind this post: to show how some few commands applied in the right context, might make you edit faster.

Read more...

Starting a gnome-shell extension

Since I moved from Ubuntu to Fedora early this year, I changed my desktop environment from unity to Gnome Shell.

I must say it is a great experience. At the beginning I was thinking on what was better compared to unity (because I did not like Unity). Regarding this comparison I found a more stable and usable window manager. I still prefer something simpler perhaps, but it works good and it is nice.

Read more...