Academia vs. Business
November 18th, 2009 by Brad HeapFrom the wonders of xkcd

From the wonders of xkcd

One of my papers this semester is focused on Google Android Mobile Operating System.
The brief for my final assignment is:
Your task is to write any application you like. The are no restrictions on what your application can do but it should show of the capabilities of the platform and be well written.
Marks will be awarded for interesting applications that make good use of the Android platform.
Make sure your application works on the emulator but I will also test it on a real device.
For this assignment I decided to create a Blog Reader that reads the RSS XML feeds off blogs to display them in a Android Application.
I have spent around three days coding this assignment. I will not release the code until after the assignment has been marked, however here are some screen shots of the work

My Application Sitting in the Android Application Menu on my phone

The applications home screen

Adding a new blog feed into the application

Viewing a list of blogs

Removing a blog feed

Viewing a list of blog posts

Viewing list of blog posts

Viewing single post
Okay as part of my internship I have to deal with a huge number of text strings.
These strings come into the program unsorted and they must be sorted and each one must be unique. (i.e. no duplicates).
Now there are a few different ways to be able to store this data.
A SortedList, SortedDictionary, or two different forms of lists, the first where before each add you check to make sure that the data doesn’t already exist, and the second where you just add then sort then remove duplicates at a later time.
Two work out what one would be best I wrote a program to determine which form of storage operated the fastest on input. The results follow and then the code for how I did it.
As you can see the SortedDictionary worked the best, however at the early stages both the SortedList and Duplicate List gave it a run for it’s money.
Results
Sorted List Test: 00:00:00.1169883 Input: 5000 4000 List Size: 2838 Sorted Dictionary Test: 00:00:00.1339866 Input: 5000 4000 List Size: 2858 Unique List Test: 00:00:00.1119888 Input: 5000 4000 List Size: 2862 Duplicate List Test: 00:00:00.0239976 Input: 5000 4000 List Size: 2832
Sorted List Test: 00:00:01.3768623 Input: 50000 40000 List Size: 28516 Sorted Dictionary Test: 00:00:01.0678932 Input: 50000 40000 List Size: 28466 Unique List Test: 00:00:12.3097689 Input: 50000 40000 List Size: 28384 Duplicate List Test: 00:00:01.2058794 Input: 50000 40000 List Size: 28549
Sorted List Test: 00:01:36.9733017 Input: 500000 400000 List Size: 285367 Sorted Dictionary Test: 00:00:12.3307668 Input: 500000 400000 List Size: 285422 Duplicate List Test: 00:02:32.7467238 Input: 500000 400000 List Size: 285506
Sorted Dictionary Test: 00:02:37.8040000 Input: 5000000 4000000 List Size: 2854095
Definition: The state of sending the wrong expression to be checked and getting back the opposite response to what you are expecting.
Suffixes: if s add es, else not s add s
Abacus -> abacuses not abacuss
Monkey – > Monkeys not monkeyes
Okay I got a lession in why you shouldn’t rush code on a Friday night.
This morning on my internship I was cleaning up some code I had written last friday and making sure everything worked as planned.
While checking some of the output of the program I came accross this word: Reabsorbsinged. I thought it looked a little odd and upon closer inspection of the code I found out why.
The word Reabsorbsinged is made up of one base word: absorb. From this you can combine prefix and suffix to build more words e.g. Reabsorb, Absorbs, Reabsorbs etc.
However in my blind coding last week I had failed to realise a cruicial mistake I had made when trying to take a shortcut. I had fed my input variable into a function and overwritten it at the sametime. This is a good trick if you want to minimise memory and you don’t need to worry if you input variable is overwritten.
Unfortunately I needed my input variable to stay intact to be able to generate the other words (like above). Instead I ended up with just one huge word: re+absorb+s+ing+ed So like you end up with dick of the day in some jobs I now have word of the day.
And on an entirely different note:
I am currently converting the code that generated this mistake from c++ to c#. Easy enough C# is pretty similar to java and doesn’t have pointers, yes! However as I discovered it doesn’t have a string reverse function either.
Glancing on the internet there are a few around pretty much going from extremely long and memory expensive, i.e. copying each character onto a new string at each step, or extremely quick but near impossible to read, understand or debug. So I got smart and wrote my on.
The code was a long the lines of this:
string normalString = "abcdef";
char[] tempString = normalString.toCharArray();
for(int i=0; i < tempString.length / 2; i++) {
char tempc = tempString[i];
tempString[i] = tempString[tempString.length - i -1];
tempString[tempString.length - i - 1] = tempc;
}
string reversedString = tempString.ToString();
And today’s other top story.
NZTA was told in mid December they had security issues but did nothing.
http://www.nzherald.co.nz/technology/news/article.cfm?c_id=5&objectid=10550914
I have been laughing over the last few days as the New Zealand Transport Authority has become more red faced over the massive security hole in their toll road payment system.
On January 25 the Silverdale to Puhoi motorway extension will open, however to drive on it you will need to pay tolls, and for the last two months or so the NZTA have been advertising the www.tollroad.govt.nz website heavily so regulary uses of the new road can set up accounts.
On Monday a computer user realised that the website was not encrypting credit card information which means that anyone who knows anything about packet snifting or the like could intercept peoples credit card details as they used the website.
Now first and foremost this should never happen. Not on any ecommerce site, let alone a government website. Ecommerce programing 101 would surely teach you that first you must always encrypt data through using SSL and HTTPS not plain HTTP.
But what was more funny is that the red faced NZTA denied that there was anything wrong with the site! Refusing to take it offline or stop processing accounts.
That was until today when with egg on their face they took down the site for maintenance and admitted they stuffed up. Time to get new programmers one thinks.
Read more here:
http://www.nzherald.co.nz/connect/news/article.cfm?c_id=1501833&objectid=10550614
and
http://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=10550744

Update: Source Code now available. Head over to the software section to check it out. http://www.brad.net.nz/?page=Software
For the past few weeks I have been thinking seriously about heading back to uni to complete my honours degree.
Currently some of the team in Computer Science at Massey have been playing with JOGL.
I had a look at it the other day but didn’t get very far. Well tonight I decided to really get my hands dirty.
And it rocks! Im currently seeing if I can convert my traffic simulator to JOGL.
Will keep this blog posted on updates.
Here is a challenge for you: http://www.hack-test.com
I am on level 11 and stuck. (A google search got me to level 12 but I still want to be able to solve level 11).
How high can you go?
I can’t believe it.
I was coding today and I actually found a useful use for Recursion.
Basically I was programming a dynamic grid and it was for once easier to use recursion then a double nested loop.
I am stunned myself. And this wasn’t Haskell either it was Java!
I am currently working on a complex website that requires two different companies on two different domains to share the same website. I have just mananged to create a piece of php code to analyse the domain name typed in and redirect to the correct section of the site for that company. Awesome!
$url = $_SERVER['HTTP_HOST'];
if(strpos( strtolower($url), “site2″ )!=FALSE) {
header(‘location:site2/index.php’);
} else {
header(‘location:site1/index.php’);
}
It is not often that code makes me happy.
I have just rolled out a complete overhaul of my website.
The changes in summary:
New:
Updated:
Deleted: