Debugging with tcpdump

I’m having some problems with one of my hobby servers but this time instead of looking at the code to try to figure out what is happening, I decided to try to do it using only tcpdump. I was trying to start my server and I got this error message:

1
failed to create GA auth provider: invalid character '\u003c' looking for beginning of value

The character ‘\u003c’ translates to <, so it seemed like the problem was that somewhere in my GA auth library I was getting what looked like an HTML instead of a JSON. The first thing I did was monitor the HTTP traffic using this command:

1
tcpdump -c 20 -s 0 -i eth0 -A tcp port http
Read More

Restart a process automatically if it dies

I have a hobby server that I’m deploying to a digital ocean droplet. I run this server as any other program and it does what it was programmed to do:

1
./myserver

The problem is that this server is not perfect and I’m OK with that. Nevertheless, I don’t want to have to restart it manually every time it dies. For that reason I did some googling and found an easy way to restart my server if it unexpectedly dies:

1
2
3
4
5
6
7
8
#!/usr/bin/env bash

until /home/tacos/myserver >> myserver.log 2>> myserver.error.log; do
    echo "$(date -u) - Server crashed with exit code $?.  Respawning..." >> runner.log
    sleep 1
done

echo "$(date -u) - Server manually killed" >> runner.log
Read More

First steps in Go Language

My company started using Go for some services and currently there is only one person that is familiar with the language. This means nobody is reviewing the code and nobody can contribute or fix stuff if it is necessary. To fix this, I have decided to learn Go.

Install

The install steps might change depending on your operating system, so you are probably better reading the official documentation. I’m going to show the steps I followed to install on my system just as an example.

I’m running a Fedora machine so I downloaded the binary from the downloads page and extracted it to a folder. The next step is to add the Go binaries to the path. You can achieve this by adding two lines to ~/.bashrc:

Read More

Running Polymer tests with Docker

On a previous post I wrote about how to write tests for polymer components. Now, I want to hook those tests into my automated test suite that runs for all commits in a repo. The problem is that we are kind of in a low budget so we don’t have a selenium grid we can connect to. What we do have is a machine where we have Jenkins installed. Because we run many different jobs in this machine, we usually use docker to keep our environment isolated.

The problem now is that we can’t run polymer tests in a headless browser like phantomjs, because it is not supported. We have to run our tests in a real browser like Chrome or Firefox. These browsers need a GUI to work which docker doesn’t provide, so we have to do a few things to work around this issue.

xvfb

Xvfb stands for X virtual framebuffer. It is a display server that implements the X11 protocol, but does everything in memory, so it doesn’t really need a screen to work. This is exactly what we need. To use it we just need to create a Dockerfile that uses xvfb to run the tests:

Read More

Testing Polymer components using Web Component Tester

I have started writing some real life polymer components, and I feel really bad that I haven’t been writing tests for them. In this post I’m going to teach myself how to write and run tests for polymer components so I can stop being a slacker and do some proper TDD.

Lets start by creating a little project. You can leave the defaults for the questions asked by npm init:

1
2
3
mkdir ~/test
cd ~/test
npm init

Now, lets setup bower. You can again, leave the defaults:

1
2
npm install --save-dev bower
./node_modules/bower/bin/bower init
Read More

Using Gerrit with MySQL

A few weeks ago I published a post with an introduction to Gerrit. The configuration I explain there is not very scalable, so now I want to explain how to connect it to an external MySQL database so the data is more secure. As in my previous post, I’m going to do everything inside a docker image so it is easy to reuse and share.

Lets start with the Dockerfile from my previous post:

1
2
3
4
5
6
7
FROM gerritforge/gerrit-centos7:2.11.4

# Expose gerrit ports
EXPOSE 29418 8080

# Start Gerrit
CMD /var/gerrit/bin/gerrit.sh start && tail -f /var/gerrit/logs/error_log
Read More

Suspending processes

Sometimes when I’m running a process in the foreground (most commonly, vim). I unintentionally press Ctrl + z and I get a message like this:

1
[1]+  Stopped                 vim

There might be reasons why you want to do this if you are running in a system that gives you a single terminal, but when running a UI where you can have multiple terminal tabs open, this usually happens by mistake. But no reason to panic, if you want to go back you just have to type this command:

1
fg

As a matter of fact, you can have different jobs running on the background:

1
2
3
4
jobs
[1]   Stopped                 vim
[2]-  Stopped                 vim
[3]+  Stopped                 less Makefile

And reopen them using fg %n. For example:

1
fg %2
Read More

Adjusting the width of Nerdtree navigator

Nerdtree is one of my VIM essentials, but I was always annoyed that it took so much space in the screen. Since I use a vertical monitor, I barely get 80 characters to work on. I recently found that this is easily fixed by adding a configuration to .vimrc:

1
let g:NERDTreeWinSize = 20

Sometimes, when I was browsing through the folders I actually wanted to be able to make it larger so I could see the complete file names. This is also easy to achieve. Move your cursor to Nerdtree and toggle it using:

1
shift + a
Read More

Uploading to an S3 bucket that contains dots using node SDK

I’m trying to host a static site in S3 using AWS. The problem is that for it to work with a custom domain, the bucket needs to be named like the domain. Domain names contains dots and for some reason they are not supported out of the box in the SDK. I was trying to something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var fs = require('fs');
var aws = require('aws-sdk');
var bucket = 'my.domain.com';

var bucketParams = {
  params: {
    Bucket: bucket
  }
}
var bucket = new aws.S3(bucketParams);

var uploadData = {
  ACL: 'public-read',
  CacheControl: 'max-age=31556926',
  Key: 'somefile.txt',
  ContentType: 'text/plain'
};
uploadData.Body = fs.createReadStream('somefile.txt');
bucket.upload(uploadData).send();
Read More

Using Gerrit for better collaboration on git projects

I’m working with a small team that is divided in two geographical locations. This separation has made collaboration a little challenging which has compromised the quality of the code base. I’m exploring tools that can help us collaborate better, particularly making it easy to review each others code.

Gerrit promises a platform that makes it possible to create ACLs on top of git repositories, so that code can’t be committed until an official approver checks and approves the code. Ideally, the workflow will look something like this:

  • Carlos makes changes and commits them to his local repository
  • Carlos pushes his changes to Gerrit and creates a code review
  • Luis, as an owner of the project reviews the code and suggests changes
  • Carlos makes the changes, commits them and updates the code review
  • Luis looks at the changes and approves them
  • Carlos can now push the changes to upstream
Read More