Download any PDF.. literally!

Sue me if I'm wrong with the title of this post. :)
I understand the feel of desperation when you know "that" something you need is available in a particular book, but you are not able to get it, simply becauseit costs $28.56 on Amazon!.
Well, going with the spirit of "Knowledge Is Free", I have come down as an angel in your life right now, who will enable you to download literally any book from the net!.

Type the following string in google search bar..

intitle:index.of?{extension} {search_string} [+ {search_string}]

Examples...

intitle:index.of?pdf ebooks Ruby

This will search and give results corresponding to all the hidden ebooks for Ruby Rails

intitle:index.of?mp3 U2 with or without you

will search the "with or without you" song by U2 .. you can just right-click and choose 'save-as' or 'save-link-as' to download the song for you're disposal. This way you can literally download any eBook/Song/Music videos ...
Happy Googling! Let the flames begin! etc.. Yawn.

2 sure ways to access GMail no matter which office you work in

We, being in “huge” service companies, suffer a lot in terms of online freedom. I used to get very frustrated initially when I joined, since all the sites on which I used to hangout were blocked!. Patiently, I started cracking(without using proxies) case after case and now, I have workarounds for all my fave hangouts.

However, today I am going post 2 simple techniques to access GMail(read-only).

1) Use GMail’s inbuilt forwarding facility: This is the simplest thing to do, just use the forwarding feature of GMail to forward all your GMails to corporate mail ID. Just go to settings in GMail and check out the pic below.

Ofcourse this is not the best way to read your personal mail, since your sys-ads might just sneak into your personal mails, and some companies might take offence. Nevertheless its practical.

2) RSS your GMail: That’s right, you can publish your GMail and access it from your favorite RSS reader be it bloglines , newsgator etc etc!. You need to add a subscription as the following in your RSS reader

https://USERNAME:PASSWORD@gmail.google.com/gmail/feed/atom

Thats about it! you will start receiving all your mails into your RSS news reader. However, the funniest thing about this technique is that, Google Reader itself doesn’t support https RSS feed yet. :) .

These are the basic 2 techniques which just cannot be blocked. There many other techniques to access the site, but they are specific to a company’s proxy.

For ex: One technique is, assuming you are behind a fire wall, you shouldn’t use your company proxy for SSL sites(change this in browser settings), so that, when you type “https://mail.google.com” you get direct access to GMail.

And then of course, there are sites like www.fuser.com which keep cropping up in this too-much-of-web 2.0 world, where in you can aggragate not just GMail, but many others too.

Happy work around-ing !

PS: do let me know if you have any more fool proof - work arounds

DTO pattern

As my project demands me to learn Enterprise Java for a project on "SaaS (software as a service)", quite far from the Ruby or Rails, I happened to come across a pattern called "Data Transfer Object" or just "DTO".

Its but obvious that, in a decent remote app, we tend to make many remote method invocations. Say for example, for a particular employee, you want to getFirstName(), getLastName(), getAge(), getSalary() blah blah blah... many such calls act as network overhead and unnecessarily slows down the app waiting for the reply.

To solve this problem, DTO pattern is implemented. Here, when a client asks for a particular detail say firstName, he is not only sent that data, but also related info like lastName, age, salary etc through a serialized plain java object. The client grabs the object and keeps fetching required info from that object.

In the following figure(courtesy) , Album artist and singer, 2 different classes on the server side are clubbed together and sent to the client.

Now, lets take a look at the implementation of this pattern. I implemented this in Java using EJB(entity bean).


Entity bean code(server side)

@Entity
public class EmployeeEntity implements Serializable {
private Long id;
private String firstName;
private String lastName;
.
.
.
//constructors go here
//setters and getters of the instances go here

//Below a DTO object is returned. 'TransferObject' is a simple serializable java object
public TransferObject getTransferObject() {
TransferObject to = new TransferObject();
to.setFirstName(this.firstName);
to.setLastName(this.lastName);
.
.
.
return to;
}
}


DTO class code(server side)

public class TransferObject implements java.io.Serializable {
private Long id;
private String firstName;
.
.
.

//Accessors/getters for the above instance variables as per the requirement should go here
}

Thats about it. Client receives the 'TransferObject' object and invokes getters on this object, just like any other java object. All the invocation so made are completely local.

I can't help but quote Martin Fowler in the end, Chief Scientist, ThoughtWorks.
"Patterns always have two parts: the how and the when. Not just do you need to know how to implement them, you also have to know when to use them and when to leave them alone."

Quit, if you hit a key - Part 2

Oops.. I seem to have found a solution here for platform independent way of solving the previous post's problem. It goes like this..

'Essentially just do a nonblocking read and rescue the “resource not available” exceptions as they come. Just hit enter to kill the loop.'

i=0
loop do
begin
break if STDIN.read_nonblock(1000)
rescue Errno::EAGAIN
end
puts i
i += 1
end

Quit, if you hit a key

The very first problem in my previous post seems difficult to solve!... and the link clearly tells its impossible to solve!. I am talking about this problem..

Display series of numbers (1,2,3,4, 5….etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).

I happened to have a discussion in the Ruby mailing list, the conclusion was that, it can definitely be solved, what the author actually said in the link, was that it can't be solved without writing some platform specific code or threads.

Here is a possible solution as suggested in the mailing list which works on UNIX like OSs.

require "io/wait"

state = `stty -g`
begin
system "stty raw -echo cbreak isig"

1.upto(1.0/0.0) do |n|
puts n
exit if $stdin.ready? and $stdin.getc == 27
end

ensure
system "stty #{state}"
end

The reason, as it seems, is that all terminals are different and you are needing to interact with it on two levels at once (reading while writing). This is what introduces the need for the platform specific code.

15 exercises to learn a new programming language

I have always found reading a particular book to learn a new programming language pretty boring. I have always thought, programming language books are only to be referred. As such, the best way learn a programming language would be implement a project, and learn on the fly.

In web development, the way to do it would be to implement 'Shopping Cart' application, it covers all the aspects of web development from databases to sessions!.

On the other hand, to learn a programming language alone(without getting fussy about UI), I feel, the following exercises are to be implemented to get the basics of the language right. Here they are(taken from here)..

  1. “Display series of numbers (1,2,3,4, 5….etc) in an infinite loop. The program should quit if someone hits a specific key (Say ESCAPE key).”
  2. “Fibonacci series, swapping two variables, finding maximum/minimum among a list of numbers.”
  3. “Accepting series of numbers, strings from keyboard and sorting them ascending, descending order.”
  4. “Reynolds number is calculated using formula (D*v*rho)/mu Where D = Diameter, V= velocity, rho = density mu = viscosity Write a program that will accept all values in appropriate units (Don’t worry about unit conversion) If number is <>
  5. “Modify the above program such that it will ask for ‘Do you want to calculate again (y/n), if you say ‘y’, it’ll again ask the parameters. If ‘n’, it’ll exit. (Do while loop) While running the program give value mu = 0. See what happens. Does it give ‘DIVIDE BY ZERO’ error? Does it give ‘Segmentation fault..core dump?’. How to handle this situation. Is there something built in the language itself? (Exception Handling)”
  6. “Scientific calculator supporting addition, subtraction, multiplication, division, square-root, square, cube, sin, cos, tan, Factorial, inverse, modulus”
  7. “Printing output in different formats (say rounding up to 5 decimal places, truncating after 4 decimal places, padding zeros to the right and left, right and left justification)(Input output operations)”
  8. “Open a text file and convert it into HTML file. (File operations/Strings)”
  9. “Time and Date : Get system time and convert it in different formats ‘DD-MON-YYYY’, ‘mm-dd-yyyy’, ‘dd/mm/yy’ etc.”
  10. “Create files with date and time stamp appended to the name”
  11. “Input is HTML table. Remove all tags and put data in a comma/tab separated file.”
  12. “Extract uppercase words from a file, extract unique words.”
  13. “Implement word wrapping feature (Observe how word wrap works in windows ‘notepad’).”
  14. “Adding/removing items in the beginning, middle and end of the array.”
  15. “Are these features supported by your language: Operator overloading, virtual functions, references, pointers etc.”
If you're learning Ruby, then this has possible solutions to all the above problems.

The Web-ful Way

It was way back in August 2006.. my 6th semester exams were over, I had got recruited into Infosys(only on campus, eventually I happened to join Persistent Systems), I was looking for 'The Road Ahead', in true Bill Gates style. Yes, it was time for final year project, looking for the best possible project to work on, after all, I was tired of all the shit they fed me during my engineering course from the previous three years, learning stuff as stupid as 1978 model processor architectures!!

I consulted all the possible experts I knew at the time, took their inputs. I had decided to work in project which could be converted into an entrepreneurial venture eventually. At the time, I had misconceptions about web applications, thinking it was nothing more than web designing.. which any tom, dick and harry could do!. So practically speaking, I was zero in knowledge, all I could boast of was energy, enormous amounts, plus the interest to do something out of the way. With this as background, I started skimming the ideas, for some periods of time I was interested in my prof's(Mr. Ravindra Dastikop) idea of 'Vertical search in Indian education'(which has seen the light of the day here), then some how I dropped it for various reasons.

Meanwhile, I was getting idea for ventures everyday, I was kind of serious about 'social networking using Google Maps', held meetings with some industry leaders, drew the sketches of the possible look of the app, some how got circulated into the hands of a full time entrepreneur... got some backing from him. But later on realized that, its not really going to work at the consumer level for various reasons.

Finally, one idea stuck, named it 'Wikiratia'. As the name would describe it, the whole idea was, the user could mark any place on earth(we used Google maps APIs), say, his grocery shop and rate the place out of 5. Now, the average rating for say 40-50 people could not be wrong and hence you would get a true picture of how good the place is. So, once we get decent community for the site, we could start introducing new features like introducing social networking angle to it, where by, suppose a friend of mine rates a hotel as good, then, most probably it is good, even though there is only one rating to that hotel!.

Alright, so the idea is zeroed in on, but what about the implementation???. At the time, I didn't know any of the web languages(pretty daring ha!.. knew nothing about web but was researching so much about the idea!) like PHP, Perl, J2EE etc etc.

So, we consulted an industry leader and computer science expert Mr.Vinod Kulkarni. He asked one simple question which struck me "Normally, people use JSP/Struts or PHP/Perl, you can use one of these, else, do you have enough enthu to learn Ruby on Rails for this?". For me it didn't quite make a difference, since I knew nothing anyway, be it J2EE/PHP or Ruby. I decided to implement using Ruby, to experiment.

So, Ruby/Rails was learnt on the fly while implementing, gradually in a couple of months, with fair amount of struggle, we finished the project!.

We happened to finish the project ahead of schedule, and so happened to be free for most part of last semester. In search of gold, I applied for internship in Sun Microsystems, got through after a few round of interviews, started my work there within 10 days time. My work was related to Zetabyte filesystem Solaris OS, yup, not an ounce of web technology in it. I was so fed up of the work... that, when once in a while some web developers used to discuss AJAX and stuff, I used to just lean over and listen to them talk, thinking about my golden days of web development not long ago. Adding to the irony, the founder/developer of JRuby happened to visit Sun Microsystems, Bangalore to give a talk!!.

So, as scheduled I had to go back to the college for my internal assessments and come back duly. Incidentally, Persistent Systems was visiting my college for campus recruitment, as a 'dream' company(thats what they used to call for companies, for which anybody was allowed to attend even though you have already been recruited into one company). This was my chance to work on the web again!!!. Nope.. I didn't let it go! I was interviewed by Nandhin and one other guy(dont remember his name, and please, no hard feelings for remembering only the lady's name :) )(by the way, both are my colleagues here). I was very happy that day!.. I was ready to quit 'Sun', where I didn't enjoy at all!.

The very next day, I called my manager in 'Sun', gave him some shit reasons like 'principal is not allowing to leave the campus' etc etc to which he even told me to join after the college!!.. had a hard time convincing him. So, fully realizing that I would be getting half the pay of what I was offered at 'Sun', I joined 'Persistent Systems' on July 9th 2007.

The story doesn't end there. I was given Java training for 3 months. Now, after learning Java I realized the true simplicity of Ruby/Rails and its pace, hype and importance!. I thought that, I would never get a chance to work on Ruby/Rails again, much to my surprise, my first project in Persistent was completely based on Ruby!. Thanks to Akshar, my teammate, who introduced me to my current manager to work on RoR based project.

So far so good. Now lets see, where I go from here. As you can see, many unexpected things have been happening, hope things will change for the better!. What do I want?.. I just want to do some good work, get immersed completely in it. Hopefully, it will be some web related work. :)

Sun shines....!!

Yes, thats right. The Sun really seems to be shining bright. I know its share price is currently $6.4, I know it has had a profit of only $126 m this fiscal, but the fact is, SUN SHINES!. Some really cool facts...
1)Guys are great!.. they are really friendly, my mentor Mr. Vallish actually took me around the whole floor to introduce me to nearly 30-40 ppl(now tell me where do you find this??).
2)I was a li'l apprehensive about the dress code, I asked one of my teammate about that, he said, "the only dress code in Sun is wear one". How cool is that?.
3)No timings. You can go anytime, come anytime, have coffee or play foozball(pardon the spelling) anytime as long as its really not completely "out of the way".
4)Cool infrastructure... really nice building and cafetaria.. with cool personalisations like, your work area can be named whatever you want!!.. like my friend's area here is named "Shantinagar", cuz his name is Shantanu!

Alright, I can really go on this way, but will stop at this point.
CRUX: "Sun Shines!". :)

An interesting problem

Given a file of 4 billion, 32-bit integers, how to find an integer that appears at least twice?

One simple solution that I can think of quickly is:

Sort the integers in the file, using any of the efficient sorting techniques like Merge, Quick etc and then go on comparing adjacent integers to find duplicates.

But come to think of it, sorting a 16 GB file is not a feasible. I need to come up with something more efficient.