<$BlogRSDURL$>

Sunday, February 20, 2005

Web: My trials with Amazon Web Services 

I have been playing with Amazon Web Services for the last 1 week. It is a very very powerful application available with vast amount of data which you can use for variety of purposes. I am using it for data-mining and find relationship between products. It is an experiment and for the fun sake only.

Now for the problem. Since, I am running random queries with page numbers I get error in certain resultsets. I am using C# and .Net for the development and have added the AWS using Add Web Reference method with .Net handling Serialization and related issues. In some of the result sets, there is a formatting error with certain results being not recognized as boolean. Now, Amazon database is very dynamic. Even if I send the same query with same page number I will probably not get the same error. I tried tracing the requests using Ethereal, which is a fine fine tool, and was able to get the exact packets causing the problem. But each Amazon response is in multiple HTTP packets and I was not able to combine them together to make a proper SOAP/XML file and analyze.

Next I installed SoapScope and tried to play around with it. Another fine piece of software, but was using upto 200 Meg of memory on my machine. Since I have 1 GB of RAM (I am running the machine without virtual memory :)) my machine was able to handle it. It uses a web front-end with some nice work and worked very well on my Firefox, which was a nice surprise. It raises the status of company behind it, MindReef, in my mind. Most of the companies will just make IE friendly and not care. But it is a bit complex piece of software and I was looking for just something simple to see the packets.

Then I fell back upon the only expert I knew, Softwaremaker. He pointed me to PocketSoap, which I could not try and a tool he has developed to send manually crafted SOAP messages, available here. I tried and it worked like charm. Simple and to the point. Though it can do with some UI enhancements. Typical programmer developed tool, you can say. But as I said before, the Amazon data is dynamic I could not get back any results with faulty response.

In the end, did something which should have done the first time. I found the message board on Amazon and found already reported by someone that IsAutopraphed field is sending back 'N' which is probably not getting recognized as boolean. Ah, will have to wait for them to solve this. But it was a very good time. playing with a few tools and learning a little bit more about SOAP, Sniffing tools and WSDL.

Tuesday, December 14, 2004

XML: XSLT and the fun of torturing yourself 

Current flavor of the month ( actually for a few months) is XSLT. And interstingly today only I read a good comment, I do not know where, that "people love XSLT, because they love to torture themselves". Do not know for others, but I think most XSLT developers will understand the reason without it. It is pretty easy to get burnt doing XSLT. It seems so beautiful, but actually your files can end up looking pretty bad.

I have learnt quite a bit of it in the last few days. One problem stumped me for some time. A beginner's issue maybe. I have found a solution, not sure the perfect one.

Suppose you have an XML file you are applying XSLT to and you want to combine attributes from 2 different elements at same level. Something like
<collections>
<article author="asdf">
<author name="asdf" dob="12/2/1972">
</author></article></collections>

and you want end-result at
<author name="asdf" dob="12/2/1972"></author>

The thing is once you get into article using for-each you cannot get to the author nodes(or can you?). So what I have done is make a call-template with parameters being the article and author node collections. This way you can treat both of them at the same level and both of them will be available to you with in the template. Something like
<xsl:call-template name="A">
<xsl:with-param name="articles" select="article">
<xsl:with-param name="authors" select="author">
</xsl:with-param></xsl:with-param></xsl:call-template>

If someone knows I am doing something stupid post back here please!

Monday, May 10, 2004

Javascirpt : Lull in Progamming, Busy with Word 

There has been quite a down-time with programming nowdays, which can change today. Plus might be leading a team also in next project. Yipee! High hopes. ;) Most of the recent time has been spent writing documentation and debugging codes of other people with minor errors, but javascript always seesm to surprise me in the amount of pre-built functions available. Well, may be because I have never used it too heavily. I always find server-side work more pretty (and easy) because of richness of data-types. Still managed to learn a few new things because sometimes have to do things in js because of client demands or performace (client vs server side).

I found a way to limit or extend the floating point variables to particular number of numerals after the point, which was new to me. No more substrings and keeping track of positions.
Var1= Var1.toFixed(2);
Particularly useful if say you are comparing string to a number, which can happen more often than not, if you are doing javascript checking. Just think, if you are comparing 25.00 in string to 25.0 which if float and things would not match up. Then things like this help.

Another thing is javascript functions fail totally without any warning leaving you in middle of a guessing game. Sometimes, had a tough time figuring the errors, but largely things were alright because the programs were not too buggy.

Monday, April 19, 2004

Javascript: When 44.30 + 22.18 does not equal 66.48... 

Well, there is always something new to learn. Some wasted time with doing Javascript has taught me a lot. Before starting check out here for a very good Javascript FAQ. Anything you think is wrong with language check there ( comp.lang.javascript FAQ ).

Now to my problem. I was joustling with issue where the two figures were not adding to what they should. Somewhat like that Title of the post. It was adding up to 66.479999999. I was like totally perplexed with alternately cursing Microsoft (was checking my code in Internet Explorer :) ) for buggy javascript implementation and scrouging the web with google.

Cutting it short the reason lies with the way the Javascript numbers are represented. It is something called IEEE-754 Doubles, which has a resolution(accuracy) of 53 bits, giving an accuracy of 15-16 decimal digits; integers up to about 9e15 are precise, but few decimal fractions are. Given this, arithmetic is as exact as possible, but no more. Operations on integers are exact if the true result and all intermediates are integers within that range.

In particular, non-integer results should not normally be compared for equality; and non-integer computed results generally need rounding. (From the site mentioned above.)

Tuesday, April 06, 2004

Windows: A few Gotchas! 

Trial and Error Stuff

1. Have you ever used any of the IndexFromPoint function in ListBoxes, TreeViews and such? Does not seem to give the right answer always. Anyway the reason is the way to get the right index because of difference between screen and client coordinates is something like

Point pt = listEx2.PointToClient(new Point(e.X, e.Y));
int i=listEx2.IndexFromPoint(pt.X , pt.Y);

You can of course combine this in one line. Just for clarity.

2. Have you ever used COM Interop and gotten the error "Referenced assembly 'Interop.xxxxxx' does not have a strong name". The easiest way to overcome is to follow these steps.
1. Open the properties of the Project
2. In Common Properties, go to General
3. In the Wrapper Assembly Key File field, add the key file.

In order to know what is key and how to generate a key file see the previous posts.

Thursday, April 01, 2004

Internet Explorer: Cancelling the Refresh 

I think quite a lot of developers would have come across the problem of somehow cancelling the refresh action of the user. Normally on a posted page, a box with re-posting message shows up which allows you to , well, re-post or cancel. From my searching till now, there is no way you can stop the refresh. If you think you do not have the ID10t user problem, below is the suggestion that I found at various places. User onBeforeUnload event in the page.

<BODY onBeforeUnload="event.returnValue = 'Press Cancel to not Refresh.';">
But the problem is this event is called in the following circumstances.

1 Close the current browser window.
2 Click the Back, Forward, Refresh, or Home button.
3 Click on an anchor that refers the browser to another Web page.
4 Invoke the anchor click method.
5 Invoke the document write method.
6 Invoke the document open method.
7 Invoke the document close method.
8 Invoke the window close method.
9 Invoke the window open method, providing the possible value _self for the window name.
10 Invoke the window navigate or NavigateAndFind method.
11 Invoke the location replace method.
12 Invoke the location reload method.
13 Specify a new value for the location href property.
14 Navigate to another location by entering a new address or selecting a Favorite.

Of course one can do solution on the server to handle reposting by session variable and cookies manipulation depending on the situation. But seems like no simple solution.

.Net: Playing with the GAC ....continued 

In order to faciliate my work I had to create a Custom Windows Control and since I was trying to use it in project which had a strong name, this particulat control also needed to be strong named. So, following are the steps to do strong-naming the assembly.

1. First thing one needs to do to create a strong name assembly is to generate strong name keys for the assembly. Microsoft Visual Studio ( not .Net Framework) ships with a Strong naming tool (sn.exe) which you can find at %Program Files&\Microsoft Visual Studio .NET 2003\SDK\v1.1\Bin. Usage of the tool is like

sn.exe -k .snk

snk=strong name key
Copy this file to the folder in the assembly which you need to strong name.

2. In the AssemblyInfo.cs file of the assembly you are trying to strong-name you will need to add the location of the keys like this
[assembly: AssemblyKeyFile(@"..\..\..\.snk")]

if the snk file lies in the folder above the source code folder and assembly file(dll) in the bin/debug.

3. In order to add the assembly to the GAC, use gacutil \i

Also read the previous post for pitfalls.

That is it, your asembly is strong-named and in the GAC!!

Wednesday, March 31, 2004

.Net: Playing with the GAC 

Finally the time came when had to use the GAC. I was playing around with adding an Explorer Bar while working in .Net. I started with searching in Google and found very excellent work done by Pavel Zolnikov at CodeProject.

This is what I learnt from that article and otherwise while working on this till now.
1. Since this project involves adding/removing things in Explorer, it will not use a new GAC file until restarted. This means lots of explorer closing and starting when working/testing/debugging. He says setting 'Launch folder windows in separate process' setting in Folder Options helps but I have not been able to verify that.
2. Left automatically Visual Studio increments the version number of assembly. Everybody who has opened the AssemblyInfo files would have seen [assembly: AssemblyVersion("1.0.*")], in that file. If left like that, one can have multiple versions of same assembly in the GAC. And happy debugging then!!
3. GAC folder in Windows is a different kind of beast all together. I hate explorer treating certaing things *special*. In case you are wondering it is located at %Windows%\Assembly. Try looking at that folder in the explorer window in Details view and try to add another Column in the details. I could not find a way to do that and let me know if you can! Also look at the same window in Command window and you will be able to see all the folders and files and everything *properly*.
4. .Net Provide gacutil.exe tool for handling additiong removal of files from GAC(of course!). It is located in %Windows%\Microsoft.NET\Framework\v1.1.4322. You can use it from anywhere by adding it to your PATH environment variable. Makes it easier to use.

Well that is it till now regarding this. Wait for a follow-up.

This page is powered by Blogger. Isn't yours?