A place that was once Malgudi

For a generation which grew up on doordarshan, Malgudi days was equivalent to an epic, no less important than the Mahabratha or the
Ramyana. Shankar Nag’s Small Screen adaptation of RK Narayans writing was a very fitting tribute to one of the greatest Work of English Literature from India. Complete with S Vaidyanthans beautiful background score, RK Laxman’s Carrigraphs or master Manjunath’s depiction of the mischievous Swanithan. But Nag achieved artistic perfection by bringing Malgudi to life, which quite arguably  would have been very close to Narayan’s Imaginations.

Malgudi could have been any small town in south India, but Shankar Nag’s imagination choice was a tiny hamlet  named  Agumbe in the Shimoga district of  Karnataka.  Situated in the western Ghats and  with one of the highest rainfall in India, second only to Cherapunji, Agumbe still remains a nature lovers paradise. It was in this small village that Malgudi came alive, The Town square, Swami’s School and much of Malgudi was shot here. The tile roof building and lush country side must have made it a very ideal candidate.  The televised images of the ‘Name less’ and lawleys statute is soldered into us as if it was exactly as in Narayan’s head. Such is the power of Television , that it paints a beautiful graffiti  but leaves little to our imaginations.

The reason to not only see it but also experience it is what made me go to Kasturi Akkas, Doddamane in the center of Agumbe. This and the Agumbe center square is the only thing that remains of Nag’s Malgudi. The house is currently converted into a home stay for flashy tourists like me and the hosts were more than welcome for any random stranger to go check out their house. Although I was out rightly violating thier privacy they were more proud of their heritage than irritated.  An old Man sitting in the veranda proudly explained me how the house has been used for shooting not only TV shows up also Movies more than a couple of times. Hearing the Man I continued on my journey experiencing a piece of Malgudi.



Lesser know AngularJS directives

I have been working on Angular for the past few months and have quite fallen in love with its approach to frontend development.One of the most awesome things in angular is its approach towards creating reusable HTML attributes and elements through ‘Directives’. Along with letting you write your own custom directives, angular ships with a lot of default directives. while some are helpers like ng-show,ng-class
others ng-model ng-src are bound with angular internals. This blog post is a list of a few lesser known yet useful directives.


From an aesthetic point ng-if works similar to ng-show and ng-hide, but instead of hiding the Dom element it selectively adds or removes it from
the DOM tree based on whether the expression supplied it true for false. This is use full because unlike hide and show, the removed element
will not be collected when using css selectors.

While in ng-repeat, we can selectively add classes to the repeated element based on whether the index of the element is odd or even.
Bonus:$index gives the index of the element in the iterator.

ng-change lets you to trigger a function or evaluate a expression when the text changes in the particular text box. For the ng-change to work,
the text box should be binded to a model.

db-click handles double click events within an element and lets you invoke a function or evaluate a expression when it is done.

Lets you add inline styles to your elements. although inline styles are evil and should be avoided, this cool as you can dynamically update
your style attribute values based on a model binding.

The pluralize directive lets you pluralize your content based on en-US localization rules.


Based on the value of members_count. member or members is rendered.
When the browser renders HTML if AngularJS is not loaded completly, the bindings will show up as very ugly curly braces.
This directive acts as blanket from displaying angular binding syntax before Angular JS is loaded into the browser.
Using this directive in your main pages is a must.

These along with many other built in angular directives give us a hint of what angular project philosophy is and where it is heading towards.
Making Common UI events more declarative, reusable and decoupled from the application logic.

Parallel processing in Ruby

Parallel Processing can be achieved in two different ways, multi-core and single process threaded architecture. In a Multi core environment independent operations are shared between multiple CPU cores so as to obtain considerable improvements in performance. A single core threaded setup uses a single process with multiple threads for each individual operations using thread context switching for switching between the execution of different threads.  Threads are ideal where operations wait for longer times during I/O operations. When one Thread is blocked for I/O  a context switch takes place to another thread.  This results in collective improvement in performance.

A very simple example of using parallel processing(Threaded or Parallel Processes) is by the gem Parallel.

Note: Using Threads are dangerous and could result in actually slowing your execution if done wrongly be Warned.

The power of social network and online communities

It all started out with a normal tweeted link for Wikipedia donations. For the immense respect i have for Wikipedia, I immediately went over to the link and donated a very meagre amount. I also impulsively tweeted the link. A couple of minutes later I had a tweet poped on the timeline indicating that  a former colleague  had also donated.  Quite sure that my tweet had triggered his donation I decided to post it on facebook just so that word would spread. What followed was quite overwhelming. People where persuaded by the link I shared and it not only triggered a lot of donations followed by a comment “done”, but also a lot of shares of the link with a thank you comment. This got me thinking of how wonderful the internet has made the world and the amount of potential online communities have to make a real impact on humanity. I am not bragging here that my sharing of a link triggered so many donations. But it did get the word across and it gave us all a sense of belonging to one. A common cause for the betterment of all of us.


Why riak might not be the DB for you

Riak at a first glance seems like a down from the heavens database of the future. Highly available, easily scalable and completely fault tolerant. We had used riak for a semi relational(our biggest mistake) application and these are a few problems we faced.

– Riak isnt your ordinary database its a key value store, its extremely hard to even write a simple user management system using riak. For example  searching is possible only based on the primary key of the bucket.

– Riak kept crashing for no apparent reason with logs showing nothing at all. With the app in staging the database kept crashing quite often with a CPU usage of 100%. We had hosted it on a 12GB machine, hence resources wasn’t  the problem.

– Although the instructions for creating a cluster of nodes was easy, adding new nodes to the cluster once the clusters had some data was almost impossible. The data did not replicate properly and the nodes kept crashing.

– Riak had a interface for indexing and searching the index using a solr like interface. One of our critical feature was relying on this. The search was returning the right result on the development and staging machines.  The Riak setup on the beta machine had a mind of its own, it never returned the right results

– Riaks logging system is horribly bad. Example debug message: {:fun => pre_commit}. Some one tell me which language is this?


The mistake we made

We cannot blame riak completely for our failure. We made this huge mistake of using riak as a relational database. It probably would have been ideal where there was huge amounts of data involved and queries involving map reduced where needed.



What you need to consider this isnt a rant on raik(May be except from the crashes and the logging), there are so much praise for riak out there, one mud sling will not change that. What the message for you from this is that, be completely aware why you would want to use riak in your application. Rather then trying to use a hip new database.

After weeks of sleepless night we finally moved to a different database(name not given to prevent controversy) and we  have not missed our sleep for the past few weeks.

To the abode of the gods

Very often in life we talk about doing that special thing after which we can strike it of from our bucket list. Quitting  your job to start that company , going on a world tour or something crazy on that lines. But it so happens that you only talk of doing things and never really end up doing it. For me its always been going to Himalayas, right from child hood my imagination had been captured by all the mythology, literature and off course the images. I had never really worried about when i would visit the hills (an apt romantic reference), until the day i got this call and voice from the other end ” We are going to the himalayas are you coming?” “I need some time to think” “tell us within four days,we have to book the tickets”. A cold feet attack and i was conjuring up all reasons as to why i will not be able to join in the trip, Leave from office? money? fitness? this seem so unreal, I am i really going to do it?. Finally all  doubts laid to rest the trip still seemed unreal. I would never imagine i would strike this off so early.

I really want to write more about the trip. But having re written the post a 100 times i could not come up with something which would do justice to the trip. Next trip I am going to carry a book with me which will capture the emotions as they will experienced. In case you landed here expecting something have a look at this facebook album.


Riak, Fulll text search with ripple

One of the major disadvantages with Riak’s key value store is normal active record type search is present only using the bucket key.

For example a search like

User.where (:active=>true,:role=>"admin")

is not available in Riak. There is a simple work around for this, Riak full text search.

Riak Search is a distributed, easily-scalable, failure-tolerant, real-time, full-text search engine built around Riak Core and tightly integrated with Riak KV.Riak Search allows you to find and retrieve your Riak objects using the objects’ values. When a Riak KV bucket has been enabled for Search integration (by installing the Search pre-commit hook), any objects stored in that bucket are also indexed seamlessly in Riak Search.

The Ripple documentation on using riak search isnt straight forward for a Active Record newbie, after a little digging around I got it working.

1. Enable Riak search in app.config.

By default  riak  search is disabled. Enabling riak search is as changing a false to true in the app.config

<pre>{riak_search, [{enabled, true},]},</pre>

2.Index the bucket for which you want to use Riak search
By default none of the buckets are indexed, you have to tell riak which buckets you have to index.
From the console run.


This will make index any new entry to the bucket. Please note that any old data already present in the bucket will not be
indexed by this.

3.Searching using lucene query
Now we can use a lucene query to search the indexed data.


This creates a client object for riak.

query="role:admin AND active:1"

A lucene query for searching where role is admin and active is true


We use the method search to run the lucene query on users bucket, this will return a JSON result.

4.Params for search
The search methods takes an extra optional argument as hash where we can specify certain options.

  • df the default field to search in
  • ‘q.op’ the default operator between terms (“or”, “and”)
  • wt (“json”) the response type – “json” and “xml” are valid
  •   sort (‘none’) the field and direction to sort, e.g. “name asc”
  • start (0) the offset into the query to start from, e.g. for pagination
  • rows (10) the number of results to return
start and rows are neat little options which will let you paginate over your search results.