Monday, October 24, 2011

Do: Migrate E63 to Galaxy 3; Done!

It has been a while since I bought my Galaxy 3. Its an amazing economy Android phone :) I have an E63, which has been with me since a while now. I was trying to find ways to transfer contacts from E63 to Galaxy. Laziness! and Procrastination!!
I was not really using the Droid for a lousy reason that the contacts are not transferred.

Today I decided I will end my procrastination :D there you go; decision done -> action taken :)

A really simple 2 step procedure to copy contacts:
1. Copy all contacts from E63 to the mem card. Mount mem card & copy contacts to the PC (saved as *.vcf).
2. Copy contacts from PC to the Droid mem card & import vCard to phone!

I now feel really dumb that I waited for so long :(

Saturday, October 22, 2011

Keep your workstation ready -- Always...

Hola!!

What better can I think of doing than blogging when a bunch of software gets installed on my comp??

Setting up a new system is the most painful ordeal. PERIOD :-| I am sure a lot of us agree. This is particularly true when we have multiple systems distributed across locations AND like to keep the workstations in sync. Well few of you may say, when we can carry a laptop why bother? I can only say, I thought so too, but was proved wrong time and again.

Most of us fancy having a "High End" system. Let's face it, we don't necessarily make use of all its juice. So? There you go, settle down for a slightly lower configuration workstation that can be carried around :)

Desktop virtualization is a boon to guys like us. I used to fancy running a Linux box on my Windows PC @ work place. I am more comfortable using the 'ls' than the 'dir'. Unfortunately, my work called for using Windows for every single thing I did. Nevertheless, I had a Linux VM ready for any script-testing. I thought a VM is good for that and only that!

How incorrect I was :-O Now when I am pursuing Masters I realized the awesomeness of virtualization. Be it messing around with new software... kernel compiling... or simply try coding to check the effect of infinite recursion on the OS :-P

My latest "woah!" time was when I had to run a bunch of software on a friend's machine. I had very less time, and also could not ask my friend to load his box with all the assorted libraries which meant nothing more than non-sense to him. I quickly configured my Ubuntu VM decked it up and took the vdi file on a portable hard disk. Just one installation of Virtual Box on his machine, I had my workstation up and running in less than 5 minutes. :)

So what is the learning? For me it was simple. Configure a sufficiently powerful virtual machine on the native box you have, keep the VDI safe. Use it where ever you want.

I have now decided to work full time on this virtual machine. I have configured my virtual machine based on virtual box. Its fairly simple to use, open sourced and easy to carry around ( NOT the virtual machine, the S/w itself ). My VM is an Ubuntu 10.10 box (32 bit - safer as it runs on both a 32 bit / 64 bit base machine). How ever less I use, I have the following environment ready:
Java development, including J2EE.
A fairly decent C/C++ environment with Qt/OpenGL & Boost libraries.
Perl -- My favorite language! How can I leave it :)
Python -- a new muse.
SVN & GIT -- version control on the move.
An Eclipse IDE (Galileo -- well I know its a bit old, but WTH! it serves my purpose).
Mozilla firefox browser -- I need to "Google things out" when I'm working!

I installed this VM from a bare minimal Ubuntu server alternate disk (with no servers installed), so I handpicked the necessary software. I don't intend to play tetris on this development box. A big NO to any (un)productivity suites. However I do have a decently heavy LaTeX2e environment to type out reports :)

This VM is a 2 vCPU, 2GB vRAM machine with virtual disk size is 15gigs, which is OK! I carry this around on a USB portable harddisk, along with a Virtualbox installer(both Linux & Windows :D). I can do most of my work on this virtual machine.

If you are wondering, "You have your environment ready, then why the **** are you setting up a new machine? Couldn't you have worked on this??" Well.. lets just say, a failed upgrade! :D

Now that my base machine is ready, time to get back to the VM and crank code!

Cheers,
Akshay

Saturday, October 15, 2011

Code Indenting Made Easy

In continuation to my once-upon-a-time post about code indentation here is a quick post.

This is particularly helpful to those of us who get this kick of writing code in a single column indentation, ( some fancy name for hopelessly written code :-| ). I discovered these tools called GNU Indent and Artistic Style, when pulling out my hair reading someone's code.

Perl has a beautifier called Perltidy. I searched for "Is there a ctidy" and that is when I came across the two tools mentioned earlier. GNU Indent seems to be a C only beautifier*.
( * Correct me if I am wrong. I just read the description )

Artistic Style on the other hand works for Java, C, C++ and C#. It is a simple light weight yet powerful code formatter. You can download the source from here. Extract it to a convenient folder. Change directory to build and run make. If you prefer installing in some local location like me, provide the prefix information in install: make prefix=$HOME install. If you don't bother much, just run make install. There you have AS installed.

Running is even simple, (assuming AS is installed in the user's local bin directory)
~/<username>/bin/astyle <source files>

THAT'S IT!

AS does give plenty of options to format code, I wont go over all of it. Waste of time (:P) feel free to figure it out.

Now that the code is indented, let me figure out what it does!

Adios :)

Wednesday, October 12, 2011

Text under word in LaTeX

Howdy!!!

If there is an activity graph that is generated on my posting habits, I'm pretty sure it would look like the ECG of a dying man. 
Sigh!! how I hate myself for not being able to post frequently. All I do here is rant. Most unfortunately, I cant rant as frequently as I want :(

The title gives away the suspense (if ever it would excite anyone!). In my last post, well a long time ago, I indicated that I have been working with LaTeX for a while, there is no change in the status :) Every time I discover something new I am like "Woah!" ( Expression flicked from a good friend Tejaswini ).

Now its about placing text under a word / sentence / symbol. What's so great? Well, the way your content is typeset becomes awesome!

For starters, this has to be executed in math mode in between text. So it may not work in the equation mode.
A simple example, you need to say summation over some i. Classically, the code for the same would look like this : $\sum_{i}$
And the typeset looks as under:

Now how nice would it be if we could place the i below the sigma? Well, I had to pull my hair out to figure out the same. Thankfully, some dude had posted the solution on a forum, I adopted that, and voila! my problem was solved.
So the code to make i appear below sigma is simple: $\underset{i}\sum$.
The typeset looks like this:
Ain't that what we wanted! :)

Enjoy TeX-ing :)

Signing off for now.

Wednesday, July 6, 2011

Beautiful tables in LaTeX

It has been quite a while since I started using LaTeX. I must say, I am in love with the way it typesets the pages. I have pretty much given up using any WYSIWYG word processors :)

There are a few nitpicks that beginners face using LaTeX. Typesetting tables is one of them. If you think you can relate to this, read on...

So here you are writing a nice report of your project work. You have some tabular data, the easiest way to represent it, is in rows and columns, (quite obviously).
You bet on a rectangular grid, nice and easy...
Here is what you get:


The LaTeX listing would be:

\begin{table}[htbp]
\caption{Table 1}
\begin{center}
\begin{tabular}{|c|c|c|c|c|}
\hline
\textbf{Heading 1} & \textbf{Heading 2} & \multicolumn{ 3}{c|}{\textbf{Heading 3}} \\ \hline
 &  & Heading 3.1 & Heading 3.2 & Heading 3.3 \\ \hline
 &  &  &  &  \\ \hline
One & One & 1 & 2 & 3 \\ \hline
Two & One & 2 & 3 & 4 \\ \hline
Three & Two & 3 & 4 & 5 \\ \hline
\end{tabular}
\end{center}
\end{table}

And then, there is your guide, who wants your tables to look gorgeous! What would you do? Curse your guide of-course! And rake your brain.
Fear not :) here is booktabs.

Booktabs provides an elegant look to the tables. It is quite flexible too. 

Consider the same example as above. I used booktabs to typeset the same, here is what I get:


Now that is some elegance :)

Here is the LaTeX listing for the same :

\begin{table}
\begin{tabular}{ccccc}
\toprule
{Heading 1} & {Heading 2} & \multicolumn{3}{c}{Heading 3} \\
\cmidrule{3-5}
{} & {} & {Heading 3.1} & {Heading 3.3} & {Heading 3.3} \\
\midrule
One & One & 1 & 2 & 3 \\
Two & One & 2 & 3 & 4 \\
Three & Two & 3 & 4 & 5 \\
\bottomrule
\end{tabular}
\end{table}

The next thing about tables is when you reference them in the text. The reference numbers may get mixed up if you are not careful.
The trick is to include the label to the table after the caption in the LaTeX source.
Here is an example LaTeX listing:

\begin{table}
\begin{tabular}{ccccc}
\toprule
{Heading 1} & {Heading 2} & \multicolumn{3}{c}{Heading 3} \\
\cmidrule{3-5}
{} & {} & {Heading 3.1} & {Heading 3.3} & {Heading 3.3} \\
\midrule
One & One & 1 & 2 & 3 \\
Two & One & 2 & 3 & 4 \\
Three & Two & 3 & 4 & 5 \\
\bottomrule
\end{tabular} 
\caption{Table 2}
\label{table2}
\end{table}

That's all for now! Enjoy TeX-ing.
Gotta get back to complete my report :)

Sunday, March 27, 2011

Command line parsing :)

There is a nice saying, "do not re-invent the wheel!" It so happens, many times, we don't realize, there is already a wheel available exact to the specifications we are looking for.

Command line parsing in any programming language is a good example for this scenario.
I have a simple scenario,
  • Accept a few command line options for the program I am writing, based on the command line option, the semantics of the further arguments vary.
  • Each of the options can have sub-options (not compulsory though!)
  • Sub-options have a different meaning based on the command line switch (if we can call each of the option as a switch)
Prior to this post, I used to write a painful while loop considering various combinations of the inputs. So you guessed it right, the code for command line parsing was mostly bigger than the actual application code. I am pretty sure many of you would have faced this situation.

This was the first time I faced a challenge in terms of the number of combinations I have to consider before the entire command line was parsed! It seemed herculean.

Now what??

Google bhagwan ki jai :D :D

I came across something called getopt() in the GNU standard library. (Sorry Windows folks, I am not sure how to solve this problem on Windows yet). Getopt is a neat little library to parse the command line. There is big brother version of this library function, the getopt_long() function to parse long options. I have not yet explored the getopt_long() function. getopt() served my purpose, so i didn't go beyond that page.

The GNU page on the same is quite exhaustive. However, I found the example not so intuitive and easy. So here goes my example.

#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> struct cmd_opts { char *option; int caseIndex; int edge; int interior; }; struct cmd_opts *co; enum {CASE = 0, EDGE, INTERIOR}; const char *indices[] = { [CASE] = "ci", [EDGE] = "sub1", [INTERIOR] = "sub2", NULL }; void printUsage(){ printf ("USAGE: \n" "-h -- prints this help \n" "-t -- specify a tetrahedron case \n" "-x -- specify a hexahedron case, \n" "\t a comma separated value list. ci=<caseindex>, \n" "\t sub1=<sub case index for face ambiguity resolution> \n" "\t sub2=<sub case index for interior ambiguity resolution>\n"); } int parseCmd(int argc, char **argv) { char *casevalue = NULL; char *subopts; int index; int c; co = (struct cmd_opts*) calloc(1, sizeof(struct cmd_opts)); co->option = (char *) calloc (64, sizeof(char)); opterr = 0; while ((c = getopt (argc, argv, "hx:t:")) != -1) { switch (c) { case 'h': printUsage(); break; case 't': strcpy(co->option, "tetrahedron"); casevalue = optarg; printf("\nTetrahedron : Case = %s", casevalue); break; case 'x': strcpy(co->option, "hexahedron"); printf("\nHexahedron\n"); subopts = optarg; while(*subopts != '\0') { switch( getsubopt (&subopts, indices, &casevalue) ) { if(casevalue == NULL) { printf("\nUnspecified suboption!! -- Quitting\n\n"); return 1; } case CASE: printf("Value of : %s is : %s\n", indices[CASE], casevalue); break; case EDGE: printf("Value of : %s is : %s\n", indices[EDGE], casevalue); break; case INTERIOR: printf("Value of : %s is : %s\n", indices[INTERIOR], casevalue); break; default: printf("Unknown suboption!!\n\n"); break; } } break; case '?': switch(optopt) { case 'h': printf("Option -%c requires an argument\n", optopt); break; default: printf("Unknown option '-%c'\n", optopt); return 1; break; } default: abort (); } } return 0; } int main(int argc, char **argv) { parseCmd(argc, argv); return 0; }

The above listing was obtained using this link

Let me take you through this example,
The possible values of the sub-options are listed in the following array (or a vector if you may call it) :
const char *indices[] =  { [CASE] = "ci", [EDGE] = "sub1", [INTERIOR] = "sub2", NULL };

The function call getopt (argc, argv, "hx:t:") returns an integer, which typically is the integer value of the given options "h" "x" and "t". This integral value is used in the following switch statement.
To elaborate on the options provided above,
"h" has no colon following it, indicating it is an argument-less option
"x" and "t" have a colon following, indicating they need argument(s) that follow, something like :  
-h ci=3.


When the option is encountered, and it is destined to have arguments, the arguments are contained in the pointer optarg, defined in the library.

We can further use this optarg to process the sub-options. (Consider the case for x in the code)

The getsubopt (&subopts, indices, &casevalue) function, takes the pointer to the command line following the option parsed above, the array indicating the possible options (again indicated above) and a pointer to a string, which will contain the key-value pair(s) of the arguments.
This has some particular restrictions which are not necessarily pleasing to the programmer/user but I guess for now we have to live with it. For instance, the sub-options are delimited by comma and the key-value pairs are delimited by equal to symbol ( = ) we can't change that.
If a sub-option listed in the "indices" is encountered, the key-value pairs are extracted. This continues till there are no more comma delimited values encountered. Hence the same is put in a while loop with-in the case for "x" to extract all the sub-options.

When getopt() does not find an argument following an option, it returns "?". This can be further used to provide diagnostic messages or optionally terminate the program (as in my example).

I am including some running examples below, to help appreciate the library capabilities.

Examples:

$ ./opt -x ci=3,sub1=1,sub2=2
Hexahedron
Value of : ci is : 3
Value of : sub1 is : 1
Value of : sub2 is : 2

$ ./opt -h
USAGE:
-h -- prints this help
-t -- specify a tetrahedron case
-x -- specify a hexahedron case,
     a comma separated value list. ci=<caseindex>,
     sub1=<sub case index for face ambiguity resolution>
     sub2=<sub case index for interior ambiguity resolution>

$ ./opt -t 4
Tetrahedron : Case = 4

$


I hope this is useful when you are faced with a similar problem :)

Signing off,
Aks

GLUG... GLUG.... GLUT.... GLU.... GL

... ... ... And thus ends a horrifying story. The bad-man dies shouting
"Heeeeeeeellllllllllppppppppppppppp!!! I am drowning....
glug... glug... glut... glu... gl... "

Errr... that sounds familiar.
Why did GLUT come in the story that was meant for my nephew??

AAARRRGGGHHHH!!

Uh oh! you guys are out there!  I guess, that's the effect of sticking on to OpenGL for over a week now. 

I was struggling with OpenGL, right from where I started. First it was installations. Here is a nice tutorial to get OpenGL to work with VisualStudio. Looks good ain't it? Pretty cool too. Simple and Short tutorial. BUT! it didn't work for me on my laptop :( Tried the same on my desktop @ home, worked like a charm.
NOW! I am sure a lot of my friends would yell at me for not completing the work when and WHERE it was working.
Me - being ME, tried to get it to work on the super awesome Dell Studio 14, the lady on my lap ( :-P ) Spent a good one day ( give and take, considering I was on Facebook for 51% of the time I was in front of the studio )

Finally after a useless day, I decided its time to call it Quits for VisualStudio. What did I do about it? I Tweeted :D

On a serious note, I tried to find material online for OpenGL + Eclipse + Windows ( Well that was exactly my search string on Google ) nothing very useful came up. I was no Lucky after all by selecting Google's "I'm Feeling lucky". I guess there was some basic problem with setting up the libraries.

I "Moved on!" booted Ubuntu after a LONG time. Thanks to the guys who came up with the concept of "apt-get". How apt! I got the OpenGL libraries installed in few words on command line.

Copy-pasted a sample program from the net. Where was I when I expected it to work wonders?? I was drawn back to earth, when the compiler threw up 
fatal error:  GL/gl.h : No such file or directory. compilation terminated.

Thanks g++ for bursting the bubble :-|

Realized that the problem was with the installation of OpenGL libraries. Re-installed them.

Bingo!! worked like a charm.




PS: This post was not published when it was drafted :-/ i m wondering why. It was listed in edit-open posts in my blog. Here goes, published :D


PPS: Wrote this when i was screwing around with OpenGL in December 2010 :D

Saturday, March 19, 2011

Commodity Computing -- a FFT

Howdy Folks!!

Long time again since I blogged. My bad!

I keep wondering, how can a guy make same mistakes over and over again. Then I see my blog. I realize how!! :(

Grad school is keeping me busy and lazy in strict alternation ( I know! too much of OS Course ). Busy with assignments/projects and lazy otherwise. Awesome combination to keep me from writing :-|

An Interesting FFT -- "food for thought"( term courtesy our prof in college who writes this in the mails for math club ) thats what this post leaves you with.

This was a discussion that ensued between few geeks from Yahoo! and myself in the Hadoop workshop @ IMSAA ( in IIITB, dec 2010 ).

Wow! Dec 2010?? YES!! Discussion then, blogging now :)

After an elephantine 4 hour long session on Hadoop, I struck a conversation with the blokes who presented the seminar hoping to get some tips n tricks to get started with Hadoop. Okie! it has been so long since I spoke to them, I don't remember any of their names :(

My first question "Hey! can we set up Hadoop on commodity hardware?"
Bloke1: "Absolutely, we run all our Hadoop installations on commodity - off - the - shelf hardware."
For those of you who are wondering what is commodity hardware, here it is.

I got even more excited, the very thought of installing Hadoop on my lappy (ohhh! yesss she will be cursing me for abusing her sooo much! sorry baby :D)
This follows the fact that, just a day before I attended "Large data processing using Dryad LiNQ" @ Microsoft Research India office. I was disappointed there for the reason that, Dryad framework needs extremely chic systems to run on :( More on this sometime later. Like some texts state "Not in the scope of this discussion"

Before my next question, Bloke2 pitches in "what is your definition of commodity hardware?"
Me: "Err, my laptop?"

Bloke2: "Oh! actually, we can run Hadoop off a laptop, but it should be sufficiently powerful system."

Then came a list of "suggested requirements". Topping the list was : 2 quad core CPU doing a good 2.5Ghz. Woah!! where do I get it from???

Me: "Woah!! Ain't that some huge server?"
Bloke2: "Well, yeah, but we bought it off the shelf from market, which makes it commodity for us!!!!"

Here is one post which I liked for the 1st line. Paraphrasing it, I can write it as "my definition of commodity hardware is different from your's DUDE!!"
If you look at the recommended specification in the same page, ( please don't faint I want you to complete reading this ;-) ) its gotta be quite a big Momma machine :O

The later discussions with those Blokes from Yahoo! only discouraged me from installing Hadoop on my lappy ( sweetie-pie you are saved :P ) and hence, I am not even going to quote it here. ( clarification: I remember the discussion, even after Dec 2010 to March 2011 gap :) )

I was left wondering, does commodity hardware really mean commodity hardware for common man?

Me thinks, this IS some food for thought! What do you think??


Ps:
I hope to leave now, only to return soon!
C ya folks :)