Thursday, May 24, 2007

I learnt AJAX!!!

I just updated my Graduate Web Page at http://cs.uga.edu/~krishna
It was a good learning experience to come up with some decent color combinations. I used online color picker tools, well I dont have the link for the tools I used, but here is one good article that gives interesting insights on color-combinations.
http://www.limov.com/colour/schemes.lml

I developed a similar tool in ASP.NET, first using non-AJAX approach and then made the application an AJAX one. It was a great feeling to develop an AJAX application and trust me, with ASP.NET AJAX, we can develop AJAXify any web application in no time and absolutely zero coding.
Here is what I did!
1. First I created a User Control, which had the pallette selection. Then drag and drop ScriptManager control and UpdatePanel on a new ASPX page.
2. Drag and drop the User Control you just created into the Update Panel.
3. Compile and run! all the changes in the page are ajaxified!!!
Absolutely no coding!!!!

I always felt that I lacked good color scheme selection ability, but now with my own tool, I can select a variety of themes!!!
I hope I have some online ASPX Web Hosting service. I intend to buy an ASPX portal very soon and then I can upload the tools I make once a while!

Saturday, April 07, 2007

Research for Summer

With may 10th 2006, the first term with UGA will come to an end. Then I am planning to move on and work on GWT and ASP.NET. And as for my thesis, I am planning to work on P2p Media Streaming - especially I would like to study and enhance the current p2p media streaming networks and come up with something really good enough for my thesis. Hopefully I would stand on this and work further to bring up something good.
Just got few books on p2p computing in java and .NET, also the core technology book to study the underlying systems. Have to wait and see if this plan of mine will work!

Thursday, March 29, 2007

Mean Shift Tracking in Java

After long long attempts to learn - understand the Mean Shift tracking, I have finally implemented the Kernel Based Object Tracking in Java. First I have tried to implement the tracker in openCV but I had some problems with the rectangle selection(the bounding box) so I moved back to Java and implemented the code offline using Java Media FrameWork. I have written a nice small class using JMF which we can use to extract frames out of a given Video file. There is no support for WMV format - it says NoPlayerException and some DivX formats, but then most of the files were played successfully.

My tracking results are shown below. Shown are the first, 19th and the 10th frame of a striker - video courtesy "WEB".


Monday, March 12, 2007

asp.net 2.0 - fun to learn

I have just started working on ASP.NET 2.0 again after a long long time. Its been almost an year since I did some serious coding and I want to get myself updated with the latest - asp.net 2.0.

I decided to use the Core ASP.NET reference book from MS Press and have been going through fundas like the IIS 6.0 Process model, HttpRuntime queue and so on.

How to detect the browser programatically in ASP.NET?
---------------------------------------------------------
You have the Request object with you. You can access the Request object either directly or from the HttpContext object. To detect the browser you are running ....

Dim browser as String = HttpContext.Current.Browser.Browser

For IE, browser would be "IE" and for firefox, its Firefox.

More about the HttpContext....

Actually, ProcessRequest method is called on the HttpRuntime object when a request arrives. Just before it serves a page to the request, a "context" is created which could be accessed through the HttpContext object. The HttpRuntime object uses the HttpContext object to locate or create a Web App object that is capable of handling a request it gets. There is an internal object that will be used to do the search - HttpApplicationFactory which maintains a pool of HttpApplication objects to serve incoming http requests. The HttpApplication is the base class that represents a running ASP.NET application. It is this object that determines what kind of a handler is needed - basically it decides what kind of resource is being requested - whether its a web page being asked for or a web server or a server control, etc.



Page Class and important members
-----------------------------------

The following is the list of important members of the Page class.
  1. Application - instance of HttpApplicationState
  2. Cache - instance of Cache class, implements cache for an asp.net application
  3. Request - instance of HttpRequest
  4. Response - instance of HttpResponse
  5. Server - instance of HttpServerUtility, helper method for processing web requests.
  6. Session - instance of HttpSession.
  7. Trace - instance of TraceContext, used for tracing.
  8. User - represents the current user whose request is being processed.
There is also a Context object that could be used ( it holds for HttpContext.Current).

From my past experience coding ASP.NET web apps, one most important thing that a newbie should always learn is the Page life cycle. By Life cycle in an application programming model, we basically mean what events are fired at what time. The ordering of events become very essential especially when the application grows. Knowing where to put initialization code, where to add controls dynamically, etc will help us code better applications.

The ASP.NET Web Page life cycle is given below.
  1. PreInit
  2. Init
  3. InitComplete
  4. View State is now restored
  5. Posted data is processed
  6. PreLoad event is fired
  7. Load event is raised
  8. LoadComplete (in between few events for handling postback is taken care of)
  9. PreRender
  10. PreRenderComplete
  11. SaveStateComplete
More information is given here
ASP.NET 2.0 Page Life cycle
http://www.robincurry.org/blog/content/binary/o_aspNet_Page_LifeCycle.jpg

I will post more as I get deep into the subject. I plan to devote an hour a day once the spring break is over.

This is what I think I will/should be doing
1. Core ASP.NET 2.0
2. Data binding with ASP.NET 2.0 and ofcourse ADO.NET
3. ATLAS / ASP.NET AJAX.

Then may be I can get hands-on with XAML,WPF,WCF,Windows Workflow...Gosh there is a lot to learn....

Sunday, February 04, 2007

Makefile to compile java programs

The following is the makefile to compile java programs:

all: | remove_classes ProxyServer.class

remove_classes:
rm -f *.class

ProxyServer.class: ProxyServer.java
javac ProxyServer.java -nowarn


The order of execution of jobs within the makefile can be normal or we can specify the order. The jobs listed after the pipe (|) are all orderly, as mentioned above.

all: | first second third

Makefile can be executed as:
> make

If target-name is omitted, then the first job is run. So in the first job, we name it as "all" and then there we specified the jobs it should run, along with the order. It is simple to understand that the current make file removes all old class files and then compiles the java program to get the latest class files. Though this is not needed, as javac would update the class files, this simple example helps us to understand "make".

Have fun!

Setting path variables in Linux permanently

Recently I have installed Linux Ubuntu on my laptop on top of Virtual PC. There is a very good post on how to do this at this link:
http://arcanecode.wordpress.com/2006/12/19/installing-ubuntu-on-virtualpc-step-by-step/

Then I had installed Eclipse and JAVA 1.5 on the new linux workstation! I wanted to work out a few programs on the linux platform.

When you start the terminal in Ubuntu and type "java -version", it displays the version but as you notice down it is not the Sun HotSpot VM that is running but is the GCJ, a free java compiler which doesnt actually interpret. So you would like to change the system to use the Java VM you installed. For that the obvious way is to change the Path variables for JAVA_HOME and PATH.

You can set a path variable using "export" command as :

export JAVA_HOME=/opt/jdk1.5.0_11
export PATH=$JAVA_HOME/bin:$PATH

When we set PATH variable, we should not forget to append already existing path variables( using :$PATH).

Now when you type "java -version", you can see your Java VM as HotSpot one. But then close the terminal and open it again.

Again try the "java -version", you will find your settings to be gone! What happens is that your settings were temporary and effective only for the terminal window that was launched and path set. In order for the variables to be effective for the user throughout the sessions, you should edit the bashrc script.

You can set environment variables permanently for a given user by changing the bashrc:

>pico ~/.bashrc

This opens the bashrc for you. Paste the two lines of "export" i mentioned earlier. Make sure you give the path of your JDK properly.
Save the changes and exit.

Now type

>source ~/.bashrc

This updates the changes made the new variables have been set. To test your settings you can now type:
"which java" and it should display the path of the java compiler that is being use( the one you set in the bashrc).

I am trying to find out how to set variables to reflect on all the user accounts !!! Let me know in case you guys know how to!

Thursday, October 12, 2006

Crank! I will watch that soon!

This article supposedly will help good developers develop good design for their websites. I have always had this problem. I always felt I lacked this "good designing capability".

http://peterkellner.net/2006/08/28/msprofcsshowto/

I did not go through it yet. But once I am home I would study that and make some observations.

Speed launch of Studio products

Its been around 6 months since I used Visual Studio and worked on any .NET application. So I am having problem of amensia - memory loss!! :D I have been using the /nosplash option with Visual Studio since long, since I started real coding on .NET! But sitting idle in my office and browsing the internet, it took me a long time to recall "what was the option that I used to quickly launch Visual Studio?". It is the "/nosplash option, which you can give in the TARGET of your Visual Studio project. For example, you can launch the Visual Studio from Start->Run and type "devenv". You can see the usual Splash screen. Its very elegantly designed, but still I dont want to see it everytime I start Visual Studio(I used to launch Visual Studio around 20-30 times a day!) So you can use this handy tip. Type
"devenv /nosplash" and press enter. And Splash!!! your Visual Studio is straight up! and working fine!

This post is just to make sure that incase I forget that myself, I know where to look out !

Signing a weak assembly in .NET 2.0

Just came across this post on MSDN Blogs. It says "Signing an unsigned assembly in .NET 2.0". Usually I dont find such things interesting, but gone are those student days and being a professional, there are some "corporate" things to be learnt. So recently I borrowed a book from library "Introducing .NET Framework" by O'Rielly. It was an old book, dated .NET 1.0 beta 2 release!! but still I felt I learnt a lot of new details regarding .NET Framework, especially about the CLR and stuff like that. So I found this one interesting. I have made some notes which I would post it in the future.
For now, take a look at this.
http://blogs.msdn.com/neerajag/archive/2006/10/12/signing-a-existing-net-assembly.aspx

Wednesday, October 11, 2006

Height of Sincerity!

well the title would not make any sense for another two to three days. Thanks to my colleagues that I am nominated for the Best Learner and Best Guide awards for the FLP batch. Friday, the 13th! is a big day for us, FLPites. Its our Graduation day and the day when we get a hint of our "what next?"

Old habits die hard and my taste for .NET still remains. So I often keep browsing about Microsoft and .NET. In that process I read some excellent blogs. One such blog is here. Its an index of Various "How-to-deploy" on Visual Studio. It is a must-look!
http://blogs.msdn.com/astebner/articles/574618.aspx

I would not change the heading of my blog. But I would like to post few comments on the currently technology I am working on! Surprisingly, inspite of not liking the platform, I am doing pretty well on Mainframes! As a developer who fine tuned his programming skills among OBJECTS, working on COBOL, developing applications with CICS appears awful. But still, you have to do it.

One thing that we should appreciate about coding Cobol on Mainframes is, with the tools I used so far, I now feel that I can survive coding without the help of Visual Studio or Eclipse or any IDE for that matter. If you can manage a project on TSO, trust me, you can do wonders with Visual Studio and other IDEs.

There is a lot to learn about Mainframes - CICS, COBOL and JCL! But still somehow I feel I dont belong here. I plan to move to .NET professionally too....

More insights later. I also plan to post tips/guide for mainframe beginners! Now - I aint a beginner anymore and I do have valuable suggestions and tips on Mainframes too!

Friday, September 29, 2006

After a long time

Well hi to those non-existent visitors of my blog ! :)

Lots of work got updated on the Microsoft development front(in my unfortunate absence). Anyway this post is to just store a link about UpdateControl, an aTlas how-to. Wonderful job done, i find it pretty soothing as i have just completed reading Atlas At Last:MSDN Mag article. Take a look at the how-to :
http://blogs.msdn.com/trobbins/articles/678575.aspx

Wish I had a PC at the place I stay :(

Wednesday, May 03, 2006

Step by step guide to Web Services

Firstly, this is no documentation for Web Services and neither do i wish to make any. I dont discuss any inernals on how web services work. It is just a step-by-step guide to develop Web Services and consuming them in .NET. I prefer VB.NET for this tutorial. I use layman terms and if you have some problem with my language, visit MSDN and learn-dont bother to visit again.
What are Web Services??
I would say a Web Service is a DLL that is referenced through the internet using HTTP protocol. Instead of shipping your business logic along with the application, as a DLL, we can make it a web service and host it as a website. But all it does is to provide the same services as a DLL - i.e no presentation involved.
How to create a web Service?
1. Start Visual Studio 2003. Go to VB Projects -> ASP.NET Web Service -> Give a project name and click OK.
2. Click on Switch to code view on the designer view you get. We dont need a designer so we go to the code view.
3. You can notice a Hello World method commented. Copy the same and paste it and this time uncomment it. That is your code file should look like this.

_
Public Class Service1
Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

' WEB SERVICE EXAMPLE
' The HelloWorld() example service returns the string Hello World.
' To build, uncomment the following lines then save and build the project.
' To test this web service, ensure that the .asmx file is the start page
' and press F5.
'
' _
'Public Function HelloWorld() As String
' Return "Hello World"
'End Function

<WebMethod()>
Public Function HelloWorld() As String
Return "hello world"
End Function
End class

4. Ok your web service is ready. Just "Build" the project clicking on CTRL + f5). It starts up IE showing a sample page. That looks like the one shown below!

Service1
The following operations are supported. For a formal definition, please review the Service Description.

HelloWorld

5. Click on the "HelloWorld" and you are taken to a page that has the SOAP Headers and HTTP Post descriptions along with a Invoke button. Click on the "Invoke" button. the output you get is as follows.

<xml version="1.0" encoding="utf-8" ?>
<string> xmlns="http://tempuri.org/LearnWebServices/Service1">hello world</string>
The webservice is working perfectly. I dont intend to discuss the above XML, its self explanatory.

How do you consume a Web Service?
1. The above described way is to check if a webservice is working properly. It is not the actual way to use a Web Service. In order to use a web service in Visual Studio, add a new Windows project to the same solution. Right-click on the newly added project and click on "Add Web Reference.." and in the page you get, click on the "Web Services on the Local Machine".
2. Then you get a list of the webservices that are available on your machine. Click on the one which you just created(i renamed my .asmx file in the web services project to SampleService, so i ll click on the SampleService in the window). Give some proper "Web Reference Name" above the button - "Add Reference". Click on the button to add the reference.( I gave the Web reference name as "LearnWebServices" )
3. Reference has been added. It actually checks to see if the service is upto date without any errors. Only then it adds the reference. You can then see a web References folder inside the Solution Explorer for the WindowS application project.
4. Now add a button to the form in the win app project. In the click event, write the following code.

Dim s As New LearnWebServices.Service1
MsgBox(s.HelloWorld())

5. When you run the Windows application and click on the button you get a "
hello world" message displayed. The first execution is always slow, but later on you see the message displayed immediately. What i did in the above code is to instantiate the Service1 class and then call the method on its object. You can notice that its just as if you are using a Local library!

Some Issues?
The coverage is not complete. There are books on writing Web services and i dont have any intention for competiting them. I discuss few more issues as days pass by but for now, some notes follows.
1. You can write as many classes inside the web service, just the methods should have the <WebMethod()> attributes. There could a non-webmethods inside the webservice, but they cannot be accessed directly like the Web methods.
2. Method overloading is not directly supported. in order to overload methods we need to use specific attributes. If we overload Helloworld() method and try to test the web service, we get this exception -

Overloaded methods

<WebMethod()> _
Public Function HelloWorld() As String
Return "hello world"
End Function

<WebMethod()> _
Public Function HelloWorld(ByVal name As String) As String
Return "hello world " + name
End Function


The exception we get when we try to run the web service is
Both System.String HelloWorld(System.String) and System.String HelloWorld() use the message name 'HelloWorld'. Use the MessageName property of the WebMethod custom attribute to specify unique message names for the methods.

The correction needed is to add a MessageName property to the web Method!! As shown.

<WebMethod()> _
Public Function HelloWorld() As String
Return "hello world"
End Function

<WebMethod(MessageName:="HelloWorldWithParamter")> _
Public Function HelloWorld(ByVal name As String) As String
Return "hello world " + name
End Function

As you can notice we use the named paramters in VB.NET. Figure it out on how to use this in C#.

3. Another difference with Web Methods is that Parameters when reference types are passed as paramters and changes are to be reflected, then ByRef has to be used unlike in the case of local methods where ByVal and ByRef mean the same for the reference types.

4. When you make a changes and compile the Web Service again, you shoud REBUILD the web service project. Also you should "update web reference". For this right click on the Web references/LearnWebServices in the solution explorer and click on Update Web reference.

Well thats all for now. See you later with more tutorials.

Wednesday, April 26, 2006

ASP.NET Boom!

Its been quite a long time since i posted an entry here. I was busy with all my work, exams, projects, jobwork, learning, movies and a lot more :)
Well ASP.NET 2.0 is too good to work with. We can make excellent and very powerful controls by mixing some of the already existing controls. And yeah! I did try and made one. I worked recently on "making a Tab Control in asp.net 2.0" and also a "Scrollable Datagrid". In the later entries i would post some tutorial on both.
Also Microsoft is giving great support for ASP.NET, probably ignoring the Windows Applications a bit. And trust me, I am seeing more and more Asp.NET 2.0 website projects everyday and very soon we get to see as many asp.net 2.0 projects as that in PHP! Definitely an excellent technology to learn and not only that Microsoft has provided excellent video tutorials for free ! there are two sets of tutorials - one "How do I?" series and the other is a Visual Web Developer Express tutorials. Both of them are available for free download at
http://msdn.microsoft.com/asp.net/learning/learn/newtodevelopment/default.aspx#Multimedia

http://msdn.microsoft.com/vstudio/express/vwd/learning/default.aspx

more links available at
http://msdn.microsoft.com/asp.net/reference/multimedia/#aspnetHowTo

And guess what they are giving more publicity for VWD than that for Visual Studio 2005 and that too when VWD is for free. They have seriously had some tough competition from Eclipse which is no doubt an excellent IDE and is for free. So they probably want to give something for free which would not effect the sales of VS 2005 and at the time is as powerful as that.

Even I got to watch those videos and once i get the time, i would love to watch and learn more about ASp.NET 2.0

Next post i would talk about servlets and their issues. A bit depricated but really good like any other Java Technologies!

Saturday, March 18, 2006

Newbies guide to Servlets.

I better kiss ASP.NET and bang the heck out of servlets. Agreed, servlets are easy to program to a certain extent, but when it is for presentation oriented applications they are terrible to work with. They just mess up your code so much that you begin to hate it yourself.
Anyway, for those who doesnt know servlets - heres a sample servlet and steps.

1. Download Apache Tomcat Server(the best for servlets) and install it.

2. In the installation folder you can see " webapps " folder which is the root folder for your server. You copy your applications into this folder.

3. Write your servlet and compile it. Take a look at sample servlet.
import javax.servlet.http.*;
import java.io.*;
public class SampleServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws Exception
{
doPost(req,resp); //call post method handler
}

public void doPost(HttpServletRequest req,HttpServletResponse resp) throws Exception
{
PrintWriter out=resp.getWriter();//obtain the stream to the output - to the browser
//we need to render html content as shown below.doesnt this suck???
out.println("
<html><head><title>Sample Servlet</title></headgt;<body>");
out.println("Bhargava's blog rocks!!!</body></html>");
}
}

How to compile??
Nothing different, but make sure you add path to the Servlet-api.jar which is present in the common/lib folder of Apach tomcat installation folder. How do you do that? well figure it out yourself. otherwise mail me.

4. Now that the servlet is ready, compile it and keep the .class file aside. Now Create a folder, say TestServlet and create a WEB-INF folder inside this folder. Inside the WEB-INF Folder, create a "classes" folder and copy your servlet class into the file. I shall give you a web.xml which is to be placed inside the WEB-INF Folder. Copy the TestServlet folder to webapps directory of the Tomcat installation folder. The following is the directory structure you should get as a result.
Apache installation path.....\webapps |-TestServlet
|-WEB-INF (-> web.xml is also present in web-inf)
|-classes
|-SampleServlet.class

5. Actually the better way is to create a .war archive. Create WEB-INF and place web.xml in it. Also classes directory with SampleServlet .class inside it. Go to command line and navigate to the folder which has this WEB-INF and type the following
jar cvf TestServlet .war WEB-INF
You can just copy the generated war archive into the webapps folder of Tomcat and restart Tomcat.
6. The web.xml is the configuration file that tells the container what servlets are available and other information(i dont know !! ) create the web.xml as it is. Try to understand what it says.

<?xml version="1.0" encoding="ISO-8859-1"?>


<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<!-- SERVLETS INFORMATION STARTS HERE -->
<!-- sample servlet for testing -->
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>

<!-- end sample servlet-->
</web-app>


Notice the value. It says when ever SampleServlet is called from browser , invoke the servlet whose name is SampleServlet whcih inturn loads the servlet whose class is mapped to this servlet, throuh

Assuming apache runs on localhost, and that you have deployed your servlet(by the way the web.xml is called Deployment Descriptor) you should type the following URL on browser

http://localhost/TestServlet/SampleServlet



You should get
Bhargav 's blog rocks!!


In case you dont get the output and get a 404 Error(resource not found) please verify if you have created the directory as i mentioned and most importantly the web.xml is correct or not. I once got stuck up with this problem and no where on the internet you can find solution for the problem!(not now cos i posted it on my blog! isnt my blog informative?) The problem was that i did not specify the schema to follow in the element inside web.xml, that is even the following portion is very important.



<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">



I hope this brief tutorial gives a kick start for those interested in learning servlets. Actually there is more of servlets than what i just covered(what i told is simply about Deployment in Tomcat, nothing else)? Just google out and if you have any questions , feel free to contact me at krishnabhargav@yahoo.com. I am not bad at J2EE, though not as good as .NET. Anyway i can help you out.

Next on this servlets issue, i would post a tutorial on Forms based authentication using Servlets and Apache Tomcat container. Again there is no proper step-by-step tutorial for this online, so meanwhile please go through some sample servlets code. All the best. And please hate servlets :)) cos compared to servlets Asp.NEt is veryyyyy easy to work with.


Krish.

Wednesday, March 15, 2006

Long ago ..... System.Web.Mail

Hi all,
Its been quite a while since i posted on my blog. I was terribly busy(emotionally disturbed, so took a two week break and i did nothing but "eat,sleep,watch movie,freak with friends"). Anyway the following is the steps you need to do, to send email from .NET application using System.Web.Mail.
1. Add reference to System.Web.dll if it its not already added(for asp.net applications, its already added, so you can skip this)
2. Import the namespace System.Web.Mail
3. Customize the following code
'a) Prepare your message
Dim msg as new MailMessage
msg.To = "to@email.com"
msg.From = "from@email.com"
msg.Subject = "Your subject goes here"
msg.Body = "Body of email"
'b) Send your message
SmtpMail.SmtpServer="smtpserveraddress"
SmtpMail.Send(msg) 'sending the mail.

As you notice, its pretty simple to work with!! But it isnt as simple as it appears. Just for information, Web.Mail uses CDOSYS internally to communicate with SMTP server and this is considered bad(i dont have enough experience to tell why, but its bad from what i read) .
Also another question is "What if my SMTP Server needs authentication?" Well this question has haunted me for two years and have now found out the answer. Just check out this cool support topic from MSDN.
http://support.microsoft.com/default.aspx?scid=kb;en-us;555287

Well there are sooo many issues with System.Web.Mail that there is a dedicated site for the namespace !!! check out www.systemwebmail.com !!! Cool

Also for your information, for .NET 2.0 use System.Net.Mail namespace - which actually makes sense. That is all for now and i have another problem to figure out. I noticed that Query Strings end when they encounter "#" I mean if actual string is Pa=1&Pg=2&Name=C#&Value=CS,when you read that string inside the asp.net applicaiton using "Request.QueryString", all you can see is that its only Pa=1&Pg=2&Name=C and #&Value=CS is skipped!!! Any solution for this?? Comment on my blog.