Code

Parley meets Android in Cairo

April 29th, 2009  |  Published in Code

I’m exactly three months into my Arabic studies in Cairo, where I’ve been taking time off university studies and Amarok development. I’ve realized that acquiring a large vocabulary as fast as you can manage is a crucial part of studying a language intensively, and thanks to the awesome KDE-Edu folks I’ve been successfully barely keeping up with the hundreds of new words I’m assigned per week with Parley.

The major problem I have with Parley is that I have to be in front of my computer to use it!

I know you’re laughing. That’s like saying a major fault of beer is that you have to drink it to get drunk, after all Parley is a computer program.
You’re right, just because I hardly find the time to actually use the computer doesn’t mean I should lay the blame on Parley. Technically, I should blame the denizens of Cairo and their insane traffic. Seriously, too many of my life’s hours are wasted in the smelly, stuffy, taxis of Cairo (today was particularly bad, pardon the rant).

This past weekend I ignored the towering pile of homework and whipped up a little application for Android devices that groks Parley’s kvtml2 file format, displays lessons, and provides flashcard exercises. My app is really an Android Port of the J2ME mobile application MobVoc. Michael, the MobVoc developer, did most of the hard work for me: parsing kvtml2 files into java data structures. Mad props to Michael; I definitely plan to pass along any contribute any bug fixes/optimizations I make to his code (such as sub-lessons support).

The application – unimaginatively dubbed ParleyDroid for now – is extremely bare-bones. Here is the current feature set

  • Pick a kvtml2 file from the SD card
  • Choose 1 or more lessons to practice
  • View flashcards of the words in the selected lessons.
  • Gesture support in the flashcards: Long Press marks card as known, Fling Left/Right changes to Next/Prev card.
  • Each practice session has a short-term memory: i.e., if you mark a card as known you won’t see it again that session but if you restart the session you will.
  • Arabic Support – if the 2nd language is Arabic, it will be rendered correctly on screen

The last feature is probably the most noteworthy. Android, by default does not support RTL or non-Latin scripts, but with a little Android-trickery-that-deserves-another-blog-post I’m finally able to practice my vocabulary in the back of the taxi or while walking along the Nile.

Binary and Source:
ParleyDroid Source
ParleyDroid Android Binary

Obligatory Screenshots (click for full view):
ParleyDroid Pick File ScreenParleyDroid Lessons Screen
ParleyDroid First Word ScreenParleyDroid Second Word Screen w/ Arabic

The Lessons of a Master

January 24th, 2009  |  Published in Code

Several of us at Camp KDE—myself included—owe a great debt to Till Adam. When he came to the sunny, beautiful beaches of Jamaica, instead of spending his days lounging on the shore or swimming in the warm Caribbean, he chose to pen himself in a stuffy room with a dozen geeks and teach them Qt.

Till works for Klarälvdalens Datakonsult AB (KDAB), the Qt consultancy firm. Besides working on large-scale, enterprise Qt applications, KDAB provides professional Qt training to such companies as IBM, Boeing, Ericsson, and J.D. Edwards. These training sessions usually run a few thousand Euros per person. With the OK from Nokia and Qt Software, Till provided us with a mini two day training course for free!

While the content and materials Till used during the sessions is copyrighted, the information I learned is not. With his permission I’m going to discuss a few pointers in this post. The topics covered somewhat basic/intermediate Qt skills, so those of you who have been programming with Qt for any length of time might not find anything new or interesting. However, for those, like me, who haven’t quite developed our Qt Fu to the Master level, take away tips from here knowing it was passed from a master.

#1 Most Common Performance Issue in Qt
Converting from a QPixmap to QImage too often.

This tip is actually fairly well known, but apparently KDAB consultants run across this mistake very often while in the field. There is a great discussion of this topic over at KDE’s techbase. In summary:

  • A QImage is stored in main memory
  • A QPixmap is stored in video memory
  • Converting from a QPixmap to a QImage is a very expensive operation (see the above article for the explanation)

#1 Most Common Cause of Crashes in Qt
Deleting this from slots

This tip needs some more explanation. Essentially, a mistake many Qt programmers do is include executable code after emitting a signal. Consider this flow of execution:

  • The function Produce::blend() emits signal pineapple()
  • The slot slotBlender() deletes the instance of Produce
  • The signal/slot connection returns to the function Produce::blend(), which has some other executable code such as variable assignments after the emit.
  • Crash. Since the slot deleted Produce, any code following the emit statement that modifies memory is now attempting to write to invalid memory.
  • One good practice to follow is: don’t have any executable code following the last emit statement in your objects’ methods.
    However, the real solution is: Use deleteLater() on your QObjects.

    This post is getting somewhat lengthy and I potentially still have two topics to cover (Threading and Model/View). Most likely I’ll dedicate a post regarding threading in Qt (I took better notes during that talk) in the next couple days. Many thanks to Till for the sessions, as well as KDAB and Qt Software for allowing them to happen.

Amarok & NPR :: 13 Years of News Media Now Available at Your Fingertips

November 5th, 2008  |  Published in Code, Technology

Earlier this summer I had noticed that National Public Radio (NPR) launched a brand new open API based on open source technologies. My initial reaction was at best skeptical. I assumed any sort of “API” released by a major media outlet would turn out to be nothing more than a few customizable RSS feeds. If the company was particularly progressive the RSS feeds might include full articles, rather than the neutered one-sentence teasers you find in all the big name’s syndicated content.

I couldn’t have been more mistaken. NPR’s API is no small potatoes. Just take a look at the comprehensive Query Generator to get an inkling of the types of complex queries you can create. Looking at the Query Generator also sheds some light on the content you can retrieve using the API. The API’s main page says the API exposes the entire NPR archive of content starting from the launch of the NPR website in 1995. Just how big is this archive? Over 250,000 stories including text, images, video, and audio!

This quote from the article announcing the API caught my eye immediately:

There were quite a few questions that we addressed when developing the API, but one thing that was not really in question was the need to open as much of our content as possible.1

This isn’t the first open media API. BBC was the first to offer a public open access API, however BBC’s API is restricted to the content from the past 7-days. Seven days! That’s nothing compared to the (approx.) 4748 days – and counting – that NPR’s API offers. NPR and the BBC are two large companies leading the technological shift towards open and free information.

But that’s only half the story.

After discovering this fantastic API I had to do something with it, and the new service architecture in Amarok 2 provided the perfect platform to build a NPR mashup. That was several months ago, and at the time the scripting API in Amarok was still being flesh out (Thanks to Peter). On Monday I noticed the BBC scriptable service Nikolaj had created for Amarok 2. I happened to have several hours of free time, so I cooked up a similar service for NPR:

You can get it at kde-apps or via the “Get More Scripts” button in Amarok 2′s Script Manager.

There is definitely room for improvement and in fact here are a few things I plan to do with it:

  • Display more than 20 stories under a category
  • Sort content by date
  • Support searching
  • Display the full articles, with images, in the context view

Major props and thanks go out to the entire NPR technical team and all the contributors who made API a reality.

  1. NPR API is Live on NPR.org []

Exporting contacts from Verizon to Gmail

October 23rd, 2008  |  Published in Code, Technology

I got a G1 today.

That deserves a post unto itself, but I wanted to share a solution an annoying issue regarding switching from Verizon to T-Mobile. Before I got the G1 I had a LG-VX9800 (yes, ancient, I know) with around 200 contacts. Obviously one of the first things I wanted to do when I got my G1 was transfer all my contacts from the LG to the G1. There are several ways to do this

  1. Go to a Verizon store and pay $10 for data backup
  2. Buy a USB Cable for the LG-VX9800, and use bitpim
  3. Manually copy (type) your contacts into the G1/Gmail
  4. Use my method

There was no way I was going to pay $10 for what should be a simple “Export,” so #1 was crossed out. I’m impatient and didn’t want to wait for a cable to be delivered and neither did I want to pay the money for one. There goes #2. I didn’t even consider #3; I just listed it for completeness sake.

That leaves my somewhat difficult and unreliable method. Basically, what I do is use Verizon’s “Backup Assistant” tool to send my contacts to Verizon’s website. Then I save the source of the “Print Contacts” page – because there is no export feature. With a little ruby I parse the file into Gmail’s CSV format and import the file via the Gmail contacts page.

Here’s a quick howto.

  • On your Verizon phone go to “Get Going -> Get a New App -> Backup Assistant” and install it for $1.50 a month.
  • Follow the prompts and backup your contacts.
  • Go to the Verizon backup website and sign in.
  • View your contacts and click the “Print Contacts” link. Save the source of this page to a file
  • Download this script and run it against the saved html file. Save the output in “contacts.csv”
  • Go to the Contacts page in Gmail and select Import, and upload “contacts.csv” Note: I suggest using the “add these imported contacts to” a new group feature. Because you will likely have to merge and cleanup the imported contacts.
  • Import and Enjoy

IMPORTANT: My script only grabs the following information from the Verizon contact list: Name, Email, Work Phone, Mobile Phone, and Home Phone.

GSoC Wrap Up

September 18th, 2008  |  Published in Code, Technology

If there was a blogger award for “Most likely to make timely posts”, then in no possible world would I even be considered for the award. I could list some excuses that sound legit in my head, but the real reason I don’t feel motivated to post often (or on time) is because I’d rather spend that time in Google Reader reading everyone else’s exciting content (that was not sarcastic).

So, lets see… last time I posted I was en route to Akademy 2008 (the KDE developers conference). That was July 30th, now, a month and a half later I am back from Europe (which was amazing), GSoC is over (sad), and class has started (jury’s still out).

Current Status of the MP3tunes Amarok Service

The Good (Works)

  • Browsing & Streaming
  • Querymaker is as functional as possible with the current API
  • Manual Downloading from MP3tunes to Local Collection
  • Manual Uploading from any Collection to MP3tunes

The Bad (Doesn’t work)

  • AutoSync – 80%- The code is there, however there are problems with the daemon not receiving signals from the MP3tunes’ servers
  • MP3tunes playlists support – 0%- Never got started on this

The Ugly

There is one large issue I am still wrestling with. The details of the issue are complicated, but essentially it deals with the way Amarok handles remote tracks in playlists across sessions. Generally, remote tracks’ metadata isn’t cached by Amarok for use between multiple sessions. So, if you add an mp3tunes track to a playlist in Amarok, then restart Amarok and try to play that playlist the mp3tunes track is blank. Now, there exists a method for retrieving that metadata, however it was originally implemented synchronously. When you are retrieving metadata for any significant number of tracks (10+) synchronously, and each one of those retreivals is an HTTP Get request you end up blocking the GUI thread. At Akademy I hacked a way to do this asynchronously, but it is a really nasty hack. I’ve got code on my computer that implements this feature correctly, but it has the nasty habit of crashing Amarok every so often.

Between classes, marching band, homework, and other responsibilities I’m working on getting this ironed out and committed. Hopefully this will happen before the 2.0 release, because right now using MP3tunes in Amarok across sessions is slow and annoying.