# Monday, November 17, 2014
Monday, November 17, 2014 1:05:00 PM (GMT Standard Time, UTC+00:00)
# Wednesday, October 1, 2014

Here is my interview with Todd Gardner of Track:js, describing his company and how they used BizSpark and Azure to grow.

Wednesday, October 1, 2014 7:24:06 PM (GMT Daylight Time, UTC+01:00)
# Monday, September 1, 2014
Monday, September 1, 2014 10:25:23 PM (GMT Daylight Time, UTC+01:00)
# Monday, December 30, 2013
Monday, December 30, 2013 5:31:02 PM (GMT Standard Time, UTC+00:00)
# Monday, December 16, 2013

Episode 296

Ward Bell on Breeze

Monday, December 16, 2013 10:58:00 PM (GMT Standard Time, UTC+00:00)
# Monday, November 11, 2013
Monday, November 11, 2013 11:05:00 PM (GMT Standard Time, UTC+00:00)
# Tuesday, September 3, 2013

Overview

The Google GeoCode API offers a service for retrieving driving directions between 2 addresses.

Syntax

The service is exposed through a URI. The syntax of the URI is

http://maps.googleapis.com/maps/api/directions/output?parameters

output is the format in which I want to receive result – either “json” or “xml”. I prefer the simplicity of json.

parameters is an ampersand-delimited list of name value pairs to pass to the API. The parameters I care about are

Origin

The starting address

destination

The ending address

alternatives

”true”, if you want the service to return more than one possible route. Unless I have a reason to provide multiple routes, I prefer “false”

Units

”imperial” to return data in feet and miles; “metric” to return data in meters and kilometers. This should depend on the country where the data is going to be used.

Sensor

”true”, if I am using a sensor to provide location; otherwise “true”. I don’t own such a sensor, so I set this to false.

Sample Code

Here is a sample URI to request directions from my old office to my new one, returned as JSON data.

http://maps.googleapis.com/maps/api/directions/json?origin=31555 W 14 Mile Road, Farmington Hills, MI, 48334&alternatives=false&units=imperial&destination=26957 Northwestern Highway, Southfield, MI, 48076&sensor=false

This is a nice function to call from JavaScript. I prefer the simple jQuery syntax for making Ajax calls like this.

var startAddress='439 East 31st Street #214, Chicago, IL 60616';

var endAddress='30 North LaSalle St, Chicago, IL 60616’;

var requestUrl = 'http://maps.googleapis.com/maps/api/directions/json?origin=' + startAddress + '&alternatives=false&units=imperial&destination=' + endAddress + '&sensor=false';

$.ajax({ 
url: requestUrl, 
dataType: "json", 
type: "GET", 
data: {}, 
error: function (err) { 
$(#distanceDiv).html("Error calling Web Svc.<br/>Calculate."); 
}, 
success: function (data) { 
var distance = data["routes"][0]["legs"][0]["distance"].text; 
$(# distanceDiv).text(distance); 
} 
});

The code above calls the service; then parses the resulting JSON to retrieve the distance and displays that distance in a DIV with the ID distantDiv. In this example, I hard-coded the 2 addresses, but you could use jQuery selectors to retrieve the address from elements on the page or user input.

Response

Below is part of the Json response to the service call

JSON Results

Limitations

There are some limitations you should be aware of. I am a cheapskate, so I’m using the free version of this API. With the free version, I can only send 2500 addresses per day. If I try to send more, the service will respond with a status of “REQUEST_DENIED” and no results will be returned.

Also, Google expects you to display the results on a Google Map. I’m not sure how they enforce this, but they don’t allow you to use the Geocoding API to display data on someone else’s map.

Tuesday, September 3, 2013 6:02:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, June 24, 2013
Monday, June 24, 2013 12:47:31 PM (GMT Daylight Time, UTC+01:00)
# Monday, June 3, 2013
Monday, June 3, 2013 7:10:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, September 24, 2012
Monday, September 24, 2012 2:03:36 PM (GMT Daylight Time, UTC+01:00)
# Sunday, August 19, 2012

JavaScript’s popularity proves how useful people have found the language. Novices use it to add simple validations to web forms, while advanced build amazing applications with JavaScript.

Yet, for all its utility, many look at JavaScript with disdain and fear, pointing to dangerous features and to the difficult of dealing with the browser's Document Object Model.

In JavaScript: The Good Parts, Douglas Crockford distinguishes between the good features of JavaScript that make it and elegant and powerful language; and the bad parts that make it dangerous and difficult to understand. Crockford’s message is to use the good parts and avoid the bad parts and stop fearing JavaScript.

According to Crockford, most people misunderstand JavaScript and so they misuse it; then, they complain about the language.

Crockford acknowledges that the designers of JavaScript made some mistakes (global variables, for example), but that there are enough good features of the language to make it appealing to a wide range of users writing a wide range of applications. He notes that JavaScript succeeded as a platform for creating client code for the web – something that that the more powerful Java language attempted and failed badly – and that this proves JavaScript’s power.

Applications will be better and developers happier, notes Crockford, if developers avoid the bad parts of the language. For example, always use the "===" operator, which returns what most users expect because it doesn't do any type coercion. Avoid the confusion of the "==" operator, Crockford recommends.

Crockford's style is concise and straightforward. At fewer than 200 pages, the book has no room for distractions. Regular Expressions are presented and described and examples are shown how to use them. Crockford clearly describes Closures, a feature that is likely new to many developers; and he spells out how callbacks are implemented in JavaScript.

Before reading this book, I was unaware of implied semicolons in JavaScript and whey they can be dangerous. Crockford spelled out the dangers and how to avoid them very clearly.

JavaScript can be a great language if you confine your programs to using the best parts of the language and steer clear of most of the dangerous features. This book will help distinguish the two.

Sunday, August 19, 2012 3:36:23 AM (GMT Daylight Time, UTC+01:00)
# Monday, July 30, 2012
Monday, July 30, 2012 4:57:00 PM (GMT Daylight Time, UTC+01:00)
# Monday, May 28, 2012
Monday, May 28, 2012 10:34:00 PM (GMT Daylight Time, UTC+01:00)
# Friday, May 4, 2012

At Codeslingers last night, someone pulled out some coding Katas. For those who don’t know, a Kata is a coding exercise that is designed to practice your programming skills, rather than to solve a particular business problem. I was handed the classic “FizzBuzz” problem. The assignment:

Create a function that will print the integers from 1 to 100 with the following exceptions:

  • If a number is divisible by 3, print the word “Fizz” in place of that number.
  • If a number is divisible by 5, print the word “Buzz” in place of that number.
  • If a number is divisible by both 3 and 5, print the word “FizzBuzz” in place of that number.

The output should look something like the following:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16

I started with a C# console application because that is the language with which I am most familiar. It was able to finish the following in under 2 minutes. It took me 5 minutes to write the unit tests.

class Program
{
    static void Main(string[] args)
    {
        for (int i = 1; i < 100; i++)
        {
            var p = FizzBuzz(i);
            Console.WriteLine(p);
        }
        Console.ReadLine();
    }

    protected static string FizzBuzz(int i)
    {
        if (i % 15 == 0)
            return "FizzBuzz";
        if (i % 3 == 0)
            return "Fizz";
        if (i % 5 == 0)
            return "Buzz";
        return i.ToString();
    }
}

I only occasionally code in JavaScript, so I tackled that language next. Someone recommended using http://jsfiddle.net/
as an online IDE for writing and sharing JavaScript, so I tried it and liked it. Of course, JavaScript is a dynamic language and one of my big challenges was spelling things correctly without all the help Visual Studio provides when writing in a statically-typed language. In my case, I misspelled the id of a div, which cost me at least 15 minutes. I created the following boilerplate HTML:

<html>
    <body>
        <div id="fizzbuzz"></div>
    </body>
</html>

Then, I used the following JavaScript (plus a bit of jQuery) to output the FizzBuzz results:

for (i = 1; i <= 100; i++) {
    $("#fizzbuzz").append(function() {
        var newLine = i;
        if (i % 3 === 0) {
            newLine = "Fizz";
        }
        if (i % 5 === 0) {
            newLine = "Buzz";
        }
        if (i % 15 === 0) {
            newLine = "FizzBuzz";
        }
        var newDiv = $("<div>").text(newLine);
        return newDiv;
    });
}

A simple program like this provides a fun way to practice an old language and to learn a new language. Next up, I’ll try this program with F# and Ruby, since I have very little experience with these languages.

Friday, May 4, 2012 12:40:00 AM (GMT Daylight Time, UTC+01:00)
# Monday, January 16, 2012
Monday, January 16, 2012 4:15:00 PM (GMT Standard Time, UTC+00:00)
# Monday, June 27, 2011
Monday, June 27, 2011 7:25:37 PM (GMT Daylight Time, UTC+01:00)