Java Parsing RSS XML using XPath

October 11, 2011 Leave a comment

import org.w3c.dom.*;
import org.xml.sax.InputSource;
import javax.xml.xpath.*;
import javax.xml.parsers.*;

public class XmlParser {
 public static void main(String[] args) {
 try {
  DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder = domFactory.newDocumentBuilder();
  URL url = new URL("");
  InputStream inputStream = url.openStream();
  Reader reader = new InputStreamReader(inputStream, "UTF-8");
  InputSource inputSource = new InputSource(reader);
  Document doc = builder.parse(inputSource);
  XPath xpath = XPathFactory.newInstance().newXPath();
  XPathExpression expr = xpath.compile("//rss/channel/item/title/text()");
  NodeList nodes = (NodeList)expr.evaluate(doc, XPathConstants.NODESET);
   for (int i = 0; i < nodes.getLength(); i++)
    String title = nodes.item(i).getNodeValue();
  catch (Exception exception) {

Categories: Programming

C# Get Physical Device ID from Drive Letter or Logical Disk ID

October 8, 2011 1 comment
var logicalDiskId = "C:";
var deviceId = string.Empty;

var query = "ASSOCIATORS OF {Win32_LogicalDisk.DeviceID='" + logicalDiskId + "'} WHERE AssocClass = Win32_LogicalDiskToPartition";
var queryResults = new ManagementObjectSearcher(query);
var partitions = queryResults.Get();

foreach (var partition in partitions)
query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" + partition["DeviceID"] + "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition";
queryResults = new ManagementObjectSearcher(query);
var drives = queryResults.Get();

foreach (var drive in drives)
deviceId = drive["DeviceID"].ToString();
Categories: Programming

A 4.0 GPA only does not necessarily guarantee a job

June 5, 2011 5 comments

I am sure most of us have experienced and have been with these perfect 4.0 classmates. I will call them, uhm, the four-point-os or four-point-oz. They carefully pick their classes and spend a whole year on researching and looking at different ratings to what classes and specifically profs to pick for next year. Since they are so focused on their GPA, they opt to not work or take internships. They are never late in submitting their homework or they never submit an incomplete homework. They even have so much time to read the whole textbook from cover to cover. They also whine when they get a 104% out of 105% even if that 5% was just extra credit. In most instances like these they are always fast to declare that “the prof is stupid” or “the prof doesn’t know s**t.” At instances they feel good when they point out if a prof is wrong. On other instances they gather so much pride when they answer a question in class 10 times faster than the rest of the class. They also like to interrupt when the prof is trying to answer someone’s question. They try to display that now they are at the same level of understanding as the prof or even better. They are also very disciplined as in they never miss any single class and they are always in time and never sit anywhere but the first two-row. And if sometimes things are not going their way, these four-point-os will drop the class in time so it does not hurt their GPA. With this kind of things happening, they are willing to stay a semester or a year longer to make sure the class load does not ruin their perfect GPA. In the end they end up taking easy classes that do not increase any important skills or knowledge to the already set of skills they have.

All that said, I have noticed in my experience (I would be glad if you can share yours too), that these 4.0 students always have a hard time finding and getting jobs. Frequently, because of this reason and the fact that they have a 4.0 GPA and a 1600 GRE score they end up going to grad school. Even if they are very smart at school, they fail terribly outside school structure. Where homework and projects are beyond the levels that they have experienced. They also have poor interaction skills as all these years they prefer to hide in their boxes and secure that GPA. The worst thing is that they have earned their perfect education but have not learned anything out of it. They never had chance to apply and think rationally about the things taught in classes outside the school. Because of this they know things but cannot apply it especially during interviews, the gateway to getting a job.

Most importantly, employees feel  that these 4.0 GPA have nothing to offer other than their ability to follow strict rules and being disciplined. They lack any kind of job related experience, especially internship experience. They have no record of how well they do outside of the school. Which results into rejection.

I was lucky to be in a class with couple or more 4.0 GPA students as it gave me a first hand experience of them. I was more of a guy who wouldn’t attend a class if I think I won’t learn anything out of it. I skipped those classes and instead spent those hours at my internship. Since I was paid by hour, and I was clocking more hours than they had expected, the number of meals served on my lunch box increased. The meals I refer to is the number of projects I was assigned at my internship. I tended to have my plate full and did most of the projects at a level most full-time and senior level employees did. The projects and the number of responsibilities I was given boosted the level of my resume and it wasn’t that hard (I will talk more about this on another post) for employers to call me for an interview and even get a job after I graduated. But then there were these four-point-os and they had hard time even getting interviews. No doubt that they were really smart in school but as Joel Spolsky says that they have to be smart and get things done. With a lack of internship experience, it was hard for these four-point-os to show that they could get things done.

So here is my advice to all the college students out there:

  • Do not focus and worry about GPA – I am not saying that do not study hard and make effort but if you end up making a B and you feel like you learned something from the class than be happy with that
  • Get an internship – There is no other substitute for this or get a job that let’s you apply the skills learned from school or is in a way related to your major
  • Take hard classes that are intensive in applying the knowledge you have learned in previous classes

To end this, I just want to add few other things. I might have generalized a lot of characteristics of the four-point-os. There are always other instances and circumstances that these four-point-os are not able to get the jobs. They are great individuals and they do have capability and talent for the jobs. They are one of the smartest individuals and some of them are wonderful at heart. Few of them make continuous efforts at being better at everything, but the four-point-os are beyond them. They take school seriously and value the money and time they have spent on it. I was also lucky I was able to get help, learn, and participate in discussion with few of these individuals. I hope that everyone looking for a job gets one soon. My love goes out to everyone, especially the four-point-os and I apologize, too, if I have hurt anyone which I techinically did not mean to.

How come Computer Science Graduates are valued less than Contractors?

May 21, 2011 Leave a comment

In my Junior year at college and after applying to so many places for internships, I finally got accepted to one. The company where I got the internship is in retail business of home furnishings, especially imported ones. As I was an intern (or that was what I was expected of), I was not asked any coding or programming questions. Is this the reason so many new guys cannot code? I don’t know about others, but I could definitely write code for Binary Search. What the heck, why not Quick sort or even code for a Red-Black tree. But that’s not my point, they more of asked me questions like do I know .NET (check), html (check), C# (check), crystal reports (never heard of), ColdFusion (nope), and so on. Based on this questions and some situational questions like -what if you cannot solve a problem?- I was selected for the internship position. Hurray!!!

The thing I learned during my internship years was that the contractors were the most valued in the company. Let me rephrase, contractors were the most revered out of all the tech workers. I am not sure why, may because of their $1000/day salaries.

It was like the contractors where there to create new projects and features, leave them undocumented for the full time on-call employees. I felt sorry for the on-call tech people, they had to be working 24 hours plus when a bug was hit or the whole credit-card database application crashed only to find out that there was no documentation ever left by the contractors to help figure out what went wrong.

Every few months a handsome looking guy with a nicely pressed shirt and pants and a clean shave would blab about all these Silverlight applications he created for x number of companies. He would then get hired to lead and write all the code for this new flashy project only to be maintained months later after he has left a huge mess. But even then they are still revered as gods and the full time employees get all the hearing to why they did not learn anything from these intelligent creatures when they were here.

Aside from that, the most astonishing fact I learned from this Contractors was that they never had a programming class in their 4 years or so of college. The reason was that they were English or History or Agriculture majors and then they did not find jobs in their majors and they took this Learn C# and .NET in 24 hour classes and now they were better than the Computer Science majors. These consulting companies or contracting companies or whatever they are called, hire these people and shove down few tricks of C# and whatever the programming hype is down their throats in a few days time and they are (supposedly) better than the average Computer Science graduate.

Here is where the frustration is built up by these average Computer Science graduates, when they are rejected because they don’t have 5 years experience using J2EE or Silverlight or PHP or Ruby on Rails. (When I say average I don’t mean to demoralize anyone but the above average Computer Science grads most often end up in companies like Google, Facebook, Microsoft, Amazon, etc or end up doing Computer Science research as Phds or begin their own start-up companies). These is a common trend among these companies who create in-house softwares where experience and knowledge of some technical trendy language or framework is more important than the fact that you can pick up this in a small amount of time given you know some programming.

On the other side, all the big software companies and other few care about the fundamental Computer Science skills and not the knowledge of some recently applauded new programming language. Except few of those who additionally want you to have an in-depth knowledge of C++, Java and PHP.

Scala vs Python: Read File

April 13, 2011 Leave a comment


val txt = FileUtils.readFileToString(new File("input.txt"))


val txt = Source.fromFile("input.scala") mkString("")


txt = open("input.txt").read()

Categories: Programming

Qualities of a Great Teacher

February 3, 2011 1 comment

The night of July 13th 1991 marked an important event not only in my life but my four siblings. On that night, my grandmother came driving from a small village at 1a.m. to give news that my father had died. I was merely 7 years old. My father was the key bread winner in our extended family. His business efforts not only helped to educate 5 children in the house but also sustained the household needs of the entire family. The death of my father struck a permanent blow in the family. The next 13 years leading up to my college, the education of my four siblings and I was supported by a generous donation by the local community alone. Ever since, I made a promise: “I shall help others like me when I grow up.” My natural inclination has been one to always help the less fortunate in whatever ways I can. Since, education has been my greatest gift in life; I have found teaching as the most pure forms of giving. And to be given an opportunity to teach a less-fortunate segment of kids in the society even means a lot for me. There are few places in the world where one gets to be a hero every day – a hero who gets to live up to the value he believes in. Even to belong to such a cadre of corps is a blessing indeed.

I personally consider that the mark of a great teacher is his or her ability to at least enable others to be as capable as one is. If there is no transfer of knowledge, inspiration and passion then there are chances that the student shall never arise to one’s highest potential. Enabling others to discover their greatest gifts within and bringing those gifts out would be a true measure of my accomplishment. Many elders wish that when they went to school they would have been taught the importance of deciding on a direction in life that strongly vibrated with their being. The greatest people followed their heart’s calling with one single thread and drove out all hindrances with might. Such people are able to create a lasting difference in the world. Apart from knowledge, all teachers have the duty to cultivate values in the generation to come. A world without values is a world without hope. Another lasting accomplishment that I seek is to ornament my students with lifelong values.

We tend to remember people who have had most impact in our life. It is harder to remember the best singer but it is easier to remember a math teacher who taught us an important lesson in life. The best way to assess my success as a corps member is the extent to which I have been able to make an impact on others. When one has profound love for what one does there is no doubt one shall not leave a trail of footprints. The footprints reveal prominent marks of impact.

(This essay is from someone I know very closely and it was part of an application for a Teaching job. The author wants to remain anonymous.)

Letter Frequency Counter Using LINQ

December 20, 2010 Leave a comment

A year ago I was taking an Information Security class and we learned about how to decrypt messages that were encrypted using Substitution ciphers. The trick was to first know what language was it, the percentage frequency of letters in that language, and the frequency of the characters in the given message. As a homework assignment, we had to decrypt a message that was encrypted using a substitution cipher. Instead of looking up online, I jabbed my keyboard and wrote a Java program to count the frequency for me. Later, I came to realize sites dedicated just to do that. Apart from the above story, I was messing with the LINQPad 4 and trying to learn some LINQ. Here is how to count the frequency of characters in a string using LINQ:

var toks =
 from t in "The red green blue bird flew over the zoned-out programmer's 10 feet long desk."
 group t by char.ToLower(t) into g
 orderby g.Key
 select new { g.Key, Count = g.Count() };
 toks.Dump(); // note this a LINQPad syntax only

%d bloggers like this: