Sunday, May 31, 2015

Tuesday, March 31, 2015

Change

Its been more than 3 years now and to tell the least, I have learned a lot. Starting from structuring an application to deploying and tagging. Monitoring if parts of the application works and taking actions and analysing.

But during the last year my productivity and urge has gone down. Substantially. And I have myself to blame. I kept on latching on to my job and did not innovate and search for a new one or change something inside. Now I feel that my team has no trust in me and I am a useless part of the team. This has to change. This has to stop. And importantly I have to come out of this strong.

I intend to look to for opportunities in Berlin and shape my future for the best!

Look more at :-

Nodejs
React
Backbone
Docker
Chef
Swift
SQS


Sunday, March 1, 2015

No Deployment Friday Grunt Plugin

My First Grunt Plugin which just a simple thing! Stops a deployment if the day is a Friday (any day you define as a No Deployment day actually).

Have a look at https://github.com/dinks/grunt-warn-friday.



Tuesday, February 24, 2015

Nodejs on Heroku

After hours of effort and suffering, I was able to deploy a Node.js application to Heroku. This post reveals the effort that one has to make in deploying Node.js apps to Heroku.

I had been not using Heroku for some time now and wanted to host a test application on Heroku. This test application has a DB connection to MongoDb, uses the excellent Express Framework in the server side and React with Flux in the Frontend.

The first thing that one immediately notices is that its not that easy to add add-ons in Heroku anymore. They have a policy now with specifying a Credit Card / Payment Details even though I would only like to avail one Dyno. Previously I remember when I could add small add-ons to any Cedar Instance. That was so much cooler. I went on to look at OpenShift from RedHat, but that was a much bigger pain than I expected.

So back to Heroku. The first thing that I tried was to look at MongoLab for a simple Db hosting. They have a nice free developer plan and thats what I went for. The url for the DB went onto the ENV Config for the new Heroku App created. All fine until now.

Now came the actual building process. By default, if one does not specify the node and npm versions in the package.json file, it take the latest versions from semver.io. So for node it took 0.12.0 (https://semver.io/node/stable) and for npm 2.6.0 (https://semver.io/npm/stable).

I have many packages in my test application and it failed compiling for a package called node-sass@1.2.3. This was because of a known issue (https://github.com/sass/node-sass/issues/550) and was fixed with an upgrade of node-sass. But my dependency came from another package and could not upgrade it myself. So I had to tie the version for npm and node.

Once could do this using the engines option inside the package.json file.

"engines": {
  "node": "0.10.x",
  "npm": "2.3.0"
}

The next problem was with the actual building via grunt.

I use wiredep to manage the bower dependencies for me. It injects the dependencies very gracefully and in a fully configurable way. I use font-awesome too in the test app, but it never could add fonts to the dist folder after build. I only way I could do this was via a copy grunt task.

The dependencies are added to the html file (according to the bower:css, bower:js comments) after the build. One normally would like to have the built version served on Heroku. My builds all go to the dist folder and therefore my script start looked like this

"scripts": {
  "start": "NODE_ENV=production node dist/server.js"
}


Once the fonts got copied over successfully, the pending issue was to execute the bower install and grunt build task. This could be done via a post-install hook available with npm. One has just to write something similar to the line below

"scripts": {
  "start": "NODE_ENV=production node dist/server.js",
  "test": "grunt test",
  "postinstall": "bower install && grunt build"
}


The next problem that I faced was that bower and grunt were not a part of the dependencies list. Heroku by default has the setting NPM_CONFIG_PRODUCTION set to true. This means that the npm install only installs the items in the dependencies list and not the devDependencies list (logically). This meant that I either had to move all the grunt tasks and their deps to the dependencies list or set the variable to false. I preferred the latter

heroku config:set NPM_CONFIG_PRODUCTION=false

Now the postinstall was failing. It was not able to find the commands bower and grunt. This was because the commands never got installed globally. To go around this I made a shell file called post_install.sh which has these commands with the expanded paths (according to http://gregtrowbridge.com/deploying-a-node-app-to-heroku-with-grunt-and-bower/)

#!/bin/bash
./node_modules/bower/bin/bower install
./node_modules/grunt-cli/bin/grunt build

and the call from the scripts look like

"scripts": {
  "start": "NODE_ENV=production node dist/server.js",
  "test": "grunt test",
  "postinstall": "bash ./post_install.sh"
}


The grunt-cli was not a part of my original devDependencies list and it had to be added for the command to execute properly.

Now the application ran fine! Phew!

Saturday, January 24, 2015

JavaScript Currying

Generic currying in JavaScript is so great but it takes time to understand the code. Closures!

'use strict';

// subCurry(fn, 1)(2, 3)
var subCurry = function (fn /* Multiple arguments possible */) {
  var args = [].slice.call(arguments, 1); // Dont take the first argument
  return function () {
    var thisArgs = Array.prototype.slice.call(arguments);
    return fn.apply(this, args.concat(thisArgs));
  };
};

// curry(fn)(1)(2)(3)
var curry = function (fn, length) {
  // Length will only be available after the first curry
  length = length || fn.length;
  return function () {
    if (arguments.length < length) {
      var thisArgs = Array.prototype.slice.call(arguments);
      var combined = [fn].concat(thisArgs);

      return curry(subCurry.apply(this, combined), length - arguments.length);
    } else {
      // All arguments ok
      return fn.apply(this, arguments);
    }
  };
};

var fn = function(x, y, z) { return x+y+z; }

var mFn = curry(fn);
console.log(mFn(1)(2)(3));

Monday, November 17, 2014

Recent Reads

From the book "The Senior Software Engineer" from David Bryant

I had a code review once where the reviewer took issue with a stylistic decision that I had made. It had nothing to do with the underlying change or the correctness of the system. It was a classic "agree to disagree" situation and, as I was the maintainer of the code base, I kept the change the way I had done it. He complained to my boss, who then directed me to change it. NOT COOL.
You may encounter a similar situation when having your code reviewed. You may find that the reviewer is insistent that you do things "their way". This is a difficult situation, especially if the other developer is either senior to you or experienced
The first thing you do in this situation is re-think the change. Ask yourself if the reviewer has a point and if there really is something substantially wrong about the code in question. Chances are, the reviewer is right.
If you are not convinced of this, ask the reviewer to explain in more technical terms why you should make the change they are suggesting. Explain that you don't see anything substantially wrong and that, as the code's maintainer, you feel your style should be given more weight. This might either defuse the situation or lead to a deeper discussion of why the code is problematic. 
In the end, the reviewer may just forget about your code, but if the person is persistent and present roadblocks, you might need to just make their suggested changes just to move on. In the end, its more valuable to ship your code than to "be right" in a code review. If you end up taking this route, I would recommend you avoid including this person in future code reviews

Great read and great quote!  

Wednesday, July 30, 2014

Points and Animation


A simple code pen for travel between points and animation. Works for Firefox atleast!

See the Pen iebuc by Dinesh Vasudevan (@dinks) on CodePen.

Monday, May 26, 2014

seconds_until_end_of_day expires for Cache in Rails

A colleague of mine had to cache some html until the end of the day but found it difficult because cache expects expires_in which is relative. We cant pass an absolute Time.now :P

So we now have seconds_until_end_of_day in 4.0.2, but we use Rails 3 :(

But patching Time is simple

def seconds_until_end_of_day
  end_of_day.to_i - to_i
end

http://apidock.com/rails/v4.0.2/Time/seconds_until_end_of_day

Tuesday, April 29, 2014

Observers and Migratios

The past day we created a model migration and then added an observer for the model after the migration. Surprisingly, the observer (now added in the application.rb file) was loaded first by environment which then checks for the model and tries to fire a DB query for columns.

This fails and therefore the migration does not go through.

So for future reference, always migrate first and then add the observer! 

Friday, March 28, 2014

Chuck Norris Hubot

I stumbedupon an API which spits out random Chuck Norris Jokes and I ended up writing a smal hubot for this :)


Try it out Chuck Norris Hubot

Monday, March 10, 2014

Caching Simple Navigation

Morale: Simple Navigation is not that simple

We, in our firm, have different types of user navigation for different types of users. We wanted the flexibility of creating our navigation from the backend(rails) so that there is just one file to maintain with all configurations. Simple Navigation works great in this aspect.

The configuration is complex, but is absolutely generic. We have a couple of navigations to start with, for the normal application and when a user visits the application via the iPad.

The navigation for the normal user takes more than 500ms to render. NOT GOOD! We decided on caching the html. For this we need to split the navigation yet again. With respect to logged in users. Therefore we now have 4 types of navigation, loggedout-normal, loggedin-normal, loggedout-iPad, loggedin-iPad.

We also had some badges on the navigation for unopened items. The next step was to remove these from the navigation file. We created a notifications controller and wrote a small javascript, which takes data from the json response of the show method of this controller, and updated the corresponding sections in the navigation.

Now came the hard part. Caching.

We need to define keys for the Caching itself first.

For a logged out normal user, this would be quite straight forward. Get the locale of the navigation bar. All the users with the same locale got the same navigation bar.

For logged out normal users it would be a little tricky. We have some user specific stuff in the navigation bar such as the username. Therefore, we need the user_id. The user could change his locale and this would trigger a change in the updated_on field on the Users table. This would mean that we need to include this in the key as well. We have a specific link for backend services if the user has admin privileges. For this we need to evaluate the roles of the user. An MD5 has been used to facilitate this.

We need to Cache the non highlighted navigation bar for sanity purposes. Then we plan to highlight the section according to the pages that are rendered. For this we could either create a javascript to add the correct classes or create a stylesheet which highlights the correct section on verification of the correct classes.

We decided to create a stylesheet for this. The stylesheet reads the configuration from the simple_navigation configuration and creates the correct CSS. The file is a LESS file. We extracted the styles to highlight the navigation items into some mixins and used these mixins inside our custom classes.

The next tough part is the sub navigation. While this problem still lurks, we are trying to get away from the sub navigation altogether.

While this post is clearly not technical and is conceptual, this might help some others trying to solve something similar to this.

:)

Tuesday, January 7, 2014

Altering a MySQL Table

In a normal world without a lot of records, altering (adding, deleting columns and indices) a table is an easy job. Have a look at the syntax here.

Its essentially creation of a copy of the original table, applying the alter table to the new table and copying row by row until the end of the table is reached. The essential problem with this is that the row by row copy locks the table because we don't want inconsistencies while we copy. I.e. no writes during the copy.

If the table has lots of rows then this becomes a real problem.

It seems that those intelligent guys have a solution to this too.

One Approach : 
- Make changes on the Slave and Upgrade the Slave to Master.

Another (Facebook's Way) :
- Create a temporary table which is a copy of the main table
- Apply the changes to the temp table
- Add something which could be used to run changes on the temp table
- Copy data from the main table to the temp table
- Lock the main table
- Replay the changes on the temp table
- Rename the temp table to the original table after renaming the original table to something else

Phew

Thanks to Martin for the star in github

http://www.facebook.com/note.php?note_id=430801045932
https://github.com/soundcloud/lhm

Wednesday, December 25, 2013

Bucket Maker

After some days of research and work, I managed to create a gem which focused on Creating buckets for objects and querying them when needed

Have a look at https://github.com/dinks/bucket_maker which is a gem for Rails 3.2 -> 4 .

Comments most appreciated !

Thursday, December 19, 2013

That Great Feeling

Words can't express that feeling when you upload something to a community that everyone can use !

https://rubygems.org/profiles/dvasudevan

:)

Sunday, December 1, 2013

Module extensions 1.9 and 2.0

I did not know that this threw TypeError on 1.9 but passes for 2.0

x = Module.new { def foo; end } 
Module.new { define_method :bar, x.instance_method(:foo) }

From Rails !

Sunday, October 13, 2013

Fibonacci - Golden Ratio

In mathematics, the Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers in the following integer sequence: 0, 1, 1,2, 3, 5, 8, 13, 21, 34, 55, 89, 144 ...

I have always done the one with recursion (or iteration). But mathematics says we could do it with the Golden Ratio ..


Tuesday, October 8, 2013

Js for Sublime

Setting up a build system for Sublime Text for js

Let your interpreter be Node. If you don't have Node, I would recommend installing it from here. It uses the Google V8 Engine.

Open Tools -> Build System and select a New Build System
Name it whatever you want it to be (this will show up in the Build Options)
Add the following to it


 "cmd": ["node", "$file", "$file_base_name"], 
 "working_dir": "${project_path:${folder}}", 
 "selector": "*.js
}

The syntax could be understood from this link.

Restart sublime and open the file. Goto Tools -> Build System and set the build system to the name you gave.

Run Command + B and it will work !

All the build files go into /Library/Application Support/Sublime Text 2/Packages/User

:)