Monday, June 15, 2009

Finally...Netbeans has it!!

Vim users had a significant advantage of being able to directly work on a server. Even in the most hi-speed and congestion free LANs, running Netbeans remotely on the server using X-forwarding gave a pathetically sluggish experience.
The upcoming Netbeans 6.7 solves this problem by a superb feature called remote development.
In this, you can you can map the remote files on a local folder and work on it using Netbeans on the client.Although You could have done it earlier also, the difference now is that that the the actual build takes place on the server and not your local machine. Of-course, you have to tell your username and password and the folder mappings for the server to Netbeans. Using features like make -j, you can exploit the multiple cores of the server to drastically cut the build time. Without this feature, it took 2 minutes to build the project on the laptop and now, it takes 2 seconds!(take this with a pinch of salt coz I did not ensure that everything else was constant. I did not intententionally manipulate the test conditions either)
Also you are saved the trouble of installing all the required software(build tools) on the laptop. Even the code-assistance works flawlessly(the data is gathered from the server).

I tried the release candidate of 6.7 and was more than happy with the results.
Moreover, it works both for windows and linux. In linux, I used sshfs to map the server folder to a local folder. In Windows, I used Expandrive to do the same.
You can refer to the following tutorial for details:

PS: netbeans doesn't have any stable plugin for git yet.


Tuesday, May 19, 2009

jumping from svn to git

If you are comfortable with svn but want to switch to git for a variety of reasons, this post is for you!
The major difference is that git has distributed repositories whereas svn has a central repository.So, instead of checking out a working copy from the central repo,in git we clone the repo to our local machine. The immediate advantage is that even when you are disconnected from the network, you can keep committing your changes to the local repo. When you get back the connectivity, just push the changes in the local repo to the remote repo.

This is a feature I missed a lot in svn.(while working in train/flight where connectivity is not available). Below is an illustration of a typical work flow:

  1. Cloning the remote repo(~= cheking out a copy in svn) : for the first time
    git clone repo_url
  2. make changes
  3. get changes of others from the remote repo(~= svn update)
    git pull
  4. commit your changes to the local repo
    git commit -a
  5. commit the changes in the local repo to the remote repo
    git push

Steps 4 and 5 are roughly equivalent to svn commit

Friday, May 8, 2009

replacing text using regular expressions

Regular expressions can be a very powerful tool for searching and replacing. Today I learnt how to replace text using regular expressions. The problem I faced was:
I got these 4 equations from the internet: Basically they give you the 4 parameters for a plane equation Ax+By+Cz=D passing thru 3 points (x1,y1,z1),(x2,y2,z2),(x3,y3,z3)

A = y1 (z2 - z3) + y2 (z3 - z1) + y3 (z1 - z2)
B = z1 (x2 - x3) + z2 (x3 - x1) + z3 (x1 - x2)
C = x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2)
D = x1 (y2 z3 - y3 z2) + x2 (y3 z1 - y1 z3) + x3 (y1 z2 - y2 z1)

I had to use these equations in my code. But my data structures were quite different. The 3 points were in an array of 3 points having fields x,y,z.

So the required replacements were as like:
x1 with poly->points[0].x
y2 with poly->points[1].y
z3 with poly->points[2].z

so on...(total 9 pairs!)
Also, replace the whitespace by * at appropriate places:

Smart soln:
Open the replace dialog in your editor. Select the "regular expressions" options.
I used netbeans but I think most of the good editors in linux support regular expressions

in find, enter: ([x-z])([1-3])
in replace, enter: poly->points[$2-1].$1
($1 stands for the text matching the contents of the 1st parenthesis in the find regexp. and so on..)

open the replace dialog again(to replace whitespace by * at appropriate places)
in find, enter: ([x-z])(\s)(\()
in replace, enter: $1*$3
This one needs some explanation. \s stands for whitespace. ( needs to be escaped because ( is also a token for regular expression defination syntax.

to replace whitespaces in eqation D, do:
in find, enter: ([x-z])(\s)(p)
in replace, enter: $1*$3

the results:

A = poly->points[1-1].y*(poly->points[2-1].z - poly->points[3-1].z) + poly->points[2-1].y*(poly->points[3-1].z - poly->points[1-1].z) + poly->points[3-1].y*(poly->points[1-1].z - poly->points[2-1].z);

B = poly->points[1-1].z*(poly->points[2-1].x - poly->points[3-1].x) + poly->points[2-1].z*(poly->points[3-1].x - poly->points[1-1].x) + poly->points[3-1].z*(poly->points[1-1].x - poly->points[2-1].x);

C = poly->points[1-1].x*(poly->points[2-1].y - poly->points[3-1].y) + poly->points[2-1].x*(poly->points[3-1].y - poly->points[1-1].y) + poly->points[3-1].x*(poly->points[1-1].y - poly->points[2-1].y);

D = poly->points[1-1].x*(poly->points[2-1].y*poly->points[3-1].z - poly->points[3-1].y*poly->points[2-1].z) + poly->points[2-1].x*(poly->points[3-1].y*poly->points[1-1].z - poly->points[1-1].y*poly->points[3-1].z) + poly->points[3-1].x*(poly->points[1-1].y*poly->points[2-1].z - poly->points[2-1].y*poly->points[1-1].z);


(People might say that writing 1 as 2-1 is inefficient but I'm sure that the c compiler does constant folding while generating the target code)

Friday, April 3, 2009

juggling with the static IP settings smartly!

Finally, my search for a commandline tool to configure the static IP settings came to an end with this article http://support.microsoft.com/kb/257748

First of all, I'd like to clarify that using commandline to configure IP setting should not be taken in "geeky" light. For those who never take their laptops out of their hostel room, it's okay to use the GUI to set IP settings once in a semester. But for guys like me who need to juggle between the IP settings of NAC and Kameng >= twice a day, it was a big pain to go thru the tedious process of configuring it thru GUI in Windows. No prizes for guessing that in linux, u could do it easily with the ifconfig command.

So, how to juggle the settings smartly(and geekily!)?
1) At Desktop, create a file SetKamengLANSettings.bat(it's is similar to the shell script of linux) with the following line:
netsh interface ip set address "Local Area Connection" static 10.9.2.156 255.255.0.0 10.9.0.254 1

2)create a file SetNACLANSettings.bat with the following line:
netsh interface ip set address "Local Area Connection" static 172.16.25.200 255.255.0.0 172.16.24.254 1

(replace IP , subnet mask and gateway addresses to match the settings of your hostel/lab in the above 2 commands.)

The above steps are required only once. Now all u have to do is following:

when u reach hostel, double click at the file "SetKamengLANSettings.bat"
when u reach NAC, double click at the file "SetNACLANSettings.bat"

Note: There is a minor twist in Windows Vista due to UAC: instead of double clicking, u need to rightclick the file and click at "Run as administrator" in the popup menunetsh