How I found a bug in HackerEarth


I am not a competitive programmer. I love programming, but more so I love building things. As a result, I rarely participate in coding contests. Even when I do, I try to use languages like Ruby and Python just to see if I can do it my way, so to speak.

While trying a contest in Ruby, I realized that I could not use the ruby prime library. This is a standard library in Ruby for a long while, and HackerEarth platform runs on 2.1.1, which is quite new.

I reported this as a bug to HackerEarth in September ‘14. A quick reply from HE made me realize that they weren’t understanding the issue:

Modules like mathn or erb are part of standard library. They are available.

Try using, require ‘erb’require ‘mathn’ in code editor.
However 3rd party libraries are not available.

I decided to do some tests and check all standard libraries for their availability. For those unfamiliar with Ruby, this is how you load a standard library in ruby:

require 'prime'

Using the HackerEarth API, I was able to write some quick code that tested all expected libraries:

while read lib; do
  echo "Testing $lib"
  curl -s -d "client_secret=API_SECRET&lang=RUBY&async=0&source=$SOURCE" > $lib.json
done < libs.txt

Here libs.txt contains a list of all standard libraries. The above code is in bash, and makes use of curl. Parsing the results, I replied with the following:

Requiring the following libraries raises a missing error:

coverage - RE
extmk - RE
fiddle - RE
io/console - RE
json - RE
minitest - RE
minitest/benchmark - RE
minitest/spec - RE
mkmf - RE
objspace - RE
prime - RE
psych - RE
racc - RE
rake - RE
rdoc - RE
rexml - RE
rinda - RE
ripper - RE
rubygems - RE
tk - RE
win32ole - RE
xmlrpc - RE

HackerEarth admitted the issue (I posted code to replicate on github), and have since worked on it. I just ran the tests again, and only the following libraries are unavailable now:

curses - RE
dbm - RE
debug - RE
extmk - RE
gdbm - RE
generator - RE
iconv - RE
racc - RE
readline - RE
rexml - RE
rinda - RE
tk - RE
win32ole - RE

A few of these are understandable (win32 since HE platform runs on Linux, and tk, which is a graphical library). A few of these are unavailable in Ruby 2.1.1 (I copied the list of libs from the 2.1.3 docs).

Kudos to HackerEarth for fixing a bug that very few of their users would have faced. All the source code for this post can be found at github.

Note: This article was copied from HackerEarth because they are shutting down their notes platform.

I am offended

To start with, here’s a piece of art that is meant to offend you:

Bharat Mata, by MF Hussain

The above is an artwork by MF Hussain. Its was sold as an untitled work by Hussain to a private collector, but was named Bharat Mata later when it was sold in an auction.

Were you offended by looking at it? Maybe. Does it look vulgar and offensive to you? Perhaps. What should you do as a result?


Seriously, India. The right thing to do when you are offended is not to lynch a person to death, or to issue a fatwa against singing the national song. The right thing to do is this:

Flip the table

The right to get offended in India is a result of the way our constitution curbs the freedom of speech. However, these restrictions were not in the constitution that was passed when India was made a republic (26 Jan 1950). It was added as the First Amendment (ironic, I know), which passed in June 1951.

In the 18 months that passed between these two events, Indians had the right to absolute freedom of speech. I won’t go into the details of why both Nehru and Patel thought of bringing these restrictions (for the better of India), but needless to say, the reasons are no longer valid.

However, I found a curious piece of irony while researching this:

One of the prime opponents to the First Amendment restrictions was Syama Prasad Mookerjee, a long time RSS activist, founder of the Bharatiya Jana Sangh and widely regarded as the godfather of Hindu Nationalism.

And now today, 64 years later, these restrictions are getting enacted into even more draconian laws. One such law is Section 66A of the Information Technology Act.

Kapil Sibal, former union minister writes about it:

Allowing the government to regulate the internet is a recipe for disaster. Government being what it is, it would use such power to further its own ends.

However, he gives in to the diplomatic reasoning and writes further:

I know where I stand. I am for freedom of expression, but there are no absolutes in life. Limitless freedom contains within it the seeds of conflict. We must eschew conflict and embrace freedom, for peace and harmony.

Note that back in 2012, Kapil Sibbal had spoken in favor of Section 66A, citing it as a tool to protect women online. He seems to have reversed his stance since.

This is what Tushar Mehta, Additional Solicitor General has to say on the necessity of the act:

[…] every institution and every person right from the President can be subjected to criticism and it is people’s fundamental right to free speech and expression but such rights do not cover grossly offensive comments and posts on social networking sites.

AIB recently tested their rights by making a grossly offensive video and posting it on social networking sites. A lot of people were offended. The video was taken down as a result.

Did the people who were offended see the video? Yes, probably on YouTube. But the recordings are still floating around, and are available on torrents very easily.

You see, the internet is a resilient beast. You can’t control it, or bend it to your will. It does not run by your rules, and your sense of sensibility. It has no concept of right or wrong. It just is.

A nation where I am afraid to post critical views of the government or discuss events that might offend someone is not a nation worth living in.

The internet cannot be regulated. You might certainly think of it as possible, but we will always find a way.

If you are offended it is your problem, and frankly lots of things offend lots of people. - Salman Rushdie

I don’t think I will ever see the first amendment repealed in my lifetime. However, I’m gonna try my very best to get the Supreme Court to re-evaluate Section 66A as unconstitional and over-reaching.

If you want to let the government know of your thoughts on the matter, the Assistant Solicitor General (representing the Government in the case) can be reached at

Further Reading

This is a loose list of various references and readings on the topic.

Thanks to Shashank Mehta and Ravi Kishore for reviewing drafts of this.

Are you a fighter pilot?

As part of a pre job interview for a position as a security consultant, I was asked this question. The interviewer expanded the question further as :

Given the choice between a luxurious journey in a passenger jetliner (flying business class) and a thrilling trip as a fighter pilot, which one would you choose?

My immediate reply was (without a single doubt): “I’ll take the fighter jet, thanks.”

Then the interviewer tried to dissuade me from my choice: “Its not as glamorous as it sounds. Its a terrible job flying a jet plane. There are lots of complications, you are literally defying death, and even the pay isn’t that good.”. He then spent quite some time explaining the luxuries and comforts that we take for granted in a passenger jet, and those that aren’t available in a fighter jet. “You can’t even piss properly”, he told me. “And there’s free booze on the Boeing.”

Me (after some deliberation and moment of self-doubt): I’d ultimately like to have my own private jet, but I’m willing to strap myself to a 300 million dollar plane just trying to get there. I’d take that over a passenger jet any day.

For those who didn’t get the analogy: He was trying to convince me to join a high risk job, where I’d be working late nights doing what I love. But it also means giving up tons of luxuries and comforts that I could get at other companies.

I’m sure that I’m the fighter jet kind of person, I’m just having difficulty deciding what jet I wanna fly. If you have an opening for a Full Stack Developer/Security Consultant, shoot me a mail.