Monday, July 03, 2006
Today I wrote some code that I've been wanting to play around with for a while. I know that Google Map API has been out for a while, infact its in its second version. So this afternoon I took sometime to check it out. My first impression was that it was going to be complicated. However I couldn't that couldn't of been further from the truth. If you know javascript, this is a cake walk.

The first thing I have to say is that Google did an excellent job on documentation and examples. Also when you sign up for your API key they give you an html example to start with that is amazingly helpful. Its the most basic google Maps functionality there is, but I found it to be a great starting point.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[

function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
}
}

//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>
This pretty much has everything you need to start. It shows you how to call the Google Maps API with your key. It shows you how to create a GMap2 object and what you div and body code should look like. Well I decided for my test I would mapout the locations of the Credit Union's Southern California branches. What I wanted was something simple and would give some branch information when you clicked on the pushpin icon. Of course like I mentioned earlier Google did a great job with the documentation and I started with the "Using Xml and Asynchronous HTTP with Maps examples". It basically shows how to use their GXml parser for javascript. Which seems to be really fast and easy.
GDownloadUrl("data.xml", function(data, responeCode){
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
Of course you need an xml document, which is simple enough, a documentElement of <markers> and the elements <marker> with attributes "lat", "lng", "branch", "address" and "phone". However my little problem was I didn't know how to figure out that latitude, after a quick google search I had what I needed.
<?xml version="1.0" ?>
<markers>
 <marker lat="34.191459" lng="-118.348875" branch="Burbank" address="2340 Hollywood Way<br >
 Burbank, CA 91510" phone="(800) 328-LFCU"/> </markers>
Well now I just needed a function to write out the data to the InfoWindowHtml, well with the little sample code I was about to write a function that took the data from the xml and fill the InfoWindowHtml.
function createMarker(point, address, branch, phone){
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function(){ 
marker.openInfoWindowHtml("
" + branch + "
" + address + "
" + phone); }); return marker; }
Now that I have my marker function I just need to bring it all together.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps - LFCU Southern California Locations/title>
<script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(34.191459, -118.348875), 9);
				
				
function createMarker(point, address, branch, phone){
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function(){ 
marker.openInfoWindowHtml("<div style='font-family:arial, verdana, helvetica, sans-serif;font-size:10pt;'>
<strong>" + branch + "</strong><br />" + address + "<br />" + phone);
});
return marker;	
}
				
GDownloadUrl("data.xml", function(data, responeCode){
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for(var i = 0; i < markers.length; i++){
var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
var address = markers[i].getAttribute("address");
var branch = markers[i].getAttribute("branch");
var phone = markers[i].getAttribute("phone");
map.addOverlay(createMarker(point, address, branch, phone));
}
});
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 700px; height: 500px"></div>
</body>
</html>
That's it, if you know javascript, can fake your way though xml, you can have a google map up and running in no time. :-) Happy Coding
7/3/2006 7:54:25 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
 Friday, June 30, 2006

Okay so let me set the scene, three british guys, at Norway, one mini cooper, some rocket engineers and a  ski jump. This is so something guys do.

6/30/2006 3:45:48 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
 Wednesday, June 21, 2006

Dad sent this over today. Now this is performance Driving!

6/21/2006 9:01:03 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
I mentioned WATIR a while back and I have been using it almost every day for the last month or so. The more I use it the more I like it. WATIR is built around Ruby as I mentioned earlier. So I've been looking into Ruby more and more. I have to say I really like it and am starting to use it for some repeative tasks. For example I have a WATIR test that logs into the applications, hits some links etc. It takes about 40 to 60 seconds to run. Well I decided that I really wanted to have a way to run it multiple times in a row. Well, I decided to write a quick Ruby script to take care of this for me. It took about two minutes to look up the system function, which works almost exactly as it does in PERL, another 5 minutes to code and debug and I was done

i = 0
done = ARGV[0]
testScript = ARGV[1]
 if(done == nil) or (testScript == nil)
 print "usage: ruby runmore.rb N ScriptName\n\r"
 print "N equals number of times test should run\n\r"
 print "ScriptName equals the ruby/watir script you want to run"
 else
    while i < done.to_i do
    system("ruby #{testScript}")
    i = i + 1
    end
 end

I'm really beginning to enjoy Ruby it's as readable as VB and as writable as PERL. Not bad for a interpeted language that doesn't use semicolons :-D Happy Coding

P.S. yes, I wrote a script to run another script...
6/21/2006 3:24:09 PM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
Where I work, we have to do load testing of just about everything. However we are a small shop and can't spend our budget on some of the bigger testing products out there. So we use Microsoft Application Test. It's included with VS.NET 2003 and has a recorder that works fairly well. There is one little problem, HTTPS. It doesn't record in that protocol, but it will test in it. What you have to do is to record your test on your local machine (localhost) once the test works you just make some changes to the script.

1. First, change the connection string from
Set oConnection = Test.CreateConnection("localhost", 80, false)
to:
Set oConnection = Test.CreateConnection("localhost", 443, true)

2. For each later request, change the following line in the script oRequest.HTTPVersion = "HTTP/1.0"
to:
oRequest.HTTPVersion = "HTTP/1.1"


That's it! If you would like to read more about it, here is the link to Microsoft's Knowledge Base Article about it: http://support.microsoft.com/?id=327873
6/21/2006 9:57:48 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
 Tuesday, June 13, 2006
I know I haven't posted alot lately. In part because I still haven't gotten my laptop back, not having it with me makes it hard to write blog post when the thought hits me. So I apologize for that.

Lately at work Testing has been a big part of what I've been working on. Of course as a programmer I never want to do the same thing twice, even when testing. So we use NUnit to test the code we write however the user interface has always been a difficult beast to try and test. There were a few things out there, but they basically were HTTP recorders. They recorded your actions at the HTTP level and not at the user/browser level.  So I kind of gave up on them and gave in to the fact that I would have to do all my user interface testing manually. I wasn't happy about it, but it was what it was.

Well about three weeks ago I was listening to a back epoisode of Hanselminutes and Scott Hanselman was talking about WATIR (Web Application Testing In Ruby). Well Scott isn't one to use tools that don't work, so I gave WATIR a try. It is brilliant. I can't say enough good things about this tool. WATIR basically is a Ruby wrapper around the IE DOM. So you are scripting out what is going on inside the browser. There is the minor issue of having to learn Ruby. Believe me it is a minor issue. The examples and documentation that come with WATIR will have you writing tests in no time. Honestly I think that my first test was written and working in under 10 minutes.

What is so nice about WATIR is it seems to use the same pholisiphy as Ruby. David Hienemeier Hansson, puts it really well in the 6/2006 issue of Linux Journal " Ruby is more than anything else, a language for writing beautiful code that makes programmers happy. After writing and running your first WATIR test you will be happy.


6/13/2006 10:04:53 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]
 Friday, June 02, 2006
I was reading digg.com this morning and came across an article on wired, "Choose Your Own Adventure Returns". Of course this peaked my interested as I loved the CYOA (Choose Your Own Adventure) series when I was a kid. I can remember walking down to the Rosemead Library on Del Mar, and checking two or three of them out. It was like checking out ten books because depending on your choices the book could turn out completely different.  I guess I wasn't the only one that loved this books as they sold 250,000,000 copies world wide.  Well apparently the books are being updated and will be released soon for new the generation to read and love. I can wait to buy a couple of them for the Little Boy to read. Going back to the article one, of the fun things they did to present the information was to make the article, a CYOA. Will not being techincally a difficult thing, I sure appreciated it for nostalgia sake.

6/2/2006 8:58:14 AM (Pacific Daylight Time, UTC-07:00)  #    Comments [0]