Last week my colleague Victor from Paack and I were digging through the server to look at the logs.

-rw-rw-r-- 1 dev      dev     3.5M Nov  25 17:33 newrelic_agent.log
-rw-r--r-- 1 www-data root 1G Nov  25 17:55 nginx.access.log
-rw-r--r-- 1 www-data root 1G Nov  25 17:55 nginx.error.log
-rw-rw-r-- 1 dev      dev     0 Apr 30  2015 production.log
-rw-rw-r-- 1 dev      dev     1G Nov  25 17:33 puma.access.log
-rw-rw-r-- 1 dev      dev  10G Nov 25 12:03 puma.error.log
-rw-rw-r-- 1 dev      dev     0 Dec  2 17:34 puma.log
-rw-rw-r-- 1 dev      dev   50M Dec  2 17:52 sidekiq.log

When we looked at this folder we were shocked.Our log files were a couple of Gigabytes,That was a huge problem, since this could result in slower requests as it logs it.

Are some googling we found that logrotate came part of ubuntu.So though of using it.

The configuration was pretty simple, Logrotate configuration is really cool.It loooks like a bunch of dsls.

  size 500M
  rotate 30


Runs the script weekly


Maximum size of the log file


Create a maximum of 30 files.


Ignore error if the file is missng


Compress the old logs with gzip


Truncate the old log file and create a new one file with the truncated data.


More information can be found on the documentation website

For the last 2 weeks I was busy with a hardware startup called MyTriphoto.The whole premise of the startup is to take panoramic selfie without touching the camera.To accomplish this we have been working on a hardware prototype built using the raspberrypi and a 360 camera.The user connects to the wireless network setup by the raspberrypi and the router. The user is then greeted with the webapp on this phone.

So to get this working I had to setup a captive portal on the the router.I looked around for existing solutions and came across nocatsplash.After digging a bit more I found nodogsplash.NoDogSplash is based off of nocatsplash with a bunch of new features and easier configuration manager.

To setup nodogsplash on MR3020 was a breeze.
All I had to do was update the package repositories and install nodogsplash.
Here is how i installed it.

opkg update
opkg install nodogsplash

Time to configure the portal.Luckily the documentation for nodogsplash was really good.The configuration was heavily commented and with a bunch of configuration options.

Last week on saturday I had participated in the dec0de hackathon with my friend.Unlike previous hackathon that I took part in.I had an idea in mind days before the hackathon.All that was left was implementing it during the hackathon.

The idea was pretty straight forward, it was a mobile app that tracks the transaction from different bank accounts through the SMS that it receives after every transaction.

Here is the presentation:

After thinking about it for a while, I realized that it was a combination of the presentation and the idea that made us win first place at the hackathon.

More over we were also published in a couple of article online:

While working on the Paack application I came across the issue where the main hard disk on the machine was getting full.Mostly due to the fact that Capistrano saves atleast 25 of the last deployments on the server.That meant the assets and the precompiled data, would all be written on the same drive.At the time when I looked at the computer, the system had about 36% drive space free.This was a huge cause of concern since I didn’t want to deal with the limited storage issue.

So I began looking at the azure documentation/reference on setting up extra hdd on a single virtual machine.Azure restricts the number of drives you can attach per virtual machine based the tier of the virtual machine.

Continue reading

Last night my friend wanted help with custom PHP cms which he was built for his client.The code was really a mess.You would not know where the code actually began and there was clearly no separation between the model and the views.

I didn’t want to spend considerable amount of time in understanding the code.I started debugging the code using the die function.Yeah ‘die php die’.

die() is a pretty awesome function it is similar to the raising an exception but instead of causing a crash it  just stops code execution for the consecutive lines.You can also pass arguments to the die function.

I was really not sure how the user session was stored/created.So i used the die function by passing the var_dump($_SESSION) as the argument, this returns the all the session information.

The php array was returned with a bunch of keys which didn’t make sense at all.

The good part about the whole experience was I spent less than 2 minutes in the ugly PHP land.

Nginx is a really awesome web server.It likes a magic tool which does everything you need.

Two weeks I set up a server with multiple websites running on.Since the server was beefy enough we could run 5 websites on it with relatively medium amount of traffic.


The way Nginx allows us to configure multiple websites is using a configuration block in the /etc/nginx/sites-available  or /etc/nginx/sites-enabled directory.Its not necessary to store the configuration in the particular directory but it is treated as good practice.

This is how I setup websites on Nginx.I would first create the configuration file in the /etc/nginx/sites-available/ directory.Here is the sample configuration.

The most important command to run once you have setup the configuration is sudo nginx -t.It doesn’t run the server but just tests if the configurations are correct syntactically.

Now that everything is ready, we just have to enable to website configuration.To enable the configuration we create a symbolic link using the following command

ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Make sure you include full folder/file path when creating the symbolic link.

To add another website follow the process mentioned above.

Once you are done run sudo service nginx restart.This command will reload the configuration and then restart the server.

In my quest to move away from heroku. I came across Capistrano a popular automated deployment tool written in Ruby. Capistrano is really popular with millions of downloads and lots of Plugins

Here is how I setup Capistrano to deploy static websites and create rollbacks in case the build was buggy.

Capistrano deploys the code to /var/www/application_name.It does so by logging in the user into the server and pulling the repo from the git repo specified.On top of this capistrano adds a bunch of commands to make this process simpler.


cap -T


shows the lists of commands capistrano supports.

Devise is such a beautiful library.I don’t see any reason to write my own authentication component on rails.Moreover Devise allows you to custom every single feature of the library.

Last week I was tasked with creating a registration page for a startup, to make the sign up process simpler we would allow the user to create a company in the same form.Devise made this task very simple.By default devise creates routes for user sign up,but this route would conflict if you have a user resource route.Here is how you can customize the url to use the right controller and route url.
The path_names property sets the registration url to ‘/users/register’ and since we want to create the company relation we use a custom registration controller.
The registration controller’s new method overrides the Devise::RegistrationController.

build_resource({}) and set_minimum_password_length enforces the minimum password length and also creates the resource which in this case is the user.
We also create a model for the company.

The method create on the other hand just takes the params and generates a user model from it.

The method sign_up_params is overridden to allow the company attributes to be used as rails model attributes More info.

The view on the other hand is also simple.Just add the relations and devise takes care of the rest.

As you can see the company form field is generated similarly to rails form.

You might have heard a lot of people claiming that privacy on the internet is dead.Yes that might be partially true.NSA thanks for reading this post.As for those of you who still want to say away from the preying eyes of the ads agencies, you might want to take a look at the following plugins/tools.

Here are the plugins that I use to keep trackers away.
Continue reading