Anantha Kumaran random thoughts

jQuery documentation inside Emacs

Recently I found myself switching between Emacs and browser to refer the jQuery documentation. So I looked around and found XML dump of the jQuery documentation. Now I have the data and just have to figure out a way to display it inside emacs. Parsing the XML file every time to look-up a method documentation will be very slow. So I wrote a converter which will parse the XML dump and spit out elisp code. The generated elisp code will look as follows.

(push "$.grep" jquery-doc-methods)
 (quote (("name" . "$.grep")
          (("array" "The array to search through." nil nil)
           ("function(elementOfArray, index)" "..." nil nil)))
          (text . "The $.grep() method ...")
          (js . "$.grep( [0,1,2], function(n,i){
				             return n > 0;

Now all I have to do is configure auto complete to use this data and write some code to display the documentation in a buffer.

Emacs Tips

;; usage
;; (add-hook 'ruby-mode-hook
;;          (lambda ()
;;	    (local-set-key (kbd "C-x j") 'jump-to-view)))
;; keep the point anywhere inside a sinatra route and
;; press C-x j to open the haml file

(require 'thingatpt)
(defun jump-to-view ()
  "jumps to haml view"
  (let ((sentence (thing-at-point 'sentence)))
    (if (string-match ".*haml(?[[:blank:]]*:\\(?:'\\|\"\\)?\\([^\"\', \f\t\n\r\v]+\\).*" sentence)
	(let ((file (match-string-no-properties 1 sentence)))
	  (if (one-window-p)
	  (select-window (next-window))
	  (find-file (concat (project-root) (concat "app/views/" (concat file ".haml"))))))))

My Interview Story

written on 9th June 2010

I think I will never publish this post. Who knows, my mind changes very rapidly than I could imagine. But any how I will just write down my interview experience here.

I think it was February 2010, Infosys came to our campus. They selected around 150 students in our campus. They conducted two rounds. A General Aptitude(I will use GA hereafter) round and a HR round. Most of the people who cleared the first round cleared the HR round as well. I couldn’t clear the GA round. I was rather surprised that they selected many non IT based students. Then TCS came after one month, same thing happened for me, I failed in the GA round.

I guess there are several reasons why I failed, I was not in a great form to solve puzzle. I was little nervous and didn’t concentrate well. But I guess the problems are not so simple. If you are seeing that kind of problem for the first time then it will take some time to solve. If you have already solved many problems of that kind, then you can solve it quickly. I didn’t want to spend my free time by reading RS Agarwal or other puzzle books. So to wrap up, all the problem asked in the GA was new to me. So it took lot of time for me to solve the problem, but there was only thirty minutes. Any how both of the company did a good job, they made me realize that I am not a genius.

There are some common things between this two company. I guess their recruiting the based on the fact that, “ if a student is smart, then we can teach him something and make him write programs “.

One of my friend who got placed in infosys told me “ you should have got placed in infosys, they hired many people who had never done any programming “. Infosys will give a three month or six month training to the student and will put them to write code. Well many people still fail during the training as well. If their recruiting method is good, then no one should fail in the training.

I think no one will hire a juggler without seeing him juggling the balls. But they are hiring people without seeing him writing code. As of today, I have attended six or seven interviews and none of them asked me to write a single line of code. This was rather a surprise for me. I thought people will ask me write code for difficult problems. But no one even bothered about that.

I forgot to write about today’s interview. For your surprise I cleared the first round, but failed in the second round. They told me that I don’t know to speak English. I guess this is my weak point. I am a silent type. I don’t speak very well. Maybe, this has to do something with the way I grew.

I have been saying all the problems without saying any solutions. There is no good solutions available. But I can sure of one thing, if we write a program to print random register numbers, then it will select good candidate than the current system.

They can conduct a technical interview instead of the GA round. Then more people will write book about writing programs to solve technical puzzle and students will read them instead of mugging the RS Agarwal book.

I have been writing programs and reading technical book in all my free time. So this interview procedure will not work for me. One way is to get hired is, I have to put my butt in a chair and solve all the problems in the puzzle book and I need to speak boldly. Then there is a chance to get hired in an interview. Well this is hard to do. I don’t want to spend my time by solving those puzzle. The other way is get a job through a friend or any relatives. I like the second option although it is not fair to do.


Finally I got a job in Artha42. Well they asked me to write code :).

There is something that stops me from publishing this post. I’m afraid that people will think that, I’m against the MNC because I failed in their tests. Well that is somewhat true. I would not written this post if I got placed in Infosys or TCS.

Ruby Block

def foo
  print "foo"

foo { print "bar" }

When I encountered Ruby’s block for the first time, I thought it was a new type of construct. We are calling a function foo and passing it a block. The foo function will print foo and then magically transfer the control to the block, which will then print the bar and then magically return the control to the foo function. Whenever I use the word ‘magically’, I mean that I am not fully aware of what is happening. I guess this is how most imperative programmer will think. Well I used to think this way. I guess this is the problem with the imperative programmer. We kind of think sequentially. Oops I forgot to mention who is an imperative programmer. If you have written programs only in languages like c, c++, Java etc, then you are an imperative programmer. Well I was an imperative programmer until the beginning of the fourth year in the college.

I had a very small dosage of lisp. Suddenly my way of thinking changed considerably. I mean suddenly I realized that we can consider a function as a value in javascript. Well I have written code without understanding the basic concept.

Ok, lets rewrite the above method in scheme to explain it in terms of functional programming

(define (foo block)
  (display "foo")

(foo (lambda ()
       (display "bar")))

I guess the above code is very easy to explain. We are calling the foo function and passing it a function and the foo function prints foo and calling the function we passed, which in turn prints bar. Here is the trick, we can pass function as a value to other function. So what is really happening in Ruby. Well I don’t know the internals of the Ruby, I guess there is no need to know the internals in order to it to understand the concept. There is no such thing called Block. It is a simple function with no name, aka lambda. Then you might ask what is Yield. Well yield is a kind of syntax sugar. In Ruby you can pass a block to a function and the called function can call it with the yield key word. In fact you can handle the block explicitly

def foo(&b)
  print "foo"

foo { print "bar" }

So the bottom line is, learn lisp, it will help you to think in a different way. I should take a heavy dosage of lisp, which I guess will make me look at the world in yet a different way.

Recursion and Loops

Write a program to find the nth number in the fibonacci series

Imperative Programmer (Earlier)

public void int fib(int n) {
    int a = -1,b = 1;
    for(int i = 0 ; i < n ; i++){
      c = a + b;
      a = b;
      b = c;
    return b;

can you write this in any other way? hmm.. blink...

Functional Programmer (Now)

(define (fib x)
  (if (or (= x 0) (= x 1))
      (+ (fib (- x 2)) (fib (- x 1)))))

can you write this in any other way? hmm.. well.. i can write it using tail recursion

(define (fib x)
   (define (fib-iter a b count)
     (if (= 0 count)
	 (fib-iter b (+ a b) (- count 1))))
  (fib-iter 0 1 x))