Medieval Sniper

I had an awesome dream last night, really vivid, see what you think:

It's a medieval time, there's a big castle, a king, knights; the whole nine yards. I work a job in or around the castle, nothing too high profile, nothing to do with the court or the knights & standing army.

There's a strange mix of technology in this world, there are guns and bombs as well as all the comforts of modern living.

I, for some reason, am some sort of anti-hero. On my travels and throughout my work I gain experience and new abilities. Recently I've gained a skill where I can double jump (a frog-skill as it appeared to me in my dream), yet I've not had much of a chance to try it out. I can run, leap, then when in mid-air jump again and get even higher and further.

Get link to currently playing Spotify track via AppleScript

I was looking around for a means to grab the URL of the currently playing track in Spotify earlier, but couldn't find anything.

I rattled together an AppleScript to do just that and copy the result, including the track and artist name, to your clipboard.

tell application 'Spotify'
	set theTrack to name of the current track
	set theArtist to artist of the current track
	set theAlbum to album of the current track
	set track_id to id of current track
end tell

set AppleScript's text item delimiters to ':'
set track_id to third text item of track_id
set AppleScript's text item delimiters to {''}
set realurl to ('http://open.spotify.com/track/' & track_id)

set theString to theTrack & ' - ' & theArtist & ': ' & realurl
set the clipboard to theString

"Feel Like Makin' Love - Bad Company: http://open.spotify.com/track/3HKthdb7Ejnydb74BvmQW0"

I used a few bits of this Conceited Software forum post for pointers on accessing Spotify details via AppleScript.

Enjoy,
- Chris

Clay pots & kettles

I had a strange dream recently, unlike the strange dreams I usually have - nobody was a monster and there was no killing involved.

Every person in the world is given a clay pot, in my dream there was no notion of where they come from, just that everyone always has one. Inside this pot is a clay teapot. All of them, pots and teapots, are made of terracotta; some are ornate, some decorated, others are just plain clay; regardless of how they look, they all serve the same purpose.

Pretty UK Vehicle registration years

If you've ever wanted to convert a date of a UK vehicle into a nice looking representation of the year code then you've came to the right place!

I've written a small PHP function to convert a given date to one of the following formats:

Filtered keystrokes with JavaScript

This small set of scripts should give you a starting point for filtering the valid input to certain form fields to ensure that you shouldn't end up with input that you don't want*.

Basically you'd have the following javascript functions defined:

function isNumber( evt ) {
	valid		= true;
	if( evt.which || ( evt.which != 0 && evt.charCode != 0 ) ) {
		var charCode	= ( evt.which ) ? evt.which : event.keyCode;
		if( charCode > 31 && ( charCode < 48 || charCode > 57 ) ) {
			valid	= false;
		}
	}
	return valid;
}

function isValidEmailCharacter( evt ) {
	valid	= true;
	if( evt.which == null || ( evt.which != 0 && evt.charCode != 0 ) ) {
		var charCode	= ( evt.which ) ? evt.which : event.keyCode;
		var char		= String.fromCharCode( charCode );
		var re			= new RegExp( /([0-9A-Za-z-_@.])/ );
		valid			= re.test( char );
	}
	return valid;
}

function isValidPhoneCharacter( evt ) {
	valid	= true;
	if( evt.which == null || ( evt.which != 0 && evt.charCode != 0 ) ) {
		var charCode	= ( evt.which ) ? evt.which : event.keyCode;
		var char		= String.fromCharCode( charCode );
		var re			= new RegExp( /([0-9+\s\[\]])/ );
		valid			= re.test( char );
	}
	return valid;
}