Home » Articles posted by Tai Kedzierski (Page 12)

An example of bad use of XML #rant

XML – the eXtended Markup Language – was designed with the express intent to be able to organize data into closely-associated structures, and to easily access this structured data.

Used in the right way and in the proper contexts (some purposes really only need INI), XML can be a very versatile and powerful tool both as a data structuring language and as a protocol carrier.

The Document Object Model (DOM) specification provides an API for manipulating XML documents loaded for parsing, and implementations for nearly every language have been implemented.

So you may yet understand why when I came across the following snippet, I was horrified…

<key>Track ID</key><integer>1548</integer>
<key>Artist</key><string>Chris Vrenna</string>
<key>Composer</key><string>Chris Vrenna</string>
<key>Album</key><string>American McGee’s Alice</string>
<!— skipped some ….. —>

I extracted the above from my iTunes Music Library.xml file when I was looking into parsing it for a duplicates-finding and removing script. As you can see, each piece of data relies on its positional relation relative to another piece, rather than their structural relation. XML was MADE for this structuring, to make parsing it easier. Using positional relations becomes not just bad practice, but stupidity. I’m sorry, but it does.

Examine what happens when the above becomes structured the way XML is supposed to be used (note, the following is just one way of doing it right):

<track id=”key1548”>
<tid type=”integer”>1548</tid>
<Name type=”string”>Track04</Name>
<Artist type=”string”>Chris Vrenna</Artist>
<Composer type=”string”>Chris Vrenna</Composer>
<Album type=”string”>American McGee’s Alice</Album>
<!— skipped some ….. —>

At least two advantages arise from using the correct form:

1) Now we can use the DOM Level 1 method getElementById on each track.

var track = ituneslib.getElementById(“1548”);

Accessing it previously would have required iterating through the nodes sequentially until reaching the ID, and then accessing the next node to get the actual track data. This is the required code to access the data in the badly structured version:

var track;
for(key in ituneslib.getElementsByTagName(“key”)) {
if(key.firstChild.nodeValue == “1548”) {
track = key.nextSibling;

DOM parsers come with the search methods built in. Might as well use them!

2) each child node is named so that it can be accessed directly. Changeable properties of the node are now a “type” attribute, the value is the direct child.

var name = track.getElementsByTagName(“Name”)[0].nodeValue;
var artist = track.getElementsByTagName(“Artist”)[0].nodeValue;

Accessing it previously would have meant iterating over each “key” node until one with a child value of the right content was found; then accessing the next node (of changeable name) before accessing the value we want.

var name;
var artist;
for(key in track.childNodes) {
if(key.firstChild.nodeValue == “Name”) {
name = key.nextSibling.nodeValue;
} else if(key.nextSibling.nodeValue == “Artist”) {
artist = key.nextSibling.nodeValue;

I can only fathom that the reasons iTunes uses this sloppy structure are that

  • the entire Library gets loaded anyway when iTunes starts up into an in-memory database, so that the appropriate sorting can happen during the use of the application. It’s a one-time parse during the life of the process.
  • Apple do not want anyone else parsing their data. So they make it really annoying.

I still can’t believe the structure, as it is, is even documented in a DTD…!

I’m not sure if it would even be possible to write an XSLT to turn the bad XML into good XML…!

“Social Media Explained”

A recent meme

“I’m sorry, but as you do not have a Twitter account, we can’t offer you this position.” This is what, my friend confided to me today, she was told at an interview for a job in media a few months back. At first I was surprised at such a requirement, but then again, if you want to be in media, I guess you do need to get your hands dirty every once in a while… But I was thinking, “what on earth would she have tweeted about?”

Not everyone needs to actively use all the mainstream services, but I must suppose it helps at least reserving your name on them – if only to keep your identity clean. There are some that will be used more than others, and recently, in ensuring the “cleanliness” of my online identity, I was confronted with logging in to many old accounts and checking what had been going on… Why did I have so many? Are they at all relevant to me now? What are they FOR? (and can I find kittens there??)

1) Identity

Examples: Facebook, LinkedIn, Google+

Reason to join: for any profile that has your name, other people will think it actually is you. Keep one aside that is indeed.

I believe most people know by now what each of these sites are. You can’t get away from them. If you don’t have an account, you’ve at least heard of them in the press.

These socnets are purposed to be your online “You”, the one that represents who you are, that connects you with those people you actually know, where your interests are laid bare and where, more often than not (and for G+ as a requirement) you use your Real Name.

I’d advise anyone looking to go into media to have an account on each of these. Even if you never use it. Just claim the space. Before someone else does.

Photos of Kittens: Not too many, unless they belong to your friends. A recent explosion of memes on Facebook is seeing them creeping in now though…

2) Sharing

Examples: Twitter, Pinterest

Reason to join: if you want to keep an eye on trends and “interestingness” in your area of interest, you could do worse than get the feed from the many who share those interests.

These are the “hey world, this is the interesting stuff!” sites. There are probably more of the same, but these are, it seems, the main players.

I’ll note that they are markedly different in purpose however, in that Pinterest is centred around sharing around full online content, whereas Twitter is aimed at sharing snippets and bites – which, with being accessible through SMS, is how it has been so popular in the mass-organization of protests, demonstrations… and parties.

Photos of Kittens: probably plenty on Pinterest, filed under “kittens”

3) Blog

WordPress, Tumblr, LiveJournal, Blogger, Blogspot, any website that has a “recent news [about us]” section…

Reason to join: if you enjoy writing, voicing opinions, and providing analysis, or simply entertaining, a good blog will let you build something to show for. If you’re just going to read – then just read 🙂

If you have not heard the term “blogging,” you’ve been living under a rock. The things are everywhere. You’re reading one right now.

The purpose, purportedly, of a formal blog is to provide news article-like postings for the general public to read – and sometimes even comment on. The BBC and CNN have blog sections; Apple, Adobe and Microsoft too; smaller companies around the world keep their latest news there… There are professional bloggers such as Cory Doctorow, an advocate of the Free (libre) Internet, Stephen Fry of television fame, Gary Marshall, a satirical technology writer…

… and then there the denizens. People who try to emulate the Great Bloggers by writing hopefully meaningful stuff. People who post pointed – and no so pointed – opinions online to be seen by few. People who post about events in their lives for friends and family. People who vent their spleen. People who just talk about their breakfast…

The blog is the vehicle of the in-depth analysis, the nattering mundanities, the lengthy diatribes. It is the preferred method of long texts.

Photos of Kittens: Probably on Tumblr, thanks to the “reblog” functionality. You may need to hunt a bit more on the others.

4) Pictures

Flickr, Instagram, deviantART, Picasa, Photobucket

Reason to join: if ever you want/need to share those holiday pics with friends and family, you’ll already have a space.

It seems like nearly everyone is taking photos now, and there needs to be a space to file them. For public and for private consumption. For the most part, the aim is not only to store photos, but to share them, to gain visibility.

Aside from the casual users who make up the bulk of Picasa, Flickr, Instagr.am and Photobucket, there some sites catering to more serious endeavours such as SmugMug.

And again, in all places, there are the denizens. You can find them in all places. But there are sites where the divide between the best contributors and the worst is eminently palpable. deviantART is one. But nearly anyone who wants their work seen by a wide audience has to foray into that murky place…

Always remember to enable Safe Mode on dA – or only look at the “popular” items if not. Both the crafts and the photography sections are littered with “artistic” nudes of… things.

Photos of Kittens: dA will try to claim having the cutest in the galaxy!

5) Multimedia

Examples: ReverbNation, Spotify, Last.fm, MySpace, YouTube, Vimeo

Reason to join: for content creators, to display content. For content consumers: to make playlists.

Some people create, most people consume. Under the multimedia banner there are two fairly distinct groups divided that way.

For original content creators, ReverbNation (music), MySpace (music) and Vimeo (video) are fertile grounds, and consumers looking for new obscure stuff to blow their minds should definitely go there.

Mainstream content consumers, on the other hand, are best served by Spotify (music), Last.fm (music) and YouTube (video). The latter is also a content creators’ platform – but I list it under consumers because, lets face it: nearly all the content there are mashups of other peoples’ content. Should a Vimeo video gain traction, it will probably find its way to YouTube. Think of it as “incubation” and “public release.”

Having an account on the first trio: good idea if you create original content. On the second trio? Not really necessary.

Videos of Kittens: not too many. Apart from Nyan Cat.

Animated Kitten Backgrounds: dammit, MySpace!

Sounds of Kittens: now there’s a thought for a new meme…

Which ones do I need?

For the regular person, I think the only thing needed is an email address with a good password. It’s a key to accessing any other site out there. It’s also your main vocal chord in the digital world when all else fails.

When travelling, it’s probably not a bad idea to have a Twitter with protected tweets (only people you approve can see what you post, get your nearest and dearst to keep an eye out for you), so that you can update it in the most circumstances possible and as necessary.

For people who enjoy writing, I cannot insist more: get a blog. Having something to point to can always come in handy should you need to showcase easily. Then, if you really are of the pen-and-paper persuasion… Know that Google will not find you.

Original Content Creators: I’d recommend Vimeo. There is a strong community, and I have mostly seen very good work on there. Know however that it’s a top notch crowd, so if you’re unsure, stick to YouTubing.

Companies: the first two are pretty much essential as these are the places people will virally share the most. You can cut costs by hosting videos on YouTube, you can share videos and blog posts/news articles through status updates and tweets (same thing, really) and use Tumblr re-blogging to spread marketing material. If the message is desireable, the people will share it.

Anything else… Ask yourself: how much time do you want to waste spend with the kittens?

This gallery contains 1 photos.

An example of a rule of thirds composition using nearly all the lines… This one was taken in Barbados, January 2012.

This gallery contains 1 photos.

This is me. Just so that I have a self portrait on this stream.

I do not own this music or video, all rights belong to [OTHER]

It always baffles me when people put these kinds of remarks on their videos. It makes me wonder if anyone even understands the idea of copyright? Early indications point at: no.

A good part of the YouTube “pirating” that is going on is kids (and probably grown-ups too) who simply just don’t know better… It’s a Hanlon’s Razor: Never attribute to malice that which can be adequately explained by stupidity

Either don’t say it, or don’t post it.

This gallery contains 1 photos.

Add matcha tea powder to your recipes to turn food green….

I took a train to London town

The following is based on a true story told to me by my flatmate. Here, re-told in verse and in her voice.

I took a train to London town one day in February
A journey I would not forget for this is what happened to me:

I sat at a tabled seat – you know, the ones where two face two
And as we pulled away, two drunks approached from out of the blue

The two men sat at my same berth, before me and beside
And every time one smiled at me, I died a little inside;

His teeth were rotten, breath was foul; his skin was rugged, limp and white
And every time he slurred his words I died a little inside

My neighbour spoke to me foul words, half in jest and half insult
But I remained polite for fear a fight may otherwise result

He hurled abuse accross the carriage at an Asian family
The turned to me and showed he bore a swastika under his sleeve

“I left the prison just today,” declared the drunken savage,
“And I’m going home to my bonnie lass to ask her hand in marriage”

His friend exclaimed, “excuse my pal, he’s normally not this bad;
We’re getting off at the next stop.” For this I was truly glad.

Then up they stood, up went their hoods, and they turned to another drunken pack
“Yer all a bunch o wankers, eh!” — Oh kettle! Oh pot! Oh black! Oh black!

And on the platform they did stand swaggering side to side
And thinking of their brides to be I died a little inside …

Avoid using the expression “stair me in the face.” You do not want a staircase in your face.

me, on the importance of spelling.

Turning scripts into independant commands on Windows


Dynamic language interpreters (“script engines”) in Windows don’t normally install in such a way that once you write a script, you can simply call it on the command line.

If you have a script named hello.py, you cannot just type “hello” at the command line and hope it will work. It won’t.

The file extension has to be registered as an executable file, and the default program for opening the script must be its appropriate interpreter.


  1. Create a directory at C:mybin
  2. right-click on the My Computer icon on your desktop or in the Windows Start menu (in Win7 it is just called “Computer” and select ‘Properties’)
  3. Click on the Advanced Settings button, and then on the Environment Variables button
  4. Edit the PATH variable in System Variables, add the following to the end of its data:

    (note: the semi-colon ‘;’ is important)

  5. save and return to the desktop.

We now assume that the scripts you want to run get saved to C:mybin

You will need to use the `assoc` and `ftype` commands to achieve this

1) Associate a file extension to a pattern name

assoc .jar=jarfile

2) Define the handling in the pattern:

ftype jarfile="C:jsdk-1.6.0_18binjava.exe" -jar "%1" %*

Surround the path to the executable with quote marks as best practice.

Surround the %1 argument with double quotes as well – this is the path to your runnable file; if it has spaces in its path, you need the double quotes to keep it whole.

Do not surround %* with quotes, this represents all the arguments that were initially specified on the command line.

This gallery contains 1 photos.

How things have changed… I really do wonder what Photoshop 1 was like, and if its features would still allow powerful image creation still by today’s standards – not considering ease of use which I suspect has come leaps and bounds! If Photoshop 1 or Photoshop 2, or a clone, were released today, would amateurs

Read more