The happiest man alive!

I had once read about a man who was celebrated as the happiest man alive. I was intrigued, how dd they decide it? What was the metric ?
Upon reading ore about the man, I discovered that he was suffering from a neurological disorder (i can’t pronounce or write the name of the disease as its super complex). I was shocked. So they claim that the happiest man alive is a man with a sick mind?
Upon further investigation, I figured that his actual problem was his mind was not able to comprehend that visual information it received. In short, he did not understand what he saw. Interestingly, one of the effect was that he was not able to recognise faces! But he was not mad so his mind, upon observing further details like a peculiarity on a face or voice of the person was able to recognise who the person was but never did his mind see the face of the person.
I felt interested as it was all very cool sounding but I still did not understand why was he the happiest man. I mean here is a man who cannot recognise his wife when he looked at her and he was the happiest man? But finally, I figured that the real problem was that he was fundamentally a machine. He felt no emotion when he saw his wife because he never saw!!! He recognised her when she spoke but he never saw. He can see the red color of the rose but never can exclaim at its beauty. He was a living machine with absolutely no emotions.

I felt terrible but still, why the happiest man? the answer was stunning, Here was a man who has lost emotions and cannot perceive faces,but he did not know it. He never knew that his eyesight or mind has as issue. He had lost so much that he failed to realise what he lost!! So he felt no regrets , no remorse and was super happy ever!!!
The happiest man alive!

Rails issues with Spring

So, I have been merrily using foreman in my development environment and have been very happy using the environment variables.
So recently I created a new rails project and followed the same mundane procedure and when I did the coveted

foreman start

it started working just fine and life went on!

Suddenly, I felt the urge to check something in the rails console and I called my friend

foreman run rails c

and it loaded. But when I queried, it gave me an error saying

"Permission denied for relation..."

After a bit of googling and a lot of swearing and cursing, I was filled with frustration as I had no clue what’s happening. Then, I realized that rails console was trying to access the DB not using the env variables I had set but using the default postgres user! Elementary, wasn’t it?
But the this was a shocker as I had no idea what to do now. I was almost ready to go to the church for solving this issue when spring came in my life! Not the season but the preloader gem which is now a default in rails.
As soon as I disabled spring using

spring stop

my rails console started working like before and life was happy again!

The correct way of solving the issue however is to create a `’config/spring.rb` file with contents

` '.env'`.

Hope it helps!

Rails 4 authenticy token issue


Recently I was working on a simple rails application (Rails 4) and I create a simple remote form for a model.

Things were fine but when I submit the form using javascript, it gave me an authenticity token error:


I read up(googled) a bit and figured that one has to set crsf_meta_tags in layout and not doing this creates the issue. I thought I had missed it somehow but to my dismay it was there but still I had the issue !

The problem was that in normal forms(remote => false) , rails automatically sets the authenticity token but not so in remote forms. Now there can be many work arounds like suggested here.

But the most rails way ! of doing it is adding the following in application.rb:

config.action_view.embed_authenticity_token_in_remote_forms = true

Once you restart your server, voila ! it will work.

A good reading can be found here

Hope it helps !

Keypress vs keydown in jquery

In todays web world, forms and input bars are very important. We all use searching and filtering in our applications. The easiest and obvious way to do this while using JS(jquery) is binding key events to the search bar.

The event I usually bound was ‘keypress’. This is fine and works good. But the actual meaning of keypress , in its original form in IE world (!!!!!) is the event which actually adds some value in the input field. Some keys like backspace, delete, clt etc do not add any value and hence are not detected by keypress event.

These are important keys as often in filtering when the input field is empty, we might want to show all results. The user might type some query and delete it and hence detection of such keys is important.

To avoid such confusion, one should always use keydown or keyup events. These events detect events where any key is pressed and one can use e.which to determine what key is pressed and perform action.


I personally like keyup becuase keydown event is called just after pressing the key and hence value of input field lags one character behind the actual input.


Hope it helps !

I have a question !!!

I of-course know the fact how unfortunate I am. It is something I do not think I can change. Its a quality I have , like my blood group !  Cannot do anything about it.  Do I regret it ? …

I clearly remember the precise moment when I realized the exact nature of of my misfortune. I was told the unfortunate news in front of the world ! Ofcourse, its my humble duty and desire to inform the user that world for me at that time was the class I was studying in. Admitted in a reputed university, I was merry making in the cold weather of this glorious and wonderful city.The lecture hall location in the university, I promise were built by a student as the view was impeccably astounding. Breathtaking I must say ! The glorious mountains stood on one side of the building and on the other side, was a vast and deep ocean. As enigmatic was its nature, it was mystifying. Who knew , what ,lies beneath the deep fathoms of the water body. I was wondering , the same thing as how the mountains must have risen and these enigma of the ocean , we see everyday ,created.

On this precise moment, a stern, knowledgeable  voice fell on my ear. He asked “Do you agree?” . As human instincts are, and more on work here were the student instincts and I gave the most obvious answer “yes…ofcourse sir”, fearful, that if I said otherwise, I have to answer many more questions !

But as brilliant these highly developed , all knowing beings called “teachers” are , they , like the elves , know whats in the subjects mind. So, this voice (more sarcastic than stern now), enquired in a very curious tone, “why so ?”( I wish teachers saw some movies, they would know how to act curious !). Having no clue what to say,I found myself doing the most polite and thinking voice acting I can  , and saying “because the book says so”. I think I mist have surpassed “tom and jerry” in making my audience laugh their hearts out ! I suddenly found myself, in the vast and luxurious office of the man having the stern voice and heard him “son , you are a good guy. But unfortunately, I do not find you curious for knowledge. To gain knowledge, one has to ask questions. Never take anything at face value. Ask whether what the author says, makes sense ?”. I was inspired ! I truly was. And that moment, in that office, I was a changed man ! I was a inquisitive person now.

I went home. Like my habit of many years, I started watching cartoon(yes, i love them!) and to my delight, tom and jerry was being aired. I , usually laughed and had a great time watching this show , till today. I asked myself, can a cat fly an aeroplane ? Can a mouse build a bed of matchstick ? Holy crap! Can a mouse and cat walk on 2 legs and smile and own flats ? Can there be a city where cats stay in hotels ? Frankly, It made no sense and I switched it off ! Worst meal in years for me !!!

I ofcourse had no intention of reading my favorite books as I had anticipated the questions my newly reformed, inquisitive brain would ask. Superman, how is the discovery of a planet possible. Aliens with super powers ,  na, current science does not approve of it. Similar cases with Batman, arabian nights and all other books and stories I loved ! Even the great Tolkien was not able to answer my questions like how can a wizard live forever and where are the hobbits now.

So, I thought about watching some movies. I saw some “philosophically heavy” movies. I had assumed that atleast Shakespeare wont disappoint  me. But alas! Richard , the third, never provides the answer to as how can a mother hate her own child, however he is. How can a hump back impress a beautiful lady and how the hell he can do his corrupt things without anyone knowing ?

Atlast, I went to my granny. I told her, I cannot sleep and tell me a story , as you did when I was a child, so I can sleep. She readily started,”once upon a time, there was a king”. I stopped and asked her, who was this king, where was he born,  where and how many years he reigned , how many queens she had, how was the political situation in his kingdom ? Needless to say, I was thrown out of the room !

Next day, I  was in the class of the same stern voiced “teacher”. He was teaching us mathematics and I interrupted him as asked “why is the number one written as 1 ?”. I can clearly see his puzzled face (with linearly growing anger and irritation!). But I never got an answer.

Years have passed since and I have never got an answer to any of the above question. But I have the answer to one thing. Sometimes, not asking question and believing the person is helpful and enjoyable. We all enjoy the fairy tales and cartoons without asking questions. Try asking and see how it ruins the show !

I personally think, knowledge is not about knowing the right answer but the is about believing. Understanding. Asking questions and gaining answer will only add to information we have. Believing the thing and enjoying it will give us happiness, enjoyment, satisfaction. Knowing this is what knowledge is. We often confuse knowledge with curiosity and feel , if all our questions are answered, I will be knowledgeable.

Sometimes, the most knowledgeable are the ones who know nothing !


Resetting a Database in Heroku application

Recently I faced an issue when  I wanted to delete an existing database in an application deployed in heroku and create a new one.

I tried using

heroku run rake db:drop


I got an error saying “USER does not have connect privilidges”

The way to solve it is

heroku pg:psql

This logs in to your database and then type:

drop schema public cascade;
create schema public;

After this exit the prompt and type:

heroku rake db:migrate:reset

Hope it helps.