Sunday, February 03, 2008

Matching two arrays - One Line Beauty ..

Recently I wrote some "useful" code which I would probably release online as an open source; if things do not go as expected. Anyway during that, I had a requirement where I have to match two arrays and return the match %. So let us do it in C# 2.0 or Java for that matter. Look at my code ...

public double match(string[] array1, string[] array2)
{
int common = 0;
foreach(string val1 in array1)
foreach(string val2 in array2)
if(val1.equals(val2)) common++;
double avg = (array1.Length + array2.Length)/2;
return common/avg;
}


Now let us do it in C# 3.0 Way, using extension methods which are already written for us ..

public double match(string[] array1,string[] array2)
{
int common = array1.Where(item=>array2.Contains(item)).Count;
double avg = (array1.Length+array2.Length)/2;
return common/avg;
}


Isn't that sweet? Well, it definitely is sweet. You could do something like that even in Groovy..

public match(array1,array2)
{
def common = array1.find(it->array2.contains(it)).size();
def avg = (array1.length()+array2.length())/2;
return common/avg;
}


Well, the functions size() might either be length() or count() which I usually am confused and since I always an IDE to code, I usually do not take the pain to remember these simple(but important) details. Anyway, if you want to pick the common elements in 10 arrays, even then the code in C# 3.0 or Groovy is going to be 3-4 lines. So it 400% less code?

The point here is that languages are getting sexier with time and it is really fun to write amazingly compact code. For those who haven't tried LINQ, should really take a look at it. By the way, I did a little LINQ to XML and with very little code, it makes using RESTful web services very easy. Hats off! to all the genius who came up with these ideas (of course, Microsoft did not invent closures...)

Wednesday, January 30, 2008

String comparisons : == vs. equals()

It is a well known that you cannot compare two objects obj1 and obj2 using == operator. == operator checks for the equality of the references not the equality of the objects. Just a little snippet is shown below

Point p1 = new Point(100,100);
Point p2
= new Point(100,100);
System.out.println(p1
==p2); // ??
The above code snippet, when run, displays "false" in the output console. But still both p1 and p2 refers to a coordinate (100,100). So if you wish to get your equality to be true for such cases (where the object content! matches), then you should be using "equals()" method. This works for almost all the classes shipped with JDK. For this to work on the objects of the classes that you write (eg: Employee class or Chair or Bench.java), then you should override the method "public boolean equals(Object two)" and implement your meaning of equality of the objects of your class. Also note that, it is highly recommended and important that you override the "int hashCode()" method when you override the "equals" method.

Anyway, now when we deal with String comparisons, one should remember that "Strings" are not value types but are reference types (I mean String is a class). So Strings have to compared for equality using equals method instead of == operator. But the way the JVM is implemented, there are cases under which the == returns true for matching strings. So what are the cases?

Case 1: Where == returns true

String s1 = "Krishna";
String s2 = "Krishna";
if(s1==s2)
System.out.println("Strings are equal!!");
else
System.out.println("You cannot use == here");

Trying running the code as it is and you see the "Strings are equal" on the console. Well can you guess why?

The reason for the == operator to work in this case is that the Java compiler optimizes the strings s1 and s2. Since they are both "initialized" to "Krishna", instead of having two different string objects, optimization is done by having only one object and both s1 and s2 refer to the same "Krishna" object. Remember that the == operator only works for "static" kind of initialization. So if it was the case where s1 = new String("Krishna"); then s1 == s2 would return false instead of true, though it appears both are being initialized to the same "Krishna". Let us see another case where s1 == s2 fails.

Case 2: Where == returns false and equals() return true

String s1 = "Krishna";
String s2 = new String(s1);
if(!(s1==s2))
System.out.println("You cannot use == here");
else if(s1.equals(s2))
System.out.println("You should use 'equals' method in all cases");
Anyway the moral of the story is that you should always use "equals" to compare strings and should never use == even though it works in few cases.

Monday, January 28, 2008

More C++ Pointers

When you perform pointer arithmetic, you move the pointer to the next or previous element of the array. When you say ptr++ where ptr is an integer pointer, it is equivalent to ptr = ptr + 4 (mathematically) assuming integer is of 4 bytes.

Do not do math on pointers that does not point to array. If one keeps this in mind, then you would probably prevent most of the problems.

The following code snippet is perfectly legal:

int
*ptr = array;
ptr = ptr+2;
ptr--;
ptr++;

Consider the following declaration:

int
numbers[10];

In the above declaration, numbers is of type int const*. This implies that numbers even though is a pointer, is a constant pointer and it cannot appear on the left side of an expression(as a pointer).

int *numbers;

In the above shown declaration,numbers is of type int*. It can still point to an array of itegers and you can actually do a math and can appear on the left side of an expression. So the statement numbers++ in this case is perfectly legal while in the previous case; it is not legal.

Technorati Tags: ,

Sunday, January 27, 2008

.NET 3.5 : VB and C#

[The code in this post appears weird for some reasons, I used LiveWriter and few good but buggy plugins to attach code]

I recently made a list of ASP.NET Videos that are out there online. Excluding the MSDN Nuggets and Microsoft Webcast events, the listings spanned over 4 pages!!! I am really concerned and am cursing myself for not having watched any of those for years. I have actually been a close follower of videocasts/screencasts right from those days when there weren't that many online for free. Now Microsoft, I should say is the largest provider of screencasts, of course only about MS technologies and yet there are tons of their videos that I should be watching. (Of course, lets not forget about Channel 9 where there are quiet a lot more screencasts about everything from MS)

Anyway there is also this dnrTV.com which is run by .NET Rocks guys and provides .NET TV Sessions. The most recent two shows are really something that everyone who is learning .NET should watch. It is by Kathleen Dollard and gives a first hand explanation about .NET 3.5 and shows VB 9.0 and C# 3.0 side by side which is really something! The actual show can be watched here.

I am writing down some important points for my own use and others might find it useful. I hope I am not violating any rights(hopefully).The disclaimer is that the images shown below is taken from the show using Snipping Tool which is shipped along with Windows Vista. This is not my work and I hope not to make any violations. In case of any, please let me know so that I can remove this post online.
Anyway my notes follows ....

.NET 3.5 Assemblies:

.NET 3.5 The important aspect is that .NET 3.5 still has the same Core - .NET 2.0. Simply put .NET 3.5 is nothing but .NET 3.0 plus additional features and we know that .NET 3.0 is nothing but .NET 2.0 Core plus few amazing libraries like the WPF, WCF, WF, CardSpace. It is also mentioned by Kathleen that Speech library is shipped in the .NET 3.0 and it is not that well known.

.NET Versions

.NET Versions There have been five versions of .NET till date. While VB 7 and C# was for .NET 1.0 and 1.1; VB 8 and C# 2.0 was for .NET 2.0 and .NET 3.0.

Now the brand new C# 3.0 and VB 9.0 adds a lot of new features makes programming in these languages very exciting.

Anyway the slides look amazing, you should watch the show without fail if you are interested!


Nullable in VB vs. C#

Declaring Nullable in VB

   1: Dim x as Nullable(Of Boolean) = False
   2: Dim y as Boolean? = False   

C# Nullables and bit more code to help you understand what Nullables are!


   1: bool? x = null;
   2: if(x.HasValue)
   3:  Console.WriteLine("x does have a value!");
   4: else
   5:  Console.WriteLine("x do not have a value and is null!");
   6: bool? y = x.GetValueOrDefault(); //y is initialized to false!
   7: Console.WriteLine("y is "+y);

Differences:

Suppose x and y are nullable booleans and x is set to null/nothing while y is set to false. Look at these:
x == y => False in C# and Nothing is VB (since one of them is nothing!). So can you guess the output of the following VB code snippet!

   1: Dim x As Nullable(Of Boolean) = Nothing    
   2: Dim y As Boolean = Nothing    
   3: Console.WriteLine("x = " + ((x = y) Is Nothing).ToString)


Another note for beginners! Consider the C# code:

   1: Employee emp = null;    
   2: if(emp==null)    
   3:  Console.WriteLine("Emp object is set to null!");

The equivalent VB code is:

   1: Dim emp as Employee = Nothing    
   2: If(emp = Nothing) 'This does not return true, = Nothing is not equivalent to == null    
   3:  Console.WriteLine("You would not see this line in the output!")    
   4: If emp Is Nothing ' This is how you check for null!    
   5:  Console.WriteLine("emp Object is set to null!")


If you read the above code snippet, I have conveyed the message in the comment on Line 2.

Frankly there are lot more differences with respect to how operators work differently in C# than in VB. Simply put the key point to remember is that

In Visual Basic, comparison between anything that is null(Nothing) to anything else returns Null/Nothing!!

In C#, you cannot use any operator but == on boolean

Note: By the way a great tool for .NET Developers in Snippet Compiler!

Operators in VB vs C#

Ternary Operator in C#:

   1: bool buddi = false;    
   2: string nameOfBuddi = buddi?"Bhargav":"Someone";    
   3: Console.WriteLine("Buddi is "+nameOfBuddi); //Displays "Someone"    
   4: buddi = true;    
   5: Console.WriteLine("Buddi is "+buddi?"Bhargav":"Someone"); //Displays "Bhargav"

Ternary Operator in VB:

IIf was used as ternary operator in VB but it is actually a function! But in VB 9.0, IIF is an operator! The actual difference would be understood when you look at this snippet:
   1: Shared Sub Main()    
   2:   Console.WriteLine(IIf(true,Method1(),Method2()))    
   3: End Sub    
   4:      
   5: Function Method1 as Integer    
   6:     Console.WriteLine("Method 1")    
   7:     Method1 = 1    
   8: End Function    
   9:      
  10: Function Method2 as Integer    
  11:     Console.WriteLine("Method 2")    
  12:     Return 5    
  13: End Function


The output of the above snippet is

Method 1
Method 2
1

As you can see, Method1() and Method2() are first evaluated and then the appropriate return value is returned. Here since its true, return value of Method1() is returned on the screen.

Another note for beginners, in Visual Basic, you can return a value in two ways. The first way is shown in the above code snippet in Line 7 where you assign FunctionName = returnValue and the second way is to use return keyword, like in other languages. You can use which ever makes more sense to you, well based on your choice.

The next few features were actually present in earlier versions of VB and unavailable in C# ( the above talked features were in C# only until VB 9.0)

Contd...

Tuesday, January 15, 2008

Storage Classes in C++

Courtesy: Dave, UGA

Storage Classes

Storage class specifies where the object exists in memory. Also the lifetime of the variable's storage determines the storage class of the variable/object.

Automatic Storage
  1. Default for all the variables
  2. Object is created and destroyed within the block
  3. eg: auto float x,y;
  4. register storage classes is same as auto storage class. Just that it tells the compiler to place the variable to be put in registers(for better performance)
Static Storage
  1. Lifetime of variable is entire program execution
  2. static can be applied to local variables defined in functions or to global variables
  3. Keeps the value even after the function ends, if its a local variable
Scopes
  1. Global Scope - visible to any other file - extern
  2. File Scope - visible to only that file - static
  3. Block Scope - visible only within the block.
Some funda
  1. extern int globalVariable; This is a variable declaration and this can be specified any number of times. No memory is allocated to this variable yet and thus multiple declarations are allowed. If you have an extern variable and try to access it you get a linker error. To prevent this, you should define a variable of the same name. Then you have actually defined a reference.
    Ex: extern int gv; int gv; //then you can access gv.
  2. int anotherVar; This is a variable definition and this can be done only once. This variable has been allocated memory and falls under the auto storage class.
  3. static int getVar() If this function is present in File1.cc and if you try to invoke getVar() in File2.cc, then this is a compiler error since the scope of this function is limited to the File1.cc only.
  4. static has another purpose in C/C++. You have a static variable in a function foo(), then within foo(), increment the variable and print out the variable. Now within main call foo() three times. Then each time you get a different(incremented) value. That is the lifetime of the variable is "complete" program. As long as the program runs, the variable value would be stored. The value is restored even after the function returns.
  5. Global variables in C/C++ default to zero, while local variables are garbage!

Monday, January 14, 2008

What is the output of this C++/C Program?

When compiled using GCC compiler, can you tell what is the output of the following program?

#include
int main()
{
int y=10,p=20;
int num[10]={0};
int x=10,z=4;

num[-2] = -2;
num[10] = 10;
printf("%d\n%d\n",p,z);
}

This program is supposed to be compiled on SunOS, using GCC compiler. Running it on different machine might give a totally different output.

If you run this program, you would understand how dangerous is C++ arrays, if not properly coded. Ofcourse this program does not actually corrupt your system but it does corrupt one of the variables and at times this might be dangerous.

Courtesy: Got this snippet from Dr. Dave's class. But a different example. I really liked this simple program that conveys a very big idea.

Wednesday, January 09, 2008

My work till date ...

Below is a list of projects that I have developed/worked on. This is to let me have a good idea on what I have worked on, for the upcoming interviews.

Software Associate

Online banking system using CICS
Legacy Decommissioning of 21C Systems

Freelance Developer
VB.NET Scheduler Program(with GUI and Win Service)
FTP Uploader/Downloader(VB.NET)
IP and System Info(ASP.NET,C# Win Service, Binary Serialization, Set up projects in VS 2005)
C# to VB.NET Conversion(ASP.NET Project)
URL Ping Service(C# Win Forms, Set up package, SMTP Coding)
Localization in .NET(ASP.NET and WinForms examples how-to)
Social Networking (Java Servlets! Orkut clone like Software)
ASP.NET Content Management System(ASP.NET VB.NET)
Postscript Expression Evaluation in C#
ASP.NET GDI+ Cropping(ASP.NET)
Small Various VB.NET Projects
XML Serialization Tutorial and Sample project
Distributed Error Reporting Tool(C#)
Whois Lookup in VB.NET
various book reviews at java-tips.org
Personal Information Manager(VB.NET)
Java Servlets Project(my first work!!)
And few other small help projects.

School/Personal Work
Windows Registry Tweaker in C#
Windows Remote Desktop in C#
Bulk Mail Sender
Mail GUI and Proxy Server
Bulk Image Compressor
Mean Shift Tracker in Java
Blob Library in Java
URL Redirection Detection
Loads of Web Crawlers
Grails - BlockBusted Movie Website
and a few others which i cannot recall at this moment!

Tuesday, January 08, 2008

Configuring SWT Browser Preferences (2)

In one of my previous posts, I blogged about the way one could set SWT Browser Widget Preferences and there has been a comment on my blog!!! (well apart from the comments that my friend Suri makes)
The comment has rightly pointed out to a way that one could programatically set the preferences of SWT Browser widget. The way it could be done is shown in the following code snippet.

Browser browser = MozBrowserUtil.openMozillaBrowser("about:blank");
nsIServiceManager servMgr = Mozilla.getInstance().getServiceManager();
nsIPrefBranch prefs = ( nsIPrefBranch )servMgr.
getServiceByContractID("@mozilla.org/preferences-service;1",
nsIPrefBranch.NS_IPREFBRANCH_IID);

prefs.setIntPref("network.proxy.type", 1);
prefs.setCharPref("network.proxy.http", host);
prefs.setIntPref("network.proxy.http_port", port);

browser.setUrl(url);


Again, I thank the anonymous commentor for bringing this to my notice. I appreciate all your comments and would be better if you leave me atleast an email or a URL to your page/blog so that I can get back to you.

Thursday, January 03, 2008

Image Processing with Java


Small Background


This article is to help readers understand how to process images with Java. During my course work in Image Processing(8810) under Dr. Hamid R. Arabnia, I have developed this class that helps one to work on images, apply filters and other such operations. It lets you work with images at pixel level and is implemented well enough. Though my assignments were implemented in .NET for which I used Bitmap class, I wrote this utility class to help out my friends and surprisingly it did work very well. Well, cut the crap and lets go into some theory.


Practical Image


An image could be considered as a 2D array of Pixel. A pixel has a position (x,y) and intensity values (R,G,B). You have a color image and wish to covert the image into a gray scale image, then you extract these R,G,B values and then the gray level of that pixel in the simplest form is (R+G+B)/3 and replace each R,G,B with this average. Note that in image processing terminology, a gray scale image is different from a Black and white image. A Black and White image is also known as a Binary Image where the intensity of each pixel is either 0(Black) or 1(actually 255, white). A Gray Scale image has all R,G,B values equal.


Java Image Processing


There are several options in Java to develop image processing applications. The very well known library is the Java Advanced Imaging(JAI) Api. It is a very sophisticated API and does great work, but again, to understand JAI properly, one should really have a strong Image Processing fundamentals. Simpler options include the ImageIO API(again by Sun), ImageJ library and one very good library is the Hiof's Image Processing API. It can be found here. It is a very decent library and relatively old but does great job. And I have to market my own class. I do not call it a library but it has excellent methods that helps you work with raw pixel data. I call this library as ImageUtility and is available upon request. The following are the methods that are available in the ImageUtility:


1.LoadImage(String path) loads the image and returns the BufferedImage object

2.GetImageMatrix(BufferedImage img) returns the image passed as 2d array of integers. A pixel at (0,0) is accessed as returnedArray[0][0] and the value is between 0 to 255.

3.GetHistogram(int[][] matrix) - returns the int[] histogram of the passed matrix. A histogram is the distribution of intensities. For example, histogram[255] gives you the number of pixels whose intensity is White and histogram[0] gives the number of pixels whose intensity is Black.

4.GetImageFromMatrix(int[][] matrix) a function reverse to GetImageMatrix() method. Pass your matrix and get its bufferedImage object.

5.SaveImageToDisk(BufferedImage,String saveFileAs,String type) saves the image to the disk at the specified path(saveFileAs) as a image of type("jpg","png","gif")

6.GetBufferedImage(Image) Image is the super class of BufferedImage and yet is not straight forward to get a BufferedImage from an Image. This function does that exactly and trust me it is very useful.

7.GetHistogramImage(int[] histogram) returns the histogram as an Image, a graph that is more visual than an integer array.

8.ApplyFilter(int[][] filter,int[][] matrix) I should say this is the heart of the library. A Kernel/Filter is a 2D Array that does magic on an image. You can sharpen the image, do noise reduction(smoothing) and different other operations with this amazing filter. Consider the filter as a square piece of paper and your image as bigger sheet of paper. First put the smaller paper on the image paper such that both their (0,0) are on top of each other. Also both the horizontal and vertical borders of each should be aligned. I hope this gives and idea. Now you multiple each pixel positions and add the total value. For example, if you have a 3x3 kernel, first of all, you do a

   1: val = k[0][0]*i[0][0]+k[0][1]*i[0][1]+k[0][1]*i[0][1] +


   2: k[1][0]*i[1][0]+k[1][1]*i[1][1]+k[1][1]*i[1][1] +


   3: k[2][0]*i[2][0]+k[2][1]*i[2][1]+k[2][1]*i[2][1]




where k is the kernel array and i[][] is the image matrix.



Now you put the value at i[1][1] (the center of image where kernel is applied). Once the first position is applied, you just move the kernel by one pixel such that k[0][0] is now at i[0][1]. That way you move the kernel all the way till the row ends. Then you move by one pixel down and reapply the same way. That way you cover the entire image. This infact is a time consuming operation and thus it should be now obvious on why image processing suites such as Photoshop,Paint.NET and GiMP are CPU intesive.



Understanding kernels is very important. Most frequent Image processing operations could be done with Kernels. I recommend you take a look at some Image Processing book to get a list of some filters, I dont remember them now.



9. GetFilesList(dir) Just an out of field method. Given a directory path, it returns the list of files in that directory.



10.SaveImageListToDisk(ArrayList list,folderPath) Saves the images in the arraylist in the specified folder.



Well now it is time for me to explain some code. Some of you might not be interested in my code and might just want to know how to load images from disk, how to extract pixel information from the image, etc. The subsequent sections explains you this.



Reading an Image from Disk



We use ImageIO class to load the image. Shown below is the code that loads the image. It is exactly as in ImageUtility.LoadImage() method.





   1: public static BufferedImage LoadImage(String path) throws IOException


   2: {


   3: //Load the image


   4: BufferedImage img = ImageIO.read(new File(path));


   5: //If it is not a gray scale image


   6: if (img.getType() != BufferedImage.TYPE_BYTE_GRAY)


   7: {


   8: //Let us convert to Gray Scale.


   9: ColorConvertOp conv = new ColorConvertOp(ColorSpace


  10: .getInstance(ColorSpace.CS_GRAY), null);


  11: conv.filter(img, img);


  12: }


  13: return img;


  14: }




Saving the image to disk



Again we use ImageIO class. The following method is in my ImageUtility.java





   1: public static void SaveImageToDisk(BufferedImage img, String filename,


   2: String type) throws IOException


   3: {


   4: //very simple, use ImageIO.write()!!!!


   5: ImageIO.write(img, type, new File(filename));


   6: }


   7:  


   8:  


   9:  


  10:  




Extracting the image matrix, the raw pixel data



Get the WritableRaster using img.getRaster(). Then use getSample method from the raster to get the pixel intensity at the specified location(x,y). It is as simple as that.





   1: public static int[][] GetImageMatrix(BufferedImage img)


   2: {


   3:     int height = img.getHeight();


   4:     int width = img.getWidth();


   5:     int imageMatrix[][] = new int[height][width];


   6:     WritableRaster wr = img.getRaster();


   7:     for(int y = 0; y < height; y++)


   8:       for(int x = 0; x < width; x++)


   9:         imageMatrix[y][x] = (wr.getSample(x,y,0)


  10:                             +wr.getSample(x,y,1)


  11:                             +wr.getSample(x,y,2))/2;


  12:     return imageMatrix;


  13: }




Getting image from the matrix passed






Again, pretty straight forward operation like the GetImageMatrix() method. Get the WritableRaster and use wr.setPixel(x,y,pixel) where pixel is an integer array where pixel[0] is R, pixel[1] is G, pixel[2] is B. Look at the method.





   1: public static BufferedImage GetImageFromMatrix(int[][] matrix)


   2: {


   3:     int height = matrix.length;


   4:     int width = matrix[0].length;


   5:     BufferedImage img = new BufferedImage(width, height,


   6:                                           BufferedImage.TYPE_BYTE_GRAY);


   7:     WritableRaster wr = img.getRaster();


   8:     for(int y = 0; y < height; y++)


   9:         for(int x = 0; x< width; x++)


  10:         {


  11:             int[] pixel = new int[3];


  12:             for(int i =0; i<3; i++) pixel[0] = matrix[y][x];


  13:             wr.setPixel(x,y,pixel);


  14:         }


  15:     return img;


  16: }




How to apply filter?






The signature for the apply filter method is shown below. It returns the new matrix after the filter has been applied.





   1: public static int[][] ApplyFilter(double[][] filter, int[][] matrix)




Typical Image Processing Method



We have looked at the most fundamental operations that could be used to do amazing IP operations in a simple fashion. A Typical image processing operation could look something like this.





   1:  


   2: void Sharpen(String imagePath,String outputPath,int[][] sharpenFilter)


   3: {


   4:     BufferedImage actualImage = ImageUtility.LoadImage(imagePath);


   5:     int[][] actualImage_matrix = ImageUtility.GetImageMatrix(actualImage);


   6:     int[][] sharpenedImage_matrix = ImageUtility.ApplyFilter(sharpenFilter,actualImage_matrix);


   7:     BufferedImage sharpenedImage = ImageUtility.GetImageFromMatrix(sharpenedImage_matrix);


   8:     ImageUtility.SaveImageToDisk(sharpenedImage,outputPath,"jpg");


   9: }




The above image could actually be placed in the ImageUtility.java but sometimes you might want to repeatedly apply certain filters in a sequence. Anyway the above method gives the basic idea on how to do image processing operations. The sharpenFilter, like I said earlier, I dont remember, anyway it is just a 2D integer array. Actually a double[][] filter makes more sense. Anyway my idea behind this article is to give fundamental understanding on how to do image processing operations on images with ease. Not many internet resources has this simple a code to write an image processing java code. I hope this helps atleast a few people.





Email me at krishnabhargav@yahoo.com in case you need the complete ImageUtility or some guidance on Java Programming or Image Processing.

Friday, December 28, 2007

trueBuddi Image Compressor

The pics we take with a digital camera are usually around 1.5-3 MB based on the resolution. I often waste time and bandwidth to upload such big images in websites like snapfish, orkut, facebook, flickr. I always wanted a simple utility that could be used to compress images in a folder. I wrote one software during my BE but did not carry it with me to US so I always had to use some Paint.NET or other Image Processing tools.
I started my new year coding with Image Processing tool - trueBuddi Image Compressor.
I would upload it on my website. It is very easy to use and is available
here
It requires .NET Framework 2.0 to run. Right now it compresses images within a specified folder and that too only those with .JPG extension.
Future revisions:
1. Individual File Compression
2. Image Processing Operations - Contrast enhancement, Brightness, Noise Reduction, Sharpening, etc.
3. Support for conversion among JPG, TIFF, PNG and other such types.
Ideas welcome. The tool is free to use and is not restricted with any kind of license. You can do a Reflector and anything that you want. Just do not change the title of the Frame.

Upcoming Screencasts

UPDATE: In case I am the Tutor for Java Programming, I would record these screencasts when I am teaching my students, otherwise this project is almost shelved until February!
I plan to release my screencasts on the following topics.
1. Object Oriented Programming in Java
2. Design Patterns in Java
3. Java EE Development

Disclaimer: I am not a guru in any of the above mentioned topics but I love programming and these are for my friends who are the only few visitors to my blog. So if there are any mistakes by me, please bring it to my notice so that I will learn better and I am not responsible for what so ever happens because of these screencasts.

Originally, I wanted to host my screencasts on truebuddi.wikidot.com but it does not allow me to attach video uploads. I am looking for Google Jotspot and I hope it would allow me to post videos. In the worst case, you would have to download the files from the link I give.

If you have more suggestions, let me know.

For now, here is one video that I would upload TurboGears-Getting started.

Free Screen Recording Tools

I have been searching a lot for free Camtasia alternatives that would allow me to prepare screencasts. Till date I have found three good tools

1. Free Screen Recorder
http://www.nbxsoft.com/screen-recorder.php
Pretty decent tool, allows you to save screencast as AVI files. Best option is to download Vista Codec Package from http://www.free-codecs.com/download/Vista_Codec_Package.htm and in the settings choose XVID compression with as least quality as you want. You can record voice too.

2. DebugMode Wink
http://www.debugmode.com/wink/
A much more complicated software, allows you to store captures as SWF files. Lots of options but little bit uneasy to use.

3. CamStudio
http://camstudio.org/
Free and open source. But resource intensive. Good for high end systems.

Another good tool is ZoomIt by SysInternals. It helps you zoom particular portion of screen, would be useful when u want to show something more clearly, during presentations or screencasts. Free download from
http://technet.microsoft.com/en-us/sysinternals/bb897434.aspx

More on sysinternals tools, you get awesome little tools at http://technet.microsoft.com/en-us/sysinternals/0e18b180-9b7a-4c49-8120-c47c5a693683.aspx and they are all free. Amazing tools, trust me.

Saturday, December 08, 2007

What next?

The semester is almost over. Two more exams and I will be done with the Fall 2008 semester at UGA. Looking back, one question that every student should probably ask himself is "Was I a good student?" By that I just mean what did I learn this semester? Well, I should say it was not the most inspiring semester I had in my student life, but definitely one of the hectic semester. I did learn a lot about simulation, especially parallel, distributed simulation, worked on my thesis to a great extent, participated in international capture the flag competition, attended an unsuccessful interview, realized that I am good but not good enough to become one of the best developers for a company. I developed a bad game, developed a great soccer simulator, developed a good library that can be used to develop P2P-ized applications, worked a lot on web crawling, evaluated a lot of "browser" frameworks, worked on SWT, worked on Silverlight, worked on VS 2008 Beta 2, taught a thing or two to my friends about .NET, read a lot about web security, read a lot of papers on simulation. Keeping all this in view I should say that it has been a very eventful semester. Things have been pretty bad on the personal front, but I guess thats the way I become more strong and better.
I really am looking forward for the next year. I hope it would be a totally different year and I hope it would be the way I want it to be. As a new year resolution, I plan to quit smoking right from the 31st. I know it is bad and I should not smoke.
Coming to the technical front, I have few holidays coming this month and I hope to work on the following.

You should see this presentation and would know why I chose these...
http://static.raibledesigns.com/repository/presentations/ComparingJavaWebFrameworks.pdf
1. Java Server Faces
2. Struts 2
3. Spring
4. Tapestry
5. Wicket, Stripes
6. Tiles, SiteMesh

I feel my resume is more of .NET and I really am not that bad at Java and neither am I that good at .NET. I really was good at .NET till 1.1 I used to know quite a lot of 1.1, be it asynchronous calls or anything else that complex, I was good at it. But not any more. .NET is now an ocean and my knowledge is really now very little. But the job front on Java Web looks more promising and it would probably add more value to my resume if i can develop applications on both JAva and .NET platforms. Let me see where my learning would go!

Wednesday, November 28, 2007

Code to worry!

In this post, I intend to post something that we discussed in our Advanced Computer Network and Security.
1. fork() - too many forks could halt the system, if the malicious code has enough privileges to launch that many forks. This is probably not a great problem to worry about but could be given a thought!
2. The talk was interesting. We were shown a simple echo server code that when run and well exploited can give you a shell to own! Through which you can list files and do everything that you can do from a Bash shell. So what did the program have?
The problem was that the array size was fixed and then the exploit was to copy large buffer onto a smaller buffer causing a buffer overflow attack. The exploit data has to be carefully crafted. Anyway, StackGuard is a simple fix that works for most of the buffer overflows. The other fix is to have a pointer declared in the first line of the function and save its current reference and at every exit, you are going to check if the saved value did not change. I know this does not make sense unless you see the code, but unfortunately I do not have that. The overall summary is to say that when you copy buffers, you should be careful to see that the copy is going to be safe. Few commands that i came to know. You have a port x open and then see what service uses that, you could do a
/usr/sbin/lsof | grep x
3. Using netstat to check the open ports
netstat -lt
Anyway class over so more on this later,hopefully.

Wednesday, November 07, 2007

Java Game Programming using JGame

I came across this wonderful 2D Game Engine called JGame. This is a very good engine to write simple games and with just 100 odd lines of code, you can write wonderful games! I would post a series of tutorials shortly, but meanwhile it is a good point to start
http://www.13thmonkey.org/~boris/jgame/JGame/tutorial/
Great work Boris Van Schooten!! Really amazing!

Sunday, November 04, 2007

Getting Started with OpenSocial API


Orkut applications

On Thursday, Google announced their new API called the OpenSocial which can be used by developers to develop Google Gadgets like applications for their favorite Social Networking websites like the Orkut, Hi5 and a lot more. More information about this could be found at:
http://code.google.com/apis/opensocial/partners.html

One could take it a new revolution, a combined war against the most popular social website - the Facebook. Around 14 social networking websites have partnered Google with their Social API.
Coming to the development of such Gadgets for Orkut like websites, you are required to have a basic but fundamental understanding of developing Google Gadgets. You are required to know Html, JavaScript and XML. I have just followed the Google's sample application and one thing that puts off Google to a lower standard is the way they document their API. Compare Microsoft and Google, I bet Microsoft's documentation is by far the best that is available on the internet. The Google documentation, I think is more above standard. I think the technical writers team consider the audience to be as talented as those who work at Google but unfortunately we are not! right?

I always think a hello world application should be very basic and should include everything that one needs to know. The tutorial at http://code.google.com/apis/opensocial/articles/firstgadget.html assumes that you have basic understanding of Google Gadgets and not about OpenSocial API. It does a great job to explain how to proceed with development of OpenSocial Applications but then it does not tell you how to add that gadget you developed to your Orkut account and so forth.

Well this is what I did!
1. Go to http://code.google.com/apis/gadgets/docs/gs.html#GGE
2. Go to File->New and Select Hello World Gadget. You get the basic code for Hello World gadget
3. Copy and paste the following code into the editor you see in the following link.
http://hosting.gmodules.com/ig/gadgets/file/104220043972318336267/buddiKut.xml
I apologize for not being able to show the code here. But it is my fault and I am lazy not to work around pasting HTML code in the blogger. The best thing you could do is paste the xml you see in some XML editor or refer to the actual source (firstgadget.html)
4. Now click on File->Save and give it a name. Once the file is saved, on the top right corner of the editor you get a Hyperlink with the filename you just gave. Right click on the link and copy the link to your gadget.
5. Now assuming that you have signed up for SandBox Orkut account ( you need to do that by going here http://code.google.com/support/opensocialsignup and you should already have an orkut account) sign into your orkut account with this link 'http://sandbox.orkut.com'
6. Then you see a "applications" menu item just where you see lists,testimonials and other such items ( left side of the page) (as shown in the figure)
7. Now click on that applications link and you see a page with a textbox asking for application URL. Paste the copied URL on to the textbox and click on "Add Application".
6. Once you add the gadget, you see a People API How too item added to your menu just above the applications (See figure). Click on that and you would be taken to a new applications page and you can see your application in Action!!!

Isn't it great?? You have complete access to your friends data and a lot more programatically and imagine all the possible applications that you could develop!

I hope we will be given a profile KEY which is unique for a profile and which can be used within the application and make the Gadget run outside these social networking websites!!! That would be very great ! There might be a better tutorial by someone with more knowledge about this but just that I wanted to be one of the early adopters! Who knows whats waiting for one!