Side Project – To-Do List App

Now that I have finished development on Squares I am going to start working on a couple of different side projects. The first of which will be to create a simple to-do list app (not like there are enough of them). My objective is to use a variety of different technologies that I have been wanting to combine whilst working on a number of ideas over the past few years.

Web Service

The first part of the project will be to create a Web Service that will be used to sync users to-dos between devices. The Web Service will be built using the Google App Engine. This will allow me to develop the back end of the site using the Python. The Web Service will be used across a web app, an Android app and an iOS application. The web service will be built using a RESTful methodology that will implement OAuth2 to allow each application to be correctly authorised when using the application.

Web App

The web app portion of the app will consist of a simple single pages application that will allow the end user to create a list of to-dos. I am looking to develop the application using Dart. The reason for doing this is that I am familiar developing with JavaScript; I could go about developing this with a JavaScript framework but I fancy a little bit of a change.

Android App

The Android App will be implemented as per. I’m looking to try out a couple of libraries I have read about recently.

  • The first is RoboGuice
  • For connecting to a REST based service I am looking to use a library, instead of an AsyncTask. Unfortunately, AyncTasks are not tied to the Activity lifecycle and can result in a number of repeated unecessary calls to a web service. RoboSpice seems to be a great alternative.
  • I’m also looking to go about developing the app using test Driven Development so I will be using JUnit to carry out the tests on each individual component, I haven’t been able to do this in conjunction with Android yet, so this will be interesting.
  • I am going to use Mockito to mock the response form the Web Service during development.

iOS App

The Android App will be implemented as per. My previous iOS escapade was something new to me so I am looking to code the app a lot better. I will also be looking to carry out test driven development on this app. Something I am completely new to with iOS.

Android Code Patterns

One of the core principles that should be followed religiously whilst developing an Android Application is the Model-View Controller design principle.

What is Model View Controller?

Model View Controller, MVC for short has three key concepts that are necessary for it to be correctly used.

Model

The Model is used to represent data and to only represent data. It doesn’t do anything. The Model may contain the properties describing an object, such as a Person. The Model has no direct relation to either a View or a Controller. The Model will have a Low Coupling, meaning that it isn’t reliant on any other classes, this Model could be used in another project to represent a Person in the exact same way, and as there is no reliance on other objects, the Model could be completely taken out and then reinserted into the project.

View

A View in a project is used to display the properties within a project. The view may also inform the controller of user interactions within the project itself. These may be things such as the user clicking a button or the user pressing an item within an Applications Action Bar. The View is also independent of any Model.

Controller

The controller is what glues together the Model and the View together. The controller decides where to put the data and it decides what to do with User Interactions, as mentioned above. In some cases, especially with Android, the View and the Controller can be the same object. An Activity may implement a View OnClickListener that would be used to intercept a User Interaction from a Button click, for example, whilst also being used to put data into form elements.

Squares V2

Recently I have launched the second version of my first app Squares. I launched the original version of the app over 10 months ago on Android. In those 10 months the game has had over 7,000 downloads and it has a rating of 3.91/5 from 248 reviews.

At the end of summer, I decided to revamp the app from scratch. Largely because I felt the current game mode was actually quite limiting. Only being able to play for 60 seconds at a time seemed fairly limiting. The scoring system was actually a lot more difficult than it needed to be; 100 points for hitting the right colour and subtract 50 points for tapping the wrong colour.

The revamp of the game was pretty straightforward. The end goal of the update the scores the player of the game would be achieving. I hoped that an incremental point based system would make the game a bit more fun and maybe slightly more addictive! The game itself has been simplified to a 3×3 grid of colours that are continuously updating, and the target colour has been changed to a single coloured square at the top of the screen. I have also added theme support, the reason I have added this is to eventually support extra accessibility support in the future.

Here is the download for iOS.

Here is the download for Android.

Codility – Is Permutation

The next Codility challenge I will be covering is the IsPermutation challenge in chapter 2. The question can be seen in the gist below:

The question asks us to return 1 if an inputted array is a permutation, or 0 if it is not a permutation. As we know, a permutation is an array of elements containing all elements from 1..n, once and only once. Using that, we know that an array will fail any tests if an element is less than 0, or greater than the lengths of the array. We also know that if an element appears more than once, it is not a permutation. A good solution to checking if an element has already been encountered is to use a counter. Either a boolean or an integer counter would be appropriate, as long as it is possible to determine if an element has been checked before. My solution can be found below, I scored 100% correctness and 100% performance:

As always, check out the Git for this problem.

Codility – Minimum Integer

This is the first solution I will be providing for chapter 2 on the Codility site. Te second chapter is about counting elements. The reading material is very interesting, if a bit short, and perhaps unclear. It took me a couple of read throughs, it briefly discusses methods of storing numerical data in arrays. Within the first couple of paragraphs, I was already surprised to discover a counter array; storing the occurrence of a number within an array. Using this method, you can store the same amount of data, in much less storage space.

Back to the challenge though. The question itself can be found here:

The question says, find the minimum missing positive Integer from within the array. The array may not be sorted and elements may appear multiple times. Checkout my solution to the problem below, this achieved 100% performance and 100% correctness. However, I am guilty of going back and changing my result due to using counter.length + 1, instead of counter.length at a point in my code. Unfortunately, this caused a index out of bounds error, giving me only 60% performance, initially.

Also, check out my Git repository with the solution in.

Codility – Missing Permutation Element

The second question within the chapter covering Time Complexity on Codility asks you to find a missing element within an Array. The question is below:

Each element within the Array is unique and within the range 1…n+1, however a single element is missing. The Array is initially unordered. The result of the method should return the missing element. The problem is simple to solve; reorder the array and iterate through until a number is found missing from it. When it is found, return the value. There are a couple of cases that can mean no further processing will be necessary:

  • The Array is empty – Return 1, the missing element should be between 1…n+1, or in this instance between 1..0+1->1…1. (This can happen before sorting the array.)
  • The first element in the array is not 1. Return 1. (Must happen after sorting the Array)
  • The last element of the array is not n+1. Return Array Length + 1. (Must happen after sorting)

Now you have read the brief explanation above, check out my solution below:

Also, check out the Git Repository.

Edit

Since writing this blog post, I have just searched up how other people resolved this issue, and whilst I got 100% on both score and functionality, I was way off the best solution. Going back to my solution for the first puzzle. The key is to calculate the expected element length for the number of elements, then subtract each element of the array, this gives you the remaining element. Here is a link to the Stack Exchange answer where I found the answer. I can’t believe I didn’t think of that.

Codility – Frog Jump

The Frog Jump challenge is the third challenge within Codility’s first chapter on time complexity. This challenge is pretty simple, the question is as follows:

The question simply says, how many jumps of D length will it take for the frog to cover at least distance between Y and X. The key part to take away from the question is that the distance covered won’t be exact; the distance covered by the number of jumps has to be greater than or equal to the distance.

Below is my solution to the issue; it scored 100% on accuracy and on performance.

I made a Git repository for the code on my GitHub, check it out here.

Codility – Tape Equilibrium

Codility is a great site for learning, and testing your knowledge regarding some complex programming theories. Whilst the site contains many challenges, but there is a helpful section called lessons. Each lesson covers a topic and provides challenges for you to test your knowledge on.

 
The first of the chapter within the Codility is about Time Complexity. The first challenege within this section is named TapeEquilibrium, with it’s short description being: Minimize the value |(A[0] + … + A[P-1]) – (A[P] + … + A[N-1])|. Huh. Let’s take a look at the problem and the final solution for it. The description of the issue is below:

The question is simple, an Array, A, with N elements is passed into a method. Loop through each element of the Array from A[0] … A[n-1] each time calculating the difference between the sums of each side of the current key in the array.

The question tells us that the worst case time complexity should be O(n). We know that this is linear time, but it will likely end if a certain condition is reached.

Below I have put my final solution into a GIST. Using this, I achieved 100% correctness and 100% on performance.

I made a Git repository for the code on my GitHub, check it out here.

Disable Mod Pagespeed

Recently at work I have been developing a large project on a WordPress site. Unfortunately, over night WordPress updated to 3.9.2 and a whole host of errors occurred simultaneously. One error was that my JavaScript wasn’t updating and a some strange console messages were appearing, nothing I did would fix the errors, I originally looked for errors relating to the WordPress update. The error was nothing to do with WordPress itself, I discovered in a fit of disgusted rage 5 hours later.

The issue was related to an Apache Module Mod Pagespeed. This module appeared to have been activated by the hosting company, the same night as a WordPress update.

Fortunately a bit of htaccess wizardry fixed the issue. Below are the 5 lines of code that saved my sanity.