My experience at Uppsala Hackathon, and how to build a mobile app in a day

This post originally appeared at Swedish Startup Space.

Swedish Startup Space wrote about the Uppsala Hackathon back in June and I decided that I wanted to participate in this “gathering of programmers to collaboratively code in an extreme manner over a short period of time”.

The Uppsala Hackathon was attended by about 60-70 participants. Some people had teams and ideas before they arrived, but I had not found a team, so I joined one that consisted of the Valtech ConsultantsSara IngmarDaniel LervikPetter Norman and Sandra Nyström.

Design and Motive

In the beginning of the hackathon we knew that we wanted to build an app that would help solve difficulties when using public transportation. To solve the problem, we needed to use a few different API’s. Instead of collecting information from different API’s and combing results on the mobile application itself – we decided to build our own API.

In doing so, we keep the amount of data down to a minimum which is good because traveller’s/commuters doesn’t always have high bandwidth networks available. We can also be confident that we are sending the correct information to the device and avoid wasting precious data. This also gives us the opportunity to extend our service with more public transport agencies while maintaining control of performance and bandwidth of the app. Another benefit of using your own API, is that it makes it extremely easy to build another app for another platform since we have full control of the API.

Backend solution

We chose to build the API on .NET because the team had most experience on the platform. Daniel had previously participated in a project at Valtech where ServiceStack was used to build the API. ServiceStack is an open source REST web services framework which had lots of good stuff we could use. To further speed up the development process we used AppHarbor to host the API.

Mobile app

The mobile app was going to use the API generated by the ServiceStack. Both Daniel and myself have previous experience of developing mobile applications, so we focused on this part. The API was consumed using RestKit, an amazing framework for dealing with RESTful APIs.

The mobile app was developed using CocoaPods, because there is no sane person that enjoys dealing with dependencies and build flags in Xcode. Enter SLussen, see the demo of the app in the video below.

Disclaimer: the lag you see in the film is because of the delay that appeared when doing screen recordings.

We won! The jury wrote the motivation:

The SLussen project helps commuting travelers to calculate total ticket prices when traveling through different zones in Stockholm county. This project has was picked for its potential value in Uppsala county.

Read more

Thanks Petter for a great summary of the backend!

Video

Remove Previous, Next and Done buttons from keyboard in Phonegap in iOS

I’ve been working on my first Phonegap project together with a friend the last week or so. He’s been developing most of the app for Android and Eclipse, and my job is to make sure it runs smoothly in iOS. It contains in-apps and some other goodies that I will post about later.

Hide buttons

Since everything in Phonegap is a UIWebView, I needed a way to get rid of the silly previous, next and done buttons when focusing my keyboard. This uses private API:s so it will make your app rejected if you submit with this code.
6X1vv

The solution is to modify your AppDelegate.m to something like this:

Remove and add focus on keyboard

When bringing a keyboard in and out, use the following to remove focus from it

$('#searchform-1').blur();

And use this to bring focus to an input field:

$('#searchform-1').focus();

Swedish Startup Space launched!

Last week a friend of mine got in touch with me, asking for help about a website he’s been trying to put together on his own. James now works at Helishopter and previously worked for Jameslist. He wanted to create a community for swedish startups, it was something he and many others felt was missing for the swedish startup scene.

Said and done, yesterday we launched our first version. It was running on Heroku for a few hours but the site broke down and I had to move the site in haste to Binero. Since we are running WordPress and all the media assets is on Amazon S3 it is very easy to migrate the site to another host. We will make sure to make the new setup more stable before we attempt to move it again.

Head over and visit us!

Integrate Testflight, Flurry and Corona SDK

Testflight

I use Testflight to coordinate pre-releases of software I develop for the iOS platform. Testflight is an amazing tool and I’m surprised Apple hasn’t bought the company yet. You simply create a group of people, send out invites and have them register their devices with Testflight. Unfortunately, the provisioning profile in the iOS ecosystem is a huge clusterf*ck, so you have to manually and not to mention painfully add these identifiers to your provisioning profile in the Apple Developer Portal.

When the profile is updated with the correct devices, you upload the .IPA to Testflight and add some release notes and hit send. The people participating in your beta release will then get an email that they can download a new version.

Testflight and Corona SDK

At work, we use the Corona SDK to develop multi platform games. Corona Labs describes their product as follows:

Corona SDK is the leading mobile development framework. Build high-quality apps and games for iOS, Android, Kindle Fire and Nook in record time.

It works remarkably well, not too much problems and it’s easy to deploy. Anyway, to integrate Corona SDK and Testflight you need to do a couple of things:

  • Build your software and generate the application and it’s zip file
  • Create a new folder called ‘Payload’ and move the application file into it
  • Compress that file and change its extension to .ipa instead of .zip
  • Upload the IPA to Testflight

Flurry

Screen Shot 2013-02-10 at 13.48.39
Flurry’s error log

Flurry is a great tool for gathering statistics, I’ve used it in all applications I’ve created for iOS and made sure its been used on Android as well. One of the best features for me as a developer is the fact that I get access to the crash reports (see the picture below).

To use Flurry with Corona, you use their analytics library.

-- Import library and initialize with personal application key 
require "analytics"
analytics.init( "YOUR_APP_KEY" )
-- Log event ID
analytics.logEvent( "Event ID" )

One thing I sometimes wish I would’ve implemented earlier in the project, is a log inside the app. The log should save the current state and the roadmap with the relevant server/client calls that took them there. It should also include the option to send this log to the developer.

2013-02-10 13.45.02
Evernote’s log

Evernote has implemented this very neat and it could be of tremendous help when debugging the communication between the server and the clients.

Game of Life implementation in Erlang

Background

The universe of the Game of Life is a two-dimensional grid of square cells, each of which is in one of two possible states, dead or alive. Each cell interacts with its eight neighbors, those cells that are horizontally, vertically, or diagonally adjacent. At each unit of time the following transitions occur:

  • Any living cell with fewer than two living neighbors dies, as if by under-population.
  • Any living cell with two or three living neighbors lives on to the next generation.
  • Any living cell with more than three living neighbors dies, as if by overcrowding.
  • Any dead cell with exactly three living neighbors becomes alive, as if by reproduction.

For an assignment at school, my classmate Jonatan and I were to implement this in Erlang.

Demonstration

This video demonstrates the finished game and two examples called a pulsar and a glider.

Source code

First off, here is the main program. If you would like some more information before seeing the code keep scrolling.

Data representation

The input to our program is represented as a list of {X,Y} tuples containing coordinates. Our internal data is represented as a single list using the indices of the list as a one-dimensional representation of the grid. This was chosen over representing the game and its input as multi-dimensional arrays for simplicity.

Note: the worst random access time of a list compared to an array is negligible as random access is only required once during the setup.

Each cell contains information about its coordinate, current state (dead or alive), list of its neighbors, and information about them such as number of living neighbors.

Synchronization

To keep our game in sync and avoid race conditions we use a “master” process to notify all cells when a new unit of time (tic) begins. Each cell responds by sending its current state to all of its neighbors then waits for its neighbors to send their current state. When all current states have been collected the new cell state is updated and drawn. This avoids synchronization issues by making sure all processes start at roughly the same time.

Source code for supporting files is available in this Gist.

To run the program:

c(ehtml). 
c(frame). 
c(gol).
gol:gol(40,40,[{5,4},{3,5},{5,5},{4,6},{5,6}]).

Open a browser and go to the URL http://localhost:8088/

Known bugs

The update rate for the browser is not in sync with the actual game update. This causes some irregular behaviour in the visualization of the game.

Summary

I would like to try to make a version of Game of Life in Node.js and see what advantages Node.js brings to the table in a GoL-implementation.