Rescuscitating AMM with Amazon Web Service signed requests

Wednesday, August 26th, 2009

A few days ago Amazon added a requirement to their AWS that all requests to the service be signed, lest they be rejected. I’ve been using Sozu’s excellent Amazon Media Manager plugin for a while now to manage the currently reading list on this blog. It’s been a great way to keep track of exactly what I have read (avoiding the need to, like, remember), as well as masking my illiteracy by pasting a giant list of what is commonly known as airport trash.

Unfortunately, this is one plugin that hasn’t been updated in quite a while (after all, if ain’t broke…), so it broke. Being the sort of developer that’s quite happy to pick up a block of php and hack it until it works, I stumbled across this blog entitled ‘Amazon® AWS HMAC signed request using PHP‘, which has a function to download.

So to fix AMM:

1. Download that file, and copy the contents into the bottom of amm_parser.php.

2. In the same file (amm_parser.php), replace your _setUrl function with this one:

function &_setUrl() {
	//Build URL from base URL and other required parameters
	switch ($this->_locale) {				
		case 'uk':
			$region = 'co.uk';
			break;
		case 'de':
			$region .= 'de';
			break;
		case 'jp':
			$region .= 'co.jp';
			break;
		case 'fr':
			$region .= 'fr';
			break;
		case 'ca':
			$region .= 'ca';
			break;
		case 'us':
		default:
			$region = 'com';
			break;
	}
	$public_key = "< < Your Access Key ID >>";
	$private_key = "< < Your Secret Access Key >>";
	$url = aws_signed_request($region, array(
			"Operation"=> "ItemSearch",
			"Keywords" => $this->_parameters[Keywords],
			"ResponseGroup"=>$this->_parameters[ResponseGroup],
			"SearchIndex" => $this->_parameters[SearchIndex],
			"AssociateTag" => urlencode($this->_associate_tag)),
			$public_key, $private_key);
	return $url;
}

3. Oddly enough, this new method requires a private secret key which Amazon recommends to not give to anyone. So I’m not going to post mine here, even though it’s required for the plugin to work. So before I ponder that particular nugget of madness, you’ll need to sign up for an AWS developer account, and find your own keys via the Access Identifiers page. These need to be added into the function above.

That should be enough to get you back up and running again, although selfishly I’ve only really tested it for my needs alone. So please let me know if it works, or fails miserably.

For all the legal bits, I’m not at all affiliated with Amazon or Sozu – so please use at your own risk :)

Travel map – countries visited

Sunday, March 22nd, 2009

I’ve been looking for a good countries visited map for quite some time. There’s something satisfying about painting the world red (or in this case, orange), and something humbling about seeing massive chunks of the planet untouched. So since we’re approaching April and I’m getting the inevitable itchy feet again, I’ve gone hunting.

Up until now, World66 had seemed my only option. But in the Age of Google, posting images for this sort of thing seems a bit of a letdown. Fortunately 29travels have just the thing with their Google Map version.

Pretty cool but it’s a shame there doesn’t seem to be an option to edit the map. But, a quick look at the iframe source, and you can see it’s pretty easy to hack in any new countries as you visit. Providing you know the right country codes of course.

http://www.29travels.com/getmap.php?j=ALATBACYCZDEESFRGBHRISITMKMTMENLPLSITRUSVAVN&c=cc41c9f2&w=575&h=300

That query string is a long list of 2-digit country codes. So, if you know the code for the country you want to add, just adding it to the string will provide all the highlighting you need. For example Australia = AU

http://www.29travels.com/getmap.php?j=ALATBACYCZDEESFRGBHRISITMKMTMENLPLSITRUSVAVNAU&c=cc41c9f2&w=575&h=300

Who wants to package this up into a Wordpress plugin for me? :)

Code highlighting, and the magic of LINQ

Sunday, February 22nd, 2009

I’ve had a small block of code in my drafts folder for quite some time now, just looking for an excuse to publish it.  I’ve been using LINQ a lot in the past 6 months, and it’s one of the recent additions to the language that’s made me think twice before using PHP or Perl for my own projects (despite the existence of PHPLinq).

HIM: LINQ’s like pringles
ME: only makes sense after drugs?
HIM: once you pop you can’t stop

But I didn’t really want to write a full post on LINQ.  It seemed dull.  It’d been done before.  It’s old news.

So I picked up the WP-SynHighlight extension for Wordpress.  Which gives some rather cool code-highlighting through GeSHi.

So here’s some highlighted stylised C# LINQ demonstrating how simple it is to combine LINQ to SQL with LINQ to XML data sources.

var answers = (from a in poll.Descendants("AnswerSet").Descendants("Answer")
join aCount in dbVotes
on a.Attribute("id").Value  equals aCount.AnswerId.ToString() into aJoined
from o in aJoined.DefaultIfEmpty()
select new {
id = a.Attribute("id").Value,
percentage = ((o == null ? 0 : o.VotesCount) / dbVotes.Sum(b => b.VotesCount.GetValueOrDefault())  * 100),
count = o == null ? 0 : o.VotesCount, text = a.Value
});

Now if only Microsoft would release LINQ to XSD out of preview.

Using SVN to manage your Wordpress install

Saturday, September 27th, 2008

I use SVN to manage both this blog and the Blakepics Gallery2 installation.  Using the version control software as a means of keeping my own sites’ shared components up to date is horribly convenient once you get through the initial attempts of “shit, I’ve broken it again”.

Wordpress have full instructions for setting up your blog with SVN.  I’d recommend sticking to the ‘Tracking Stable Version’ section and controlling your upgrades rather than checking out the trunk and risking an unstable install.  This basically comes down to a single command to be run within your wwwroot.

svn co http://svn.automattic.com/wordpress/tags/2.6.2 .

When a new version is released, you can switch to that with:

svn sw http://svn.automattic.com/wordpress/tags/2.6.3

What they don’t mention, is you can do exactly the same with your plugins using the repository here…

For example, find the plugin you want, and checkout to your plugin folder:

svn co http://plugins.svn.wordpress.org/share-this/tags/2.3/ share-this

As before, you can switch to new releases (make sure you’re in that plugin directory first) with:

svn sw http://plugins.svn.wordpress.org/share-this/tags/2.3/

And should you forget the URL you’ve got it from (like when you see there’s an upgrade available, running ’svn status’ in that directory should help you out.

Once you get the hang of it, it really saves so much more time than that slow download, unzip, copy process you’re probably all used to, and you stand a much better chance at maintaining your own modifications without rewriting them all the time :)

Twitter – Now the machines are syndicating us

Tuesday, August 12th, 2008

RSS recursion is not a toy

… that was syndication for the sake of it.

That’s what I said, word for word. Then a colleague pointed out that I could have twitter automatically update from my blog or Blakepics. And all hell broke loose.

I didn’t like Twitter as another way of updating my blog, or having it throw up all over my Facebook status every time I opened up my Twitter-enabled fridge. But reaching out to new audiences, and the potential to bombard mobile phone networks every time I bounce from one country to the next… Well suddenly it’s become quite cool.

And yes, I admit – I was tempted to install the application to syndicate my Xbox 360 status as well. But I’m not sure I’m ready to spam everyone that much. Yet.

“Kevin has just been killed by a bunny rabbit on Halo 3. Again”