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.

/home/dev/apps/paack/shared/log/*.log{
  weekly
  size 500M
  rotate 30
  missingok
  compress
  copytruncate
}

Weekly

Runs the script weekly

size

Maximum size of the log file

rotate

Create a maximum of 30 files.

missingok

Ignore error if the file is missng

compress

Compress the old logs with gzip

copytruncate

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

 

More information can be found on the documentation website



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.



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.

Running

cap -T

 

shows the lists of commands capistrano supports.



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



Apache 2 is a well know server for linux.Setting up an SSL certificate on it is very simple  and straightforward.

Firstly we need an SSL certificate,We can get it from numerous online SSL providers or we could generate one ourself.

To generate a 2048 bit key.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt

This will create your public ssl certificate and a private key.

Next we have to enable ssl module for apache2

sudo a2enmod ssl

Once have this enabled,Lets add the certificate to all of the websites running on the server.On apache2 you can find the websites on /etc/apache2/sites-available/.Lets change the default-ssl.conf file on the /etc/apache2/sites-available/default-ssl.conf.

Just change a couple to lines in the file.

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key

These configurations tell apache which certificate to use and which key goes along with it.All we have to do now is enable the configuration

sudo a2ensite default-ssl.conf

And then to restart the apache2 server

sudo service apache2 restart

 



Emmet has a really awesome plugin for sublime text.The plugin depends on PyV8 to function.But by default the plugin tries to download the latest version of the plugin from the internet.This is all well until you have a stable internet connection.Since PyV8 is not updated frequently you can download the binary locally for sublime to use.

This are the instructions I followed to get the plugin to work offline.

  • First download pyv8 binary for you operating system from here.
  • Then click on Sublime > Preferences > browse package.This will open the file explorer/Finder.
  • Create a directory in the Packages folder called PyV8.Extract the binary into that folder.Example(PyV8/osx-p3) osx for the operating system.
  • In the osx-p3 directory you will find a config.json file.Open the file in sublime and change skip_update from false to true.
  • Now its time to edit the emmet config file.Click on Sublime > Preferences > Package Settings > Emmet > Settings – User.Add the following line to it ‘{“disable_pyv8_update”: true}’.

Now you can use sublime with emmet.io offline without needing to download PyV8 every-time on launch.

 



Hosting a website is pretty cheap nowadays,with most of the hosting websites charging anything from 4$ to 20$ for a small traffic domain.

Recently I came across cloudflare.com CDN service through mazyod.Cloudflare is a ddos protection service that works by modifying your DNS entries.the best part is that they are free for small websites.

So using Cloudflare and heroku we can get a website running for free with free SSL again (thanks to cloudflare).

To setup your free website

Create an account on heroku.com and host your content on it.
heroku
Next sign up for their new relic monitoring service though heroku.Link

new relic
One gotcha about heroku is that it puts your app to sleep if it doesn’t receive any traffic for a particular amount of time.New relic offers a service where they check the status of the website after a particular interval of time.This check forces your app on heroku to stay away preventing from sleeping.

To activate this service go to application monitoring in the new relic dashboard and enter your domain url 

newrelic_ping
Next setup the Cloudflare account and point your nameserver to cloudflare.To use cloudflare set your nameserver to mary.ns.cloudflare.com or tim.ns.cloudflare.com

Once you are done, create a CNAME record in cloudflare with value of YOUR_HEROKU_APP_NAME.herokuapp.com.

You can check for this value in your heroku settings.

heroku_settings



Lately I was working on some projects which had videos running in the background.The original videos that I received where high quality but extremely large(1080p videos).Using the chrome debugger, loading a single video on the browser would take atleast 1 hour to download on 250kbps.So I was tasked with re-rendering the video to reduce size.
To re-render the videos, I used ffmpeg.Its a free software available on all platforms and can we easily accessed via terminal.After tweaking around with the couple of settings I could reduce the video size down significantly.I would also like give a hand of applause to google for moving the web forward.The webm format had the smallest size less than half of the size of the mp4.
To get ffmpeg installed type

brew install ffmpeg

 

Here are the configurations I used for rendering the videos
Webm

ffmpeg -i time.mp4 -c:v libvpx -c:a libvorbis -pix_fmt yuv420p -quality good -b:v 2M -crf 5 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2" output.webm

 

mp4

ffmpeg -i time.mp4 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -crf 18 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2" output.mp4

 

Just replace time.mp4 with the name of your original video.