Category Archives: Tutorial

From CD to Cloud with Debian

Hi again, Merry Christmas and happy new year to all 🙂

One of my favourite new products in recent months is Google Music, a new cloud-based music system which allows you to keep up to 20,000 tracks on Google’s servers. In a similar fashion to Apple’s iCloud, this music can then be accessed at any time via your Android devices or a web browser. Having used Google Music for nearly 2 months now, I absolutely love it – so much so that I’ve cancelled my Spotify subscription.

Around a year ago the media hard drive in my home server crashed, causing me to lose almost all of my digital music collection. Recently I’ve been starting to re-import my CDs so they can be uploaded to Google Music, going via my laptop. Problem is that the CD importing is happening via iTunes, and my 5-and-a-half-year-old macbook certainly isn’t as fast as it used to be – the spinning beach ball of doom regularly pops up. So why not let my home server take the strain? Pop in a CD, let the server automatically rip it and eject when it’s done, and have that new music automatically uploaded to Google. That’s entirely possible on a headless Debian server.

My starting point was a blog post which deals with ripping CDs on a headless server using ivman to listen for an audio CD being inserted and abcde for ripping. However, I later discovered that ivman has effectively been abandoned and has since been replaced by halevt.
Continue reading

Speed Development, or how I learned to love the App (Part 1)

(The finished app can be purchased on the Android Marketplace)

Let me set the scene first: It’s mid-evening, I’m in my home office working on my next major app but nothing seems to be clicking. I’m trying to get a fairly simple feature to work, but it’s not. Even the logs and debugging list isn’t giving me much of a clue. The heat of two computers, a laptop and a server in a small-ish room compounds my frustrations further.

Then I give up. I close Eclipse and play some Team Fortress 2 to unwind.

Sometimes when I’m coding something that takes a lot of my time, something that seems like it’s going to take forever for a one-man effort, it’s disheartening. It happened with My Shopper, an app I spent months pouring my efforts into, but ultimately didn’t sell well. I’ve got high hopes for this current project, but it still feels like it’s too easy to get completely lost. At times like those you just want to do something different, start fresh.

So that’s what I did.

Inspired by the second episode of this year’s Apprentice and fuelled by tea, I decided to set myself a challenge – come up with an idea for an application and bring it to the Android Marketplace by the morning.

The Idea

As it was 11pm, and I effectively had up to 9 hours to get this app complete, I had to think of an idea that was small but practical and whose scope was unlikely to spiral out of control. I also had to find an idea that, while not completely unique, was not likely to be crowded out by an established or superior app. Something that was likely to be used in a real-life situation.

After jotting down some ideas and comparing those ideas to existing apps on the marketplace, I opted to make a Lottery Number generator. The structure of the program would be simple – a random number generator picking numbers within the rules of each game. The rules of the chosen game would then be fed into the generator, meaning the app could be expanded for other non-UK lotteries in the future.

The simplicity of the program structure meant I could make a bare-bones demo of the app within a couple of hours, getting the functionality done and frozen before giving serious thought to the look and feel.

The Realisation

At this point I had a realisation, one of the reasons I was becoming bogged down in my major project – I had spent too much time on the User Interface, how the app was going to look, but not to the features and how it was going to work. What I thought were simple features were spiralling. I was having a hard time keeping these new features under control because I didn’t have a map of what features were required, and ultimately didn’t know how to implement them. Essentially, without the map, I was lost.

Whether it was the coding or the coffee, things were starting to look a lot clearer both in this challenge, and my coding techniques.

My name is JSON, Part 1

So here it is, my first post. And while I may have been slightly distracted by the rise of our robotic overlords, it didn’t take me that long to think of a starter for 10. As a mobile and web developer there are always certain things that may not seem important at first, but start to take a greater importance when you realise just how useful it can be, even for mundane things like encapsulating data for easy transfer.

So I’m beginning with Javascript Object Notation, or JSON for short. JSON is one of the most widely-used methods of holding data in a structured format, XML being its main rival. This was a topic originally thrust onto me during a University project in 2010, and while seeming daunting at the time turned out to be fairly straightforward. Before I explain how this data can be handled in PHP and Java, let’s take a look at some JSON-encoded data.

So what does JSON look like? Something like this:

{
    "forename" : "Michael",
    "surname" : "Dodd",
    "age" : 23,
    "breaks" : [34, 66, 12, 35, 22, 73, 94, 147],
    "match" : {
        "frames_won" : 5,
        "frames_lost" : 3
    }
}

This example is my performance in a snooker match (I wish!). Similar to PHP, this data structure can be seen as an array with named keys. Each key can contain:

  • A simple value such as a string or integer.
  • An array of simple values, denoted by square brackets [ ].
  • A child JSON object, denoted by curly braces { }.

With the ability to structure data in such a fashion, it is easy to map the data in a JSON object to the data structure in your application. One point to note when creating these structures, however, is to make sure that the final entry in each object does not have a comma at the end of it as this may cause problems with some parsers.

In the next few posts, I will explain how JSON data can be used with PHP and Java (with an Android flavour), but for now check out some of the many potential uses of JSON data with the Guardian Open Platform API.