Asynchronously loading data using Googles Paging Library

The recently released Paging Library from Google gives you an easy way to page data into memory off of the main thread. If you want to use it with Room, then the built-in support makes it trivial. However, if you’d like to page data that exists elsewhere - from the network or disk, for example - then you have to do a little extra work.

Here I demonstrate how to take existing code that loads a list of screenshots from disk and convert it to load asynchronously using the Paging Library. This example could easily be adapted for network calls.

Read on →

Tensorflow in Windows Bash

My first job out of university was at a startup doing natural language processing (NLP). Recently I’ve been rekindling my interest in machine learning, and have been playing with the Tensorflow library from Google. I work on a Mac, but at home I’m switching between a Mac and a PC - and ideally I’d like things to just work on whatever machine I’m on. The Tensorflow setup guide says it requires Python 3.5 for Windows, but I’m using Python 2.7 on my Mac and would like to be able to use files across platforms.

Here’s a quick intro to getting set up with Tensorflow for Python 2.7 on Windows (using the recently released Bash on Windows).

Read on →

Implementing GCM Network Manager for periodic network requests on Android

In the process of rebuilding What’s Shaking, NZ?, I needed to implement a periodic network request (literally polling an API). I wanted to use the new Job Scheduler API, but unfortunately, this is only available on API 21 and above. Luckily we can get similar functionality by using GCM Network Manager, as suggested on StackOverflow. Note that the GCM Network Manager actually uses Job Scheduler behind the scenes in API 21+.

The documentation for this is somewhat hand-wavy. Here I attempt to provide a true step-by-step guide to implementing this. I assume you’re not already using GCM for something else in your app (as that was the case for me).

Read on →

Handling RealmMigrationNeededException on a fresh installation on Android

Back in November, I had just started using Realm on Android and was having some troubles. I’d occasionally need to make a model change, and being early on in development I was happy to just delete the Realm and start again - in production you’d want to perform a migration so you don’t lose any user data.

However, the “delete and re-install” approach wasn’t working as expected - I kept getting a RealmMigrationNeededException:

1
io.realm.exceptions.RealmMigrationNeededException: RealmMigration must be provided

This doesn’t make sense! I should be able to uninstall an app and upon reinstalling it I should have a fresh slate to work with. As it turns out, not quite. I couldn’t figure out why at the time, but the workaround was to simply add a deleteRealmMigrationIfNeeded() call to my Realm configuration when building it. I made a note to deal with this before release, and carried on my way.

Read on →

Automating iOS build numbers

I recently encountered some problems where I was accidentallly duplicating build numbers for our iOS app. At Bridgit we’re big fans of automation, so I went about finding a way to avoid this human error and let the machines do the work for me.

Read on →

A bug in (and a fix for) the way FragmentStatePagerAdapter handles fragment restoration

Ever used a FragmentStatePagerAdapter? We’re using one at work for our ticket purchasing wizard. The user enters the wizard, and can progress to the next page once they’ve completed the current one. We control this by manipulating the stack of pages and notifying the adapter that the data has changed when a new page is available.

Unfortunately, when changing pages that have already been loaded, there’s an unexpected bug. Specifically, when you load a page, remove it and then insert a new one in its place, the next time the fragment at that index is loaded, it receives the savedInstanceState bundle for the old fragment.

Read on →

20 Things, Week 20

Week 20 of my 20 Things in 20 Weeks project. I’ve finally made it. So, how did I do?

Read on →

20 Things, Week 19

Broke my Github streak this week, at 31 days - in fact, I didn’t get any programming done this week. My partner and I left Auckland on Wednesday afternoon and didn’t arrive home until late Sunday evening. We travelled around the Coromandel peninsula and spent time climbing mountains, visiting beaches, doing touristy things - and we got engaged! I’d say that that’s a pretty good excuse for missing a week.

20 Things, Week 18

Last week I wrote a Sudoku solver script in Python. That was fun and all, but as my girlfriend pointed out - it’s not really usable for, er, well, most people. So this week I decided to make it a bit more versatile and build it into a service, with a website to go with it. It’s currently up on Github and once I’ve added some polish to the website (heh, it’s pretty awful right now) I’ll get it up on App Engine.

Read on →

20 Things, Week 17

This week I finally got around to doing something I’ve wanted to do for a while; I wrote a Sudoku Solver in Python.

Unfortunately, it doesn’t work. At all. In fact, the more I look into it, the worse I fear it is. I’ve attempted this before, but I struck a minor obstacle with some Python syntax and did something else instead; this time, I’ve got the entire algorithm worked out and developed. There’s just some fairly significant logic bug(s) that’re causing problems. Re-reading the code, there’s also quite a bit of that which could do with a rewrite.

No matter! I’m pretty happy I got the majority of the work done, and I’ll keep working on it - a bit of refactoring should hopefully make the logical errors a bit more obvious.

Edit (Jan 21 2014): Fixed.