StructureCMS

April 30, 2010

Dump the trains for a new cycling utopia!

Filed under: Cycling, Musings — joel.cass @ 4:45 pm

Obviously it’s been a while since I last caught a train… They are so slow! It’s been well over 20 minutes and we’ve moved around 7km – that gives an average speed of about 21km/h.

21km/h? That’s a relaxed pace on a bicycle. Even on a bad day my average speed will not go below 25km/h. Which gets me thinking: why don’t we rip out the railway tracks and just convert the entire network into a big cycleway?!

It would be awesome, truly. The gradients are tame, the routes are straight, and the paths would be away from dangerous motor vehicles and pedestrians. It would be a cycling utopia.

If only it were possible. Oh well. Still, it’s a great thought. Ms Keneally, are you listening? You’d be able to ride your bike EVERYWHERE! And you might not even need to bring a bodyguard along, either.

Think of all the money you’d save – no more bulky rail bureaucracies, no more expensive repair bills for faulty infrastructure… Seriously, give it a thought!

April 23, 2010

gotoandlearn.com – Building iPhone Applications with Flash

Filed under: Uncategorized — joel.cass @ 9:16 am

Visited a great site that I had looked at a while back for some flash tutorials and found some great new content:

gotoandlearn.com – Building iPhone Applications with Flash.

This is very interesting indeed – I was having trouble getting started with building iPhone apps in xCode. If building applications for the iPhone becomes possible using Adobe CS5, it means no longer do I have to learn some backwards language that hasn’t changed much since the mid 80’s. Instead I can use ActionScript! Woohoo!

Just going through the tutorial though, I came across this little bit of programming excellence:

ball.x += ((ball.x + tx) - ball.x) * 0.3

Isn’t ball.x += ((ball.x + tx) - ball.x) * 0.3 exactly the same as ball.x += tx * 0.3? And ball.y += ((ball.y - ty) - ball.y) * 0.3 exactly the same as ball.y -= ty * 0.3? I’m not sure whether it’s the nerves involved in presenting something like this getting the better of the author, or whether it’s an indication of the source of the many gremlins that float around in the flash libraries.

Some bad news: Looking through some related pages on this new functionality (thanks google) shows that Apple is not going to allow applications to be written in any other language than Objective.C. This is an excerpt from one disgruntled developer in particular:

http://theflashblog.com/?p=1888

Now let me put aside my role as an official representative of Adobe for a moment as Speaking purely for myself, I would look to make it clear what is going through my mind at the moment. Go screw yourself Apple.

I would have to say, yep, I agree. While I am sure that Apple have their reasons (e.g. stopping developers from writing malicious code using a third party language is an obvious one), it’s still not fair that innovations like this from Adobe get stomped out. And I never thought I would be mentioning Adobe and innovation in the same sentence, ever.

Perhaps a compromise could be found where the pre-compiled XCode package is delivered by the flash compiler when the project is built for the iPhone. If all the code is in the package for Apple’s perusal (no matter how clunky the flash classes might be), then it might put out some fires between the two parties.

April 22, 2010

You are invisible!

Filed under: Musings — joel.cass @ 10:03 am

Now that I am using iGoogle, every time I log on I see the default iGoogle page. On the left-hand side is a chat box, and this always grabs my attention:

You are invisible - iGoogle

Who are google to tell me whether I am visible or not? How do they know? Do they have a hidden camera just behind my screen? I can see myself and I am pretty sure I am visible to others as well. Furthermore, when I click the link to “go visible”, I don’t feel any more visible than I was before.

April 20, 2010

Google Maps – Create your own store locator

Filed under: AJAX, Web Development — joel.cass @ 12:43 pm

Recently I have had to create a store locator for a website I have been working on. On the outset, it sounds easy. Simply add a number of points to the map and calculate the distance between a point of reference and the points you have added.

Then the question comes up: How do you calculate distance? As the crow flies, or by road directions?

To test this out, I created a Google Maps Distance Calculator.

Road directions work, and are not too difficult to get from the API. However, they are dead slow and require callbacks. Sometimes a request may take up to 30 seconds, which means that it could take ages to render the distance between 10 or so points. Furthermore, sometimes the distance cannot be calculated at all.

So the more efficent and reliable way is to draw a line and measure it. That’s much easier and does not require a callback method:

var polyline = new GPolyline([
		point1.getLatLng(), // starting point
		point2.getLatLng() // finishing point
	],
	"#0000FF", // color
	1 // opacity
);
numDistance = polyline.getLength(); // in metres

I could go on about the intricacies of storing and sorting an array of points, but I won’t. Instead I have created a script that can do this for you. First off, you will need to get a google maps key. This is easy, you can do it here. Then, you need to call the google maps V2 API as follows:

<head>
...
<script type="text/javascript" src="http://www.google.com/jsapi?key=__________________KEY_________________"></script>
<script type="text/javascript">
	// initialise google maps
	google.load("maps", "2");
</script>
</head>
....

You will need to add some divs for containing the map and listing areas. By default, the map element is assumed to be a <div> tag and the listing container is a <table> tag.

<body>
...
	<div id="map"></div>
	<table id="table"></table>
...
</body>

(We will get into how you can change the listing container later)

Then, you will need to include the pointSorter.js script as follows:

<head>
...
</script>
<script type="text/javascript" src="pointSorter.js"></script>
<script type="text/javascript">
	// set target divs
	pointSorter.setDiv("map");
	pointSorter.setListingContainer("table");

	// load maps, point sorter etc
	google.setOnLoadCallback(function () {
		// initialise point sorter
		pointSorter.init();

		// add points
		...
	});
</script>
...
</head>

You may have noticed that I have not entered anything below “// add points” in the block above. There are two ways to add points:

// add point by coordinate
pointSorter.addPoint(
	new GLatLng(37.423156,-122.084917),
	"Google Inc.","<strong>Google Inc. Head Office</strong>"
);

// add point by address
pointSorter.addPointByAddress(
	"701 First Avenue, Sunnyvale, California",
	"<strong>Yahoo! Head Office</strong>"
);

Both methods take similar arguments. The first takes a GLatLng (point) object + a description, whilst the second takes an address and a description. The first method is much faster than the second as no request has to be made to the server to look up an address.

By now (after some style tweaking), your code may be looking something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
	<title>Maps Test</title>
	<style type="text/css">
		body { font-family:sans-serif; font-size:0.8em; }
		/* ID Selectors */
		#map {
			width:70%;
			height:500px;
			float:left;
		}
		#table {
			margin-top:1em;
			width:30%;
			height:500px;
			overflow-y:auto;
			float:right;
		}
		/* classes */
		.info { color:#008000; }
	</style>
	<script type="text/javascript" src="http://www.google.com/jsapi?key=_____________KEY____________"></script>
	<script type="text/javascript" src="pointSorter.js"></script>
	<script type="text/javascript">
	// initialise google maps
	google.load("maps", "2");

	// set target divs
	pointSorter.setDiv("map");
	pointSorter.setListingContainer("table");

	// load maps, point sorter etc
	google.setOnLoadCallback(function () {
		// initialise point sorter
		pointSorter.init();

		// add point by coordinate
		pointSorter.addPoint(
			new GLatLng(37.423156,-122.084917),
			"Google Inc.","<strong>Google Inc. Head Office</strong>"
		);

		// add point by address
		pointSorter.addPointByAddress(
			"701 First Avenue, Sunnyvale, California",
			"<strong>Yahoo! Head Office</strong>"
		);

	});
	</script>
</head>

<body>

<div id="map"></div>
<table id="table"></table>

</body>
</html>

If you run this in your browser, you should see a map appear with two locations shown. Clicking on either will reveal the name of the location.

Now the only thing left to do is allow users to enter in an address. This is as simple as adding the method and form below. When the form is “submitted”, a search is made for the address.

<script type="text/javascript">
	...
	function setLocation (location) {
		// set point of reference
		pointSorter.setPointOfReference(
			location,
			"<strong>Reference Location</strong><p>"+location+"</p>"
		);
	}
	</script>
</head>

<body>

<form action="" onsubmit="setLocation(this.address.value);return false;">
	<input type="text" name="address" />
	<input type="submit" value="Set Reference Location" />
</form>
...
</html>

When the form is submitted, a new point is added to the map and the distances are shown.

Here are some other tips about the script.

You can set icons for the map pointers by using the following methods:

// set icon for reference location
pointSorter.setHomeIcon("http://www.google.com/mapfiles/dd-start.png", 20, 34);
// set icon for surrounding point locations
pointSorter.setPointerIcon("http://www.google.com/mapfiles/dd-end.png", 20, 34);

If you have a lot of locations, you can limit the display to only list locations within a certain distance from the reference point, e.g. 100km:

// distance in kilometres
pointSorter.setDistanceThreshold(100)

if you are not going to use a table, you need to set the item template for listing items. The example below allows your items to be listed inside an unordered list (<ul>) tag:

pointSorter.setItemTemplate(
	"
  • " + " {description} ({distance_direct}km)" + "
  • " );

    April 14, 2010

    Hey hey it’s Wednesday!

    Filed under: Musings — joel.cass @ 7:52 pm

    If there’s one thing that Channel 9 has made a habit if, it’s flogging a dead horse. It’s bad enough that they are disillusioned into thinking that two and a half men is actually a good show. Truthfully (and many will agree), it isn’t a good show. It’s ratings are only good because the 7PM show is dead boring and no-one watches home and away.

    So they’re trying to revive ‘Hey hey its Saturday’ – on a Wednesday. Shouldn’t it be called ‘Hey hey its Wednesday’? Daryl Somers jokes are not any better, and the puppets and co-stars are the same – the same – since the 80’s we have seen a computer revolution, fuel injected cars, quantum physics becoming more than just a bunch of crackpot theories. But they are still stuck in the 80’s. Even Daryl’s haircut is a bit too boofy for this day and age.

    It makes me wonder what else Channel 9 are going to bring back – The Paul Hogan show? Back episodes of 90 minutes? It’s worse enough that we’re still watching multi-decade old footage on funniest home videos.

    April 12, 2010

    Sunny days in Olympic park

    Filed under: Cycling — joel.cass @ 4:21 pm

    This was too nice to keep to myself. This photo I took last Friday (8th April) at lunchtime. The weather was fantastic.

    I would strongly recommend people get out there whilst the weather is so good.

    April 10, 2010

    Cyclists shouldn’t have to ride on Motorways…

    Filed under: Cycling — joel.cass @ 11:55 pm

    Seeing stuff like this makes me never want to ride on a motorway, and with good reason.

    Cyclists mowed down by truck.

    It’s becoming an old story. Another truck hits something because of fatigue. It seems almost inevitable that most bad road accidents are caused by tired truck drivers. But what really is the problem here?

    First of all, infrastructure. If we had proper cycleways following all our motorways and freeways, just as they do in many other states, the cyclists would never have to use the emergency lanes in the first place.

    Second, cruise control. I believe these accidents happen because drivers can chuck the engine into “auto-pilot” and get used to thinking that there’s little else they have to do after that. It means drivers do not drive to conditions, and if they do become tired and lose consciousness, the vehicle will not keep travelling at top speed.

    Third, combating fatigue management with something other than paperwork. Making equipment such as fatigue detecting devices compulsory, and also implementing compulsory alcohol and alertness tests on interstate routes (e.g. at weighbridges), could make a huge difference.

    Lowering speed limits and perhaps outlawing the use of cruise control for trucks within 100km radius of CBD’s, along with better fatigue management practices might improve the track record for trucks on our roads, but by far setting up real cycleways following (but not part of) our motorways would guarantee that horrible incidents like this never have to happen again.

    My deepest thoughts and condolences go out to Mr. Williams and best hopes for the 3 other cyclists in recovery.

    April 4, 2010

    Sydney Royal Mystery Show.

    Filed under: Musings — joel.cass @ 3:12 pm

    After a few visits to the Sydney Royal Easter Show, I’ve come to expect exorbitant admission prices, carnival folk peddling their scammy games and ricketty rides. All that aside, the exhibitions and entertainment made the whole experience quite worthwhile.

    We were a bit hungry when we arrived, and one of the first eateries that you see after the entrance is a place called ‘common ground cafe’. It seemed like a good idea, the prices weren’t too bad and the food looked appetising. The place was not just run out of a caravan like all the other places, but in an actual wooden building that looked like it had been sitting in the middle of the park for all time. They had a real colonialist thing going, conservative clothes, men wearing hats, looked like something out of the Amish country.

    Whilst waiting for our order, I noticed something a bit funny – all the guys had beards and the girls hadn’t had rather longer than normal hair. Eh, didn’t think much of it for a while and then it just got stuck in my mind – either these people like to take the whole ‘themed eatery’ thing to the extreme, or there was something deeper. Like a cult perhaps, or some sort of travelling restaurant where the men have no time to shave and the women can’t find a good hairdresser.

    Well, some research came across this blog post, which mentions articles from a couple of years ago. In particular, the restaurants belong to the ‘Community Apostolic Order’, or otherwise known as the ‘Twelve Tribes’, a cultish sounding sort of organisation (believe it or not) started a ‘carnival barker’ in 1971. Hmm, sounds like they didn’t quite make it out of the carnival business.

    Furthermore, according to this article, staff do not get paid to work, but much rather work out of their love for the organisation. So, forget outsourcing, forget foreign subcontractors, if you really want cheap labour, start a church and get your followers to work for you. Classic.

    The whole show in general is shrouded in this sort of mystery. If all the workers are volunteers, where does that 33 dollar entry fee go? I bet there’s even a darker truth behind that one.