Cruisemaniac Dad, Husband, Geek, Cyclist!

Here's to a great 2014

2013 is done. Its time now for another chance at life - Another new start!

Another attempt to correct the wrongs, move ahead, make new mistakes, learn new lessons, forge new friendships, remember the old ones, call it what you may in this list here - its just another chance to be a new you!

Or, you can just KEEP CALM AND CARRY ON.

Choose whatever but this is how it must play out:

Introduce a little anarchy. Upset the established order, and everything becomes chaos. I’m an agent of chaos. Oh, and you know the thing about chaos? It’s fair! - The Joker.

Here’s wishing every single one of you the very best in 2014!

Here's to 2013 and a great 2014

2013 was an amazing year in many respects! Worked on more things than before - learnt a ton of new things…

Infrastructure management - I got my hands dirty with something i’ve always wondered what it was. Knowing how to organize your infrastructure, sizing, planning, creating new machines, the cloud and yes, Amazon EC2 as well!

Got better at automating software delivery - helped improve processes at work! A tiny little tool that I wrote has run with 0 downtime for the last year! Okay… there was a downtime of about 5 minutes when the root password expired :-P

Got my daughter start her schooling - at the very same place that I studied! personal best

Travelled - both within India and Outside - The visit to Copenhagen was beautiful! Cold, Freezing, yet beautiful - thanks to the amazing bread and cheese they have there!

In all, this was a year that I re-discovered myself - revelations like I can run for a kilometer before my lungs start burning OR walk for 6 kilometers before I can feel my knees start to complain were interesting!

Fell down, got hurt, got up, got running again! And thats the quick run up that was 2013.

Here’s wishing you all a wonderful 2014 ahead… and if I may, I’ll leave you with this

Introduce a little anarchy. Upset the established order, and everything becomes chaos. I’m an agent of chaos. Oh, and you know the thing about chaos? It’s fair! - The Joker.

Nginx HTTP Caching and Compression

This is a blog post for posterity - I’m sure I’ll forget how I did this and will go hunting again! and I must definitely be the last guy on the planet to be setting up nginx!

Nginx is pretty fast in itself. I use jekyll to power this site. So, when you’re reading this article, all the data is coming right off the hard disk - No databases, no queries, no lookups - simple fopen, read, stdout…

But you still want a bit more… A little bit of added juice from nginx. This is what I did - enabled http Caching and gZip compression.

And here’s how:

####nginx.conf

Open up your nginx.conf file (on my box, it was at /etc/nginx/nginx.conf) and head to the section under Gzip settings.

Uncomment the following chunk:

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";

        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

What we’re doing here is this:

  1. Turning on gzip compression - this must be on by default on nginx.
  2. Disabling compression for browsers that do not support compression
  3. gzip_vary helps set headers with vary: Accept-Encoding and gzip_proxied allows compression to happen even if the requests are coming in via a web proxy.
  4. gzip_comp_level 6 defines the level of compression between 1-9 (1 being lowest and 9 being highest)
  5. And other settings - the types of mimes to be pushed through the compression, the keep alive settings for the http 1.1 protocol, et al.

What really matters here is that you uncomment these lines.

Save the file and restart nginx.

####sites-enabled

To enable HTTP Caching, head out into /etc/nginx/sites-enabled/<your-site-config-file> and make the following changes:

    #enable caching
        location ~* \.html$ {
                expires -1;
        }

        location ~* \.(css|js|gif|jpe?g|png)$ {
                expires 15d;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

The first chunk disables expiry for html files. This will cause the text matter to be downloaded every time.

The second chunk sets the expiry to 15 days for all other content of the website - css files, javascript and images - I’ve set it to 15 days because there’s not much changes these files will see.

Another restart of nginx and you must notice a decent improvement in performance.

A quick way to check if your settings are in place is by using curl.

the-flying-dutchman:cruisemaniac.com cruisemaniac$ curl -I cruisemaniac.com/favicon.png
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sat, 07 Dec 2013 05:26:48 GMT
Content-Type: image/png
Content-Length: 34402
Last-Modified: Fri, 06 Dec 2013 23:57:03 GMT
Connection: keep-alive
Expires: Sun, 22 Dec 2013 05:26:48 GMT
Cache-Control: max-age=1296000
Pragma: public
Cache-Control: public, must-revalidate, proxy-revalidate
Accept-Ranges: bytes

Jekyll and Windows Code Pages

####Prelude I recently moved my blog over to Jekyll! Thanks to a black friday deal over at Digital Ocean, I got my hands on a vps that I dont have to pay for the next 10 months…

So, the first thing I did was to setup my almost dead in the corner blog using Jekyll, something that I’ve been meaning to do for over a year now.. And unlike a lot of people using Jekyll on *nix and OSX based systems, I was forced to setup Ruby 1.9.3 on Windows 7 and play around with it…

####The WTF So up comes c:\work\cruisemaniac.com>jekyll serve and bam!

Generating... ←[31m  Liquid Exception: incompatible character encodings: UTF-8 and IBM437 in _layouts/post.html←[0m
error: incompatible character encodings: UTF-8 and IBM437. Use --trace to view backtrace

####And…the enlightenment A bit of googling on this error says something about character pages on MS-DOS not being upto speed on handling characters from more advanced character sets - *cough* unicode *cough*

Windows uses Code pages - different bunches of characters for different languages. And MS-DOS - the command prompt is still stuck with 7-bit ASCII as the default character set.

To check your currently active code page, fire up a command prompt and type in chcp. My Windows installation uses English US as its primary language and the result of the chcp command is: Active code page: 437

To switch character code pages, the magical words are chcp 65001.

65001 is the Microsoft registered code-page for UTF-8. And all is well!

C:\work\cruisemaniac.com>chcp 65001
Active code page: 65001

C:\work\cruisemaniac.com>jekyll serve -w
Configuration file: C:/work/cruisemaniac.com/_config.yml
            Source: C:/work/cruisemaniac.com
       Destination: C:/work/cruisemaniac.com/_site
      Generating... done.
 Auto-regeneration: enabled
    Server address: http://0.0.0.0:4000
  Server running... press ctrl-c to stop.

####And then some.. Some chow on the topic of code pages before I let you be:

Fat controller or Fat model???

When coding up an app using the MVC model, how much of logic do you actually code up in the controller?

The controller’s job in an MVC setup is to pick up action requests from the user acting on the View, pass them to the model for data manipulation and pull out the new view to show to the user.

Now, the question in my mind is: How much of logic do you actually throw into the controller?

  • Is the controller supposed to have ONLY routing logic? * Is it allowed to know anything at all about the view and the model it is mediating?
  • Is the controller permitted to to have any session logic to quickly handle logged in / logged out users?
  • Is pushing any and all processing to the model the right approach?

Just a few questions that I have in mind…