Monday, December 07, 2015

Thanksgiving in US

Because of being employed by world's largest online retailer, I was aware of the custom of Thanksgiving as celebrated in USA. Mostly along the lines of large sales volume and other retail details. Its only after coming to the country, I realized it is indeed a big deal for folks here. People queue up, often overnight, in front of stores. The stores themselves have deep discounts on large ticket items, mostly electronics. The madness and the rush when the store opens in unbelieveable. The closest from my personal experience is visiting pandals in Kolkata during Durga Puja (popularly known as "pandal-hopping").

Unlike Indian festival dates, which are calculated based on position of celestial bodies, Thanksgiving date is defined as "fourth Thursday of November". Its amazing how the dates of what originally was a harvest festival has been adapted to ensure a long weekend. This indicates that the holiday in its present form was standardized after a 5-day work-week had been established. But what is more amazing is how retailers have turned this into a shopping festival. An onslaught of flyers, banners and emails ensure that people get to know of this special time. Mailboxes (physical and email) are filled up with information of "deep discounts" from all merchants. The frenzy is such that sales volumes drop on preceding weeks in anticipation of deals.

Unfortunately these are of little use to people who want only a specific brand/make/model. More often than not, those would not be available. In the rare case that they actually are, its hidden under the pile of other products and tend to sell off fast. Its mostly the things which are highly priced (as a factor of their intrinsic value) which go on sale.

For discerning folks, this provide for a great opportunity. Prices on used goods drop on auction sites. Another advantage is the relative emptiness in the neighborhood touristy places. I would not share the items I bought, but here are few nice shots from that weekend.

Weekend getaway Big Sur, 20151126-27

Wednesday, June 24, 2015

Possibilities with dark sunglasses

Aren't you bothered when talking to people wearing dark sunglasses? You know what I am talking about. The ones so dark you can't even make out the eyes. Its weird to talk to a person without being able to see their eyes.

In India, like many other places, its customary to greet someone with a smile and raise eye-brows. It spooks me out when people do this wearing dark shades. Then during conversation you have no clue which way they are looking. For all you know, they might as well be rolling their eyes at you!

There is also a great tactical advantage to not letting others see your eyes. Significant amount of brain is hooked up directly to our eyes. Following a person's eyes is one of the easiest ways to figure out their thoughts. Security folks regularly use this. Next time take a look the security personnel in TV news clips, all of them wear dark glasses.

Now think about all the awesome things that you could do with a pair of these. Use it to your fullest advantage. Stare at random things during those boring conversations. Next time you meet that annoying neighbour or the complaining colleague, instead of listening to their rants, you can be checking out that PYT who passed by. For extra points, you can try winking too. Just imagine the possibilities ... !

Frankly, I don't know what bothers me more, not being able to see the eyes or the perceived advantage I feel they have. Guess I should get a pair of those super-reflective polarizing sunglasses and give this a try.

See others comments in Reddit | Facebook

Thursday, June 11, 2015

Don't drink iced tea with a straw !

It’s only because ice floats in water that we can add ice to a drink in room temperature and instantaneously get a chilled effect. The ice melts and you taste the cold water. Well you might think it’s obvious. And you are right. It is. But just pause and think for a bit. Except for water, all other solid materials have higher density than their liquid counterparts!

Now think what happens when you drink iced tea with a straw. You are drinking the concentrated and not-so-chilled part of the drink first. And it tastes watery at the end.

Somebody will point out that it is the property of cold things to come down and hot things to go up. And they are partially correct. That is how earth is cooled. But that is due to hotter things having lower density like hot air.

If you have made it this far, you must be wondering what's the point behind all this? I was only marveling at how coffee shops serve iced drinks with a straw. At the beginning you are thirsty, so you drink a mouthful. Only after your initial thirst is quenched that you slow down. As and when you slow down, the ice gets time to melt and dilutes your drink. After a while you don’t like the watery taste and order a second round!

Link to the post on reddit and facebook

Sunday, October 26, 2014

Washing Machine and Rain

I am sitting here in my balcony. Sipping coffee while looking at the rain outside and thinking:

Its raining again! Somehow it has to rain whenever I switch on the washing machine. Is there a link between the machine and the clouds? Well you never know. Maybe it will be the next big news in Scientific American,
Scientists find strong evidence linking washing machine usage and rainfall 
... In a recent study published in the Journal of Scientific Mumbo Jumbo, researchers from University of Blah throw light onto the possible correlation between rainfall and washing machine usage. Based on a study lasting over a decade, researchers have found strong evidence suggesting ...

I know. It sounds crazy. But all I am saying is that you never know.

Or maybe I only remember instances of rain when it causes me inconvenience. Or maybe the coffee has hallucinogenic properties.

Link to the original facebook post

Saturday, February 08, 2014

How to avoid triggering the circuit breaker

Heard the following story from a colleague at Amazon:

This happened during the time I was at Amrita University. Back then the hostels did not have power sockets. This was the time when cellphones and laptops were beyond the reach for most Indian students. One day some guy managed to get his hands on an electric heater and wanted to cook in the hostel. Some searching led the guys to a socket in the corridor. Switched on the heater. There was a pop sound somewhere down the corridor and no power for that entire wing. These would be engineers soon figured out that the circuit breaker was getting triggered by the high current drawn.

Ordinary folks would think better and shut down the heater. But there was this one guy (name withheld for obvious reasons) who had this great idea. He proudly told that he will "fix" the circuit breaker. He went down the corridor and asked the guys to switch on the heater. This time there was no "pop" noise. The power went off for the entire wing. And there was a burnt smell.

Turns out that the fix was to hold the circuit breaker to the top contact and not let it "trip" (disconnect). The high load just burnt out the wires instead. No electricity for these guys for a week.

Photos of Bogmalo, Goa

Fishing boat at GoaNon-rolling stones gather all the mossNearby beach to BogmaloBogmalo Resort CorridoorBogmalo Resort Corridoor20130805-IMG_3728
Bogmalo Beach, Goa, a set on Flickr.
Some pictures of Bogmalo, Goa from August 2013. Went there from Amazon for a branding event at BITS. Wonderful campus, great beach and awesome seafood made this a very enjoyable off-season trip to Goa.

Monday, February 03, 2014

Pics of squirrels clicked in BTM

20130414-IMG_2347squirrel on coconut treelooking for mateSquirrel20130414-IMG_2349


Squirrel, BTM, a set on Flickr.
Here are some of the non-blurry pics of these cute, super busy furry animals. Clicked from the verandah of my BTM home in April 2013.

Thursday, January 30, 2014

Mysore Trip with ml-bln

mysore palace main gateStarting of journey at 0630 from WTC, 20140125crocodile_1hanging batbird_in_flight_1
bird_in_flight_2birds_1bird_in_flight_3birds_2bird_3bird after bath
bird in flightbird_6bird_7gabbar singh :)liliyanature_1
padel in waterbaby crocodilelazy crocodilesleeping crocodilebigyanbird
Mysore Trip with ml-bln, a set on Flickr.
Pictures from my trip to Ranganathittu bird sanctuary and Mysore palace with my colleagues from Amazon India and Berlin.

Via Flickr:
5 of us from the ML-Blr team went on a day trip with some members of the Berlin team. We stopped at Ranganathittu Bird Sanctuary and Mysore Palace.
20140125

Sunday, January 19, 2014

Not posting for a year

Will start this post with an apology. Its been more than a year since I last posted. Lots of things have happened since my last post. {got married, moved to a different work team, changed house twice}. The principle reason however is different.

My recent posts have been mostly along lines of "how to do X" where X is some interesting thing which I stumbled upon recently. There is no central them to X. Mostly it revolves around Linux/Unix, Internet and ML; basically my work. With the popularity of Q/A sites like stackoverflow, "how to" kind of posts have been rendered unnecessary. A look at my blog statistics convey the same theme. My original contents like GATE solutions still attract majority of visitors to the blog; mostly from search engines.

Hence, from now onwards I will try to refrain from posting simple how-to questions from my work related fields. But original content is rare. I will continue posting on  topics like:


Anyways, will be posting more regularly now.

Saturday, August 25, 2012

Colors in bash

Bash is capable of generating a huge spectrum of colors for text. Here is a small code in shell script which generates all the 256 different colors bash can render:
for i in {0..255}; do printf "\x1b[38;5;${i}mCLR-${i}\t"; done; echo; reset;

The last echo is for printing a blank like after the output, without that the command prompt would appear at the end of the output. More import is reset present at the end, without which your terminal might not go back to the original settings.

In case you are wondering how to print colored output in terminal, please read:
Now you have a number to color mapping which you can use to specify your favorite color in config files of various command like applications like vi and tmux.

Sunday, July 22, 2012

ROC Curve

My recent work related to Text Classification got me introduced to ROC Curve which is a very effective way to compare classifiers against each other and decide on the cutoff value for classes.
Its best defined with a simple example. Say you have a binary classification problem. You have generated 3 train-test datasets from the original data. Say you are using Support Vector Machine (SVM) as the classifier. After training SVM on all the three sets, you want to select the "best" of these three. How do you go about it?

Here's where ROC comes into rescue. Sort the output of the SVM and compute True Positive %tage and False Positive %tage so far for each data point and plot this in x-y graph. The area under the curve will give you a way to measure the effectiveness of each classifier. Moreover you can use the nature of the graph to establish your positive and negative class boundary.

Here are a few links to know more about ROC curve:

Thursday, May 24, 2012

tmux, a Better Terminal Multiplexer than screen

Recently I encountered a program called tmux which claims to be better at "terminal multiplexing" than screen. I did not have any idea about "terminal multiplexing", but I had been using screen for quite a few years now. tmux promises to be better that screen according to the tmux sourceforge page. This got me interested.

I installed tmux, and have been using it since last 2 weeks. My experience has been great except for a minor hiccup between vi and tmux. I thought of writing a small tutorial, but I feel there are better and more detailed ones that I would have the patience to write; not to mention we all "stand on the shoulders of giants". So I am going to point you to the online resources:
Finally, tmux is quite good and it gives some features not in GNU screen. Unfortunately, tmux is not as popular as screen, so you should be able to use both. Here is my contribution to the community, a cheat sheet with popular commands for both tmux and screen together. Please note that I use Ctrl+a as my tmux hotkey rather than the default Ctrl+b. Here is the thing you have to add to your ~/.tmux.conf to achieve this:
unbind C-b
set-option -g prefix C-a
Copy-pasting in tmux is also quite easy. You can copy from any part of the command window. Go to the copy mode by Ctrl+a PageUp. Move around the terminal using arrow keys. Ctrl+Space to start marking the text from where you want to copy. Use arrow key to select text. Alt+w to copy the text. Paste text using Ctrl+a ].

Thanks for reading.

Wednesday, May 23, 2012

Reload .inputrc at runtime

If you have been playing around with bash for some time you must have changed the file .inputrc sometime. I have changed it several times mostly for Del key and auto-completion trick. However every time I change it I have to logout of bash for it to take effect. Here are two different ways to do the same without logging out of the shell.
  1. Keyboard shortcut : Ctrl+x followed by Ctrl+r
  2. Script : bind -f ~/.inputrc
Here is an excerpt from my .inputrc which many others might find useful:
"\e[1~": beginning-of-line          # home
"\e[3~": delete-char                # delete
"\e[4~": end-of-line                # end
"\e[5~": history-search-backward    # page-up
"\e[6~": history-search-forward     # page-down
Hope this helped you.

Tuesday, April 17, 2012

Brilliant 8-phase multi-quine in ruby

Wikipedia defines quine as:
A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
In layman terms, it is a program that when executed outputs itself. Like a C program outputting its own source code. Kleene's Recursion Theorem proves the existence of quines in any Turing Complete Language. Its a good exercise to write one in your favorite language. Its fascinating to see quines.

Today morning my friend Umesh showed me this brilliant piece of ruby code that behaves as a Multi-quine. Link to original post by its author. Here's a listing of the same:



Save it as "test.rb" and run the following shell script:
while true;
do
    clear
    ruby test.rb | tee test2.rb
    mv test2.rb test.rb
    sleep 1
done

You will be able to see the picture changing after every 1 second and returning back to the original after 8 seconds. Note that when you run test.rb, it produces the output which is used for the next iteration. The shell script code lines 4 and 5 runs the code and uses the output of the code to replace the original code.

After being amazed by the beauty of this piece of code, I am not trying to figure out how exactly does it achieve this result. Someday I will post the same code with indentations and explanations in this blog.

Tuesday, April 03, 2012

Make Your Own Command-line Calculator with bc

I do not know about you, but I am bothered by the lack of a proper command line calculator for doing small single line calculations in Linux (or any other UNIX or Mac system). Sure bc is there but it does not support floating point by default, so one ends up writing things like:
echo "scale=3; 22/7" | bc
which is quite cumbersome for day to day work.

To subvert this trouble, I wrote the following two-liner and saved it as "calc" in a directory in PATH:
#! /bin/bash
echo "scale=3; $1" | bc; exit
Then do a "chmod +x" on the file to give it execute permission. This does the same thing as the above script, but is way simpler to use:
calc 22/7
The command "scale=3" was to instruct bc to print upto 3 decimal digits. You can change it as per your requirements.

The bc utility can do way more than this simple calculations. For example it can handle different bases and load functions from files. To know more about its capabilities try the good old "man bc" in terminal or read an online reference like this one on about.com.  You can read more about its advanced capabilities from an old but quite relevant article in LinuxJournal "bc: a handy utility".

Disclaimer : Although the script was by me, the idea is not new. In fact a lot of my colleagues use similar scripts for their own daily work.


Monday, March 26, 2012

Do-while loop in Ruby

As you know, I'm trying out Ruby. While solving one of the exercise problems I felt the need for a do-while loop. Unfortunately ruby has no documented do-while loop. Thankfully, somebody has already asked this same question in stackoverflow : Is there a do-while loop in ruby?

Here is a demonstration of a do-while code in ruby:


Remember that using undocumented features is always ill-advised !!

Saturday, March 24, 2012

I'm trying out Ruby

I have always been interested in programming languages. After coding in a plethora of mainstream procedural languages C, C++ and Java, last year I tried my hands on Python. Apart from being an enjoyable experience, learning Python has paid off quite well while building prototypes in my work. This prompted me to try learning some other languages.

While searching for a cool language to try out, I came across the book, "Seven Languages in Seven Weeks" which promises to go beyond the simple tutorials and "introduction to" and introduce some non-trivial aspects of the language. I have started from page 1 and am exploring Ruby. So far the author has kept up his promise.

Ruby has got very friendly constructs and syntactic sugars like:
  • the keyword "until", which is simply a negation of the popular "while"
  • instead of simple "for" loops, constructs like "10.times"
which gives a warm and friendly feeling to the language. Besides the book mentioned above I am using "Programming Ruby 1.9" from the same publishers for a reference.

Friday, March 02, 2012

Demystifying bulk SMS sender name

With the high penetration of mobile phones, companies have started sending out automated sms. I have always wondered about the cryptic sender names. Careful observations about the sender name reveals:
  • all letters are in capitals
  • name format is **-******
    • the first two letters seem random
    • followed by an hyphen
    • followed by a six letter
  • last six letters seem to identify the sender name
    • for example presently, "SBIINB" represents SBI bank
  • sometimes the same sender can send some sms with different combinations of first two letters
    • SBI sends sms as "BX-SBIINB", "TD-SBIINB" etc.
Some researching in internet points out that my observations about the last six letters are correct. The first two letters before the hyphen represents service provider and the region from which it is sent. For the examples above:
  • "BX" = BSNL from Karnataka
  • "TD" = Tata from Delhi
View the official list of bulk sms codes in the NDNC website.

Saturday, February 18, 2012

GATE 2012 CS solution

I had appeared in GATE 2008 and 2009. After that I had not been interested much in GATE. However this time (GATE 2012) a close friend of mine appeared for the same, which got me interested again. Here is a solution set to the GATE 2012 Computer Science paper. I have solved question from Algorithms, Automata, C programming, Probability ... in short, the topics that I enjoyed enough to remember them after 2 years.

As I mentioned earlier, I have not appeared in for the examination. I got the question GATE 2012 CS and IT question set C from a fellow netizen. Please download the paper first as I will be using that as the reference for objective type answers.

2 years earlier I had posted solutions to GATE 2009 CS question paper. Comments and suggestions from that post made me realize the importance of explaining every answer. Feel free to ask questions if you need further clarifications.

GATE 2012 Computer Science and IT solutions to question set C
  1. b
  2. -
  3. -
  4. b
    • Draw the sine graph for the interval. Only one minima at 3*pi/2 where sin(x) = -1
  5. c
    • fork() will spawn off a new child process every call. Three calls to fork() results in 8 processes, out of which one is original, other 7 are children.
  6. b
  7. a
    • Obviously. Look at f(X,Y) and compare it with X
  8. c
    • Balanced binary search trees require log (number of elements) time to search
    • log (n*2^n) = log (n) + log(2^n) = O(n)
  9. -
  10. c
    • Standard switch case behaviour called "fall through", when the break statement is not there
  11. c
    • Look into any DB book, I studied Navathe.
  12. -
  13. c
    • Do the checking manually
  14. c or d
    • 1 is false, 3 and 4 are true
    • not sue about 2
  15. -
  16. -
  17. c
    • follows from definition of CDF
  18. -
  19. d
    • 4 bit multiplier requires 2x4 = 8 bit input, i.e. 2^8 set of inputs
    • multiplication of two 4-bit numbers will result in at most 8-bit result, so 8 bits for every multiplication
    • 2^8 * 8 = 2^11 bits = 2 Kbits
  20. c
    • Average case is at lease as good as worst case
      • A(n) better than W(n) :: Quicksort
      • A(n) same as W(n) :: Heapsort
  21. c
    • Draw it and find out. They key thing is "any embedding of G on the plane"
  22. d
    • T(n-1) for moving n-1 disk to aux from source
    • 1 for moving the n-th disk to destination
    • T(n-1) for moving n-1 disk back to source from aux
  23. b
  24. -
  25. c
  26. -
  27. --
  28. -
  29. b
    • examine the cases:
      • P(6 in first throw) = 1/6
      • P(1 in first throw followed by 5 or 6 in second throw) = (1/6)*(2/6)
      • P(2 in first throw followed by 4, 5 or 6 in second throw) = (1/6)*(3/6)
      • P(3 in first throw followed by 3,4, 5 or 6 in second throw) = (1/6)*(4/6)
    •  summing up = (1/6)*(1+2/6+3/6+4/6) = 5/12
  30. -
  31. -
  32. b
    • b'd' -- group the 4 corners
    • b'c' -- group the a'b' columns to 2 cells with the top 2 cells in ab' column
  33. a
    • MST algorithm does not depend on the value of the weights, it depends only on the relative ordering of the edge weights.
    • Ranking remains unchanged as all the weights are >= 1
  34. b
    • I did it by hand, don't know if there is a shortcut
  35. b
    • Observe the graphs
  36. -
  37. d
    • observe that q is a dead state, so anything beginning with 000 should go to q -- A and B gets eliminated by this logic
    • after 10 if there is a 0 the state should move to 00 state, so D is correct
  38. a
    • look into any Data Structure book
  39. -
  40. -
  41. -
  42. -
  43. -
  44. d
    • Dijkstra's algorithm probes the best solution so far
    • Thanks to Shivam for pointing this out
  45. b
    • merge-sort takes O(n log n) comparisons
    • here to compare two strings you need O(n) time, so O(n^2 log n)
  46. c
    • represent a cycle by a permutation of 4 labeled vertices
    • cycles are identical if one is a rotation of another
    • same cycle of length 4 can have 4 different representations each starting with a unique letter
    • (6 P 4) / 4 = 90
  47. -
  48. -
  49. -
  50. c
    • line 2 has a static variable, which retains the old value when he function is called again
  51. d
    • "auto int" is same as normal "int"
    • "register int" is same as normal "int" as far as value retention is considered
  52. -
  53. -
  54. -
  55. -
  56. -
  57. a
  58. -
  59. a
    • maxima-minima problem
    • maximize the profit where, profit = 50q-5q^2
  60. b
  61. b
    • Given:
      • P(X) = 0.6
      • P(Y) = 0.4
      • P(R | X) = 0.96
      • P(R | Y) = 0.72
    • P(R) = P(X) * P(R | X) + P(Y) * P(R | Y) = 0.864
    • Applying Bayes Rule:
      • P(Y | R) = [ P(R | Y) * P(Y) ] / P(R) = 0.333
  62. c
    •  follows from fundamental definitions of mean and standard deviation
  63. -
  64. -
  65. b
    •  another maxima-minima problem and the function is already given, just maximize y

Please leave a comment if you were helped by my effort. Feel free to ask questions if you need further clarifications or have found some error in my solution.

Wednesday, February 15, 2012

Check who logged in to your Linux system

Linux (and all other unix clone OSs) have a handy way to let you know who are the users who have logged into your system. The command is "last". This command uses the file "/var/log/wtmp" and displays a list of all users logged in since the file was created.

I use it as:
last | grep -v -e bigyan -e reboot | less
Grep -v gives the complement of the results that it returns normally. The output of this command contains:
  • username of the user who logged in
  • terminal used by him/her ... pts/number
  • IP address from which logged in
  • Time of loggin in
  • Time of loggin out
  • duration logged in to the system
Read more usages of "last" command here. be sure to check out its cousin command "lastb" too.