Tuesday, May 04, 2010

Gentoo -> Kubuntu

For many years Gentoo has been my favorite Linux distro and it still is. I used Redhat, Slackware and Fedora for a few years before that. Just installing Gentoo is such a learning experience. Although installing a software is as simple as doing "emerge X", configuring it is a bit more involved and requires you to dig up config files and editing them. No fancy GUI to help you. Which is the best part about it. I can learn how things work in Linux. Another reason I preferred having Gentoo over other distros is because all the packages are compiled for my machine. Which means all the executables make the best use of all the instructions and features of my processor and what not. But the main reason I use Gentoo is because I can compile the Linux kernel to my taste. Tweaking every bit and compiling only the drivers that I need. I almost never compile anything as a module. Everything is in the bzImage. All these tweaking always made my computer run super fast.

While all this is good and well, I always felt a lack of proper integration of various pieces in Gentoo. To get any kind of eye candy (pre KDE 4.3 days), I had to install a compositing window manager (also known by various other names such as beryl, compiz and compiz-fusions which were forks of one another and such), and a window decorator such as emerald. Then had to configure various animations in compiz and install proper themes for emerald. At the end replace KWin with compiz. All this was tricky and time consuming. I love learning how things work internally but this is getting to be a bit too much. Why do I have to invest so much time to just get the fancy animations and eye candy? I was also noticing something else. The computers are becoming faster and faster and the difference of performance between Gentoo and other distros is becoming smaller and smaller, to the point that all the tweaking is not giving me any advantage.

Moreover I now own a core i7 laptop. It is so extremely fast that nothing really matters anymore. I have been watching Ubuntu for a while and looking forward to their new release -- Lucid Lynx. They are claiming fast boot times and the UI looks really nice too. I decided to give it a try. Since I am a KDE guy and never really liked Gnome, I went with Kubuntu. I have to say it is really good! The installation process, installing packages etc was a breeze. And even better was that the defaults that these packages come with is very good. For example in Gentoo I would have to configure the global USE flag and package level USE flags to get the right stuff (like encoders/decoder for mplayer etc).

It is not to say that the process was not without hiccups. I initially used i386 iso and I started seeing oom-killer kill ureadahead (which makes booting so fast in kubuntu) and plymouth (the boot splash). That was not nice. I Googled about this issue and found nothing. I had a hunch that it could be because of 32-bit kernels having trouble addressing memory beyond 1GB (the low and high mem issue). So I decided to go with 64-bit iso and the problem went away :). Now I have a few more issues to resolve before I am completely happy. For example installing proprietary nvidia drivers made me lose the splash screen which I loved. The integrated mic is not working for some reason. Could it be pulse issue? I have to fix all these minor things, but for now I am a happy camper :).

Thursday, March 18, 2010

XBMC / Boxee remote control android app

I have been writing a few android apps over weekends at home and during 20% time at Google. However I never actually released any of them in the android market mainly because they were quick and dirty apps that fit my needs but perhaps would not be appealing to the general public. One such app that I quickly wrote over a couple of weekends is a XBMC remote.

The media center that I use at home is XBMC and I have always wanted to have more control and faster access to my media. Using my remote to navigate through the menus is not as fast. Especially when I wanted to queue a lot of music it is very slow. So I wrote this nice little app called "XBMC remote" for my android phone to control XBMC from anywhere :).

Give it a try. Search for "xbmc" in android market and install it if you use XBMC as your media center.

When you first launch the app you will start with this screen.

You will have to setup your web server address, username and password (if required) by clicking on Menu and then Preference.

Once you entered all the information, you can click on any of the icons on the top or bottom. The image below explains what happens when you click on the various icons.

If you click on the top right icon, you will be able to control XBMC screen directly. Here is the screenshot.

There you can control playback and basic navigation. Clicking on the bottom right icon will show you what is playing on your XBMC. One more screenshot

The bottom three icons will take you to video, music and photo playlists. The screenshot below shows a music playlist.

You can delete some items from the list by clicking on the delete icon on the left of each icon. Hope you will try it out. Let me know about any bugs or feature requests.

I found out (after a comment from one of my friends) that it also works with Boxee (which is a fork of XBMC)! There are some problems with Boxee, but at least there is some basic functionality.

Some references:

Saturday, January 16, 2010

What Darwin Never Knew: DNA

I just finished watching one of the best PBS NOVA episodes - "What Darwin Never Knew". It is exceptionally good. I was finally able to understand a little about DNA - the building blocks of all living creatures. In this episode they explain how evolution is happening and why there are so many species and why even animals from the same species look so different. How complex DNA is and what a gene is. It still did not answer all my questions but got pretty close. Here is one part I found on youtube, but please watch all parts. It is very good.

So now I know that DNA is a very large sequence and it contains genetic instructions to synthesize various parts of a living creature. In simple layman terms there are three kinds of genes identified so far
  1. Genes that actually are used to create stuff. These are the sequences used to synthesize proteins and other things - the building blocks
  2. Genes that simply act as switches which can be on or off. When on the "stuff" creating genes are used to create the stuff, when the switches are off the "stuff" is not created. The show provides an example of fruit flies. Why some of them have black spots on the wings while others don't. But have the same genes that makes the spots, but in some the switch is turned off
  3. Genes that boss the switch genes. These are the ones that turn the switch genes on and off at various times. An example of this is the same bird species with same genes that creates the beak with the same switch genes, except the boss genes are different. So the switch genes are turned on at different times and the beaks of the birds are different (short and thick beak vs long and thin).
There is much more interesting stuff in there. However after seeing the show I still have a few questions. So the messenger RNA are created based on whether the switch is on or off. But how does that happen? Will the enzyme responsible for creating mRNA look at the switch? How does it "look"? Do the enzymes have sites that only lock on to the switch genes that are on? And then something happens from there on to make the enzyme use the genes to synthesize the mRNA or whatever? This means that the location of the switch genes should be close to the stuff making genes that they are controlling right?

Another question is how do the boss genes turn on and off the switches? What is the difference between an "on" gene and "off" gene? Probably the sequence. Then does it mean that the boss genes some how change the switch genes? I though a gene is an immutable entity. How can it change? Also how does the boss genes instruct the switch genes to change? Does it attract an enzyme of something to change the switch genes?

All these questions make me think I should probably study genetics or bio-engineering or something.

Friday, January 15, 2010

Fun with grep and sed

At work we have several java files that have javadocs with links that are not hyperlinked with . So I wanted to covert the links to hyperlinks. We wanted to convert only links that start with "Automates ", followed by one or more links that ends with a number. Example "Automates http://something/12345 and http://something/67890 but not http://something/54321". I wanted to do the conversion with one line of a bash command (trying to avoid writing the bash script). While tackling the problem I learnt a few things that I want to share and record here for myself to look back again in future when I forget.

To start with I needed to find all the files containing "Automates http://". I just wanted the filenames containing that string. And so comes grep to the rescue. With -l switch to list just the filenames instead of all the lines that match.

grep -R -l "Automates http://" *

Then it is time to replace the links with <a href=link>link</a> only for those lines containing "Automated http://". For this I want the line number of every line of every file that contained it. Getting the file number and line number is easy with grep. To get the filename use -H switch and to get the line number use -n switch. Here is an example

grep -R -H -n "Automates http://" *

The output of the above command looks something like this

/home/chandanp/temp/temp.java:73:  /** Automates http://something/353571 */

To replace the link with hyperlink we can used sed. All we need is the filename, the line number and the string to replace. And use sed like so

sed -i '936s|\(http.*[0-9]\)|<a href="\1">\1</a>|g' Filename.java

Where 936 is the line number I want to change and Filename.java is the filename I want to edit. The -i option edits the file in place. The more complicated part is the regex matching. Basically anything that matches the regex inside a \( and \) will be stored in a buffer. The buffer number is the number of the matching \(\). So in the example above, the first buffer is the string that matches \(http.*[0-9]\). Which is basically any link that ends with a number. To recall the buffer we use \1. Which means: use the value that matches the first parenthesis pair. So in the sed the replaced string will be <a href="link">link</a>, where link is the string that matches \(http.*[0-9]\). Here is an example of the change

/** Automates <a href="http://something/353571">http://something/353571</a> */

Notice another thing with the way I used sed's replace command above. I used s|match|replace instead of the usual s/match/replace. What many people don't know is that once can use any character after s instead of the usual /. So you could even do s#match#replace too if you want. I used the pipe symbol.

Now that we can replace each individual line of each file we somehow have combine the previous grep output with this sed command. That was tricky. First we need to break up the output of the grep command to individual filename and line numbers and then give that to sed. Well xargs, cut and sed to the rescue. We use the fact that the filename and line number are delimited by : and play some tricks

grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {} | cut -f-2 -d: | sed "s/\(.*\):\(.*\)/filename is \1 and line number is \2/"

Basically all it says is that take the output from the first grep which prints out the filename containing "Automates http://" and pipe it to xargs which takes the filename and gives it to another grep that prints filename:line_number:matched_sting and pipe that information to cut which prints the first 2 tokens that are delimited by :. We need to do the cut because the matched string also has : which means we don't want sed to use that part of information in the matching. Then we pipe the information from the cut to another sed to print the filename and line number. Here is the output after various pipes

$ grep -R -l "Automates http://" *

$ grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {}
temp.java:73:  /** Automates http://something/353571 */
temp.java:936:  /** Automates http://something/336439 and http://something/336438 */

$ grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {} | cut -f-2 -d:

$ grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {} | cut -f-2 -d: | sed "s/\(.*\):\(.*\)/filename is \1 and line number is \2/"
filename is temp.java and line number is 73
filename is temp.java and line number is 936

The final piece of puzzle is to make output from the last sed into a command and then run it. So instead an output like filename is temp.java and line number is 73, we just need sed -i '73s|\(http.*[0-9]\)|<a href="\1">\1</a>|g' temp.java. So here is the command to do just that (very complicated with lots of backslashes and quotes but I did not know any better :).

$ grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {} | cut -f-2 -d: | sed "s/\(.*\):\(.*\)/sed -i \\\'\2s|\"\\\(\"http.*[0-9]\"\\\)\"|\<a href=\"\\\1\"\>\"\\\1\"\<\/a\>|\\\' \1/"
sed -i \'73s|"\("http.*[0-9]"\)"|<a href="\1">"\1"</a>|\' temp.java
sed -i \'936s|"\("http.*[0-9]"\)"|<a href="\1">"\1"</a>|\' temp.java

Then we need to execute that command using bash. Like so

grep -R -l "Automates http://" * | xargs -I{} grep -H -n "Automates http://" {} | cut -f-2 -d: | sed "s/\(.*\):\(.*\)/sed -i \\\'\2s|\"\\\(\"http.*[0-9]\"\\\)\"|\<a href=\"\\\1\"\>\"\\\1\"\<\/a\>|\\\' \1/" | xargs -I{} bash -v -c "{}"

Ah finally. But there is one problem however. When there are multiple links in the same line, sed matches all of the links and creates a weird output like this:

Automates <a href=http://something/336439 and http://something/336438>http://something/336439 and http://something/336438</a>

I still don't have good solution for that. Since I have just a few of these lines I fixed them quickly using tkdiff. But anyone know how to solve it?

Tuesday, January 12, 2010

Attesting General Power of Attorney in SF

Recently I had to go through the motions of getting a General Power of Attorney (GPA) document attested in San Francisco. I am an Indian by birth. My parents were trying to buy a house back in India for me. Since I did not want to travel to India they needed a GPA so that they can act on my behalf to sign all the documents required to buy the house. The problem however is that they needed it urgently because the seller lives in UK and wants to get all the things done quickly so he can go back.

My parents send me a GPA document that they obtained from a lawyer. This is a document that will give the power to my parents to buy the said property in the document on my behalf. The lawyer said that I will have to get the document attested at an Indian Consulate in USA. The closest one for me is in SF and I can drive there in about an hour from where I live. So I though it will be like a day's work to get all the things done.

I looked up at their website for the procedure to attest GPA. I found the page I was looking for and the process seems simple enough. These are the things I need:

  • Complete Miscellaneous Services Application
  • Attach all previous passports in original
  • Photo copies of first 5 and last 2 pages of current passport
  • Current passport
  • Photo copy of a valid visa
  • Proof of status: original green card/visa/EAD. For me it is a valid visa
  • Proof of residence: Drivers License/Electricity/Water/Telephone bills/lease agreement. For me it is driver's license.
  • Photo copies of proof of status and proof of residence above
  • Original apostilled Power of Attorney to be attested
  • Photo copy of apostilled Power of Attorney document
  • Paste a photo in Miscellaneous Services Application
  • Paste a photo on Power of Attorney document
  • Sign Miscellaneous document
  • Pay $20 for fees using money order / cachier's check or debit card ($3 extra). Debit card for me

I got everything right except for apostilling the document. I got myself photographed. Pasted one in the GPA and another on the application and drove for more than an hour in traffic to reach the SF indian consulate only to find that I need to get the GPA apostilled. I did not know what it was and how it was supposed to be done. So I just skipped the step and went to the consulate. After standing in line for an hour the lady at the counter was kind enough to walk me through the whole process. She told me that first I should get the GPA notarized by a notary public after signing the document in front of the notary. Then I should send the GPA along with self addressed envelope to Secretary of State, California to get the document apostilled. Once they send the document back to me I will have to bring the documents to Indian consulate for attestation.

If I send the documents via mail to Secretary of State in Sacremento, it will be too late for me to send them to India. So I called up Secretary of State, CA to ask how long it will take if I walked in. By the way you can find all the details at http://sos.ca.gov. Contact phone for notary public is here. The lady on the phone said that by mail the turn around time is 1 day exclusive of the mail service time. And if I walked in it will be over in about 15 minutes. They just require the notarized document.

Great. That is easy. But there is just one thing. I wanted to finish all this in one day. So I had some planning to do. First it takes 2 hours to drive to Sacremento from where I live. And another 2 hours from Sacremento to SF where I will get the final attestation. The consulate closes at 12 pm. While the Secretary of State opens at 8 am.

The next day I started at 6am and drove to Sacremento. It was exactly 8am by the time I was in the Secretary of State. Finding the notary public office was easy and I got the document apostilled in about 15 minutes. Then I started off to SF for another 2 hour drive. I got the apostilled document photo copied at an office max in SF. It was 10:30am before I stepped into the consulate. At this point it was just a matter of time. I was in the line for an hour and then everything flew by quickly. She took the documents and the payment and asked me to return at 4pm to pick up the documents. I drove to work at 12pm and returned back to SF at 4pm. Everything was ready for me. Took the attested documents, drove back to work and then home late in the night.

Two days and 450 miles later I have all things done! That one day was tiring with 350 miles logged. End of the day the whole process is not that complicated. I was lucky to be close to Sacremento and SF. But for others who are not so lucky it will take more time. So please make sure you have enough time.