More Swift – A minor refactor

In my earlier I post I talked about not being very sure that a method I wrote for one of the Stanford iOS Programming course assignments was really embracing Swift as a language. I then posted about using Swift’s unit test framework that would make any refactoring easier and better.

And so on to the refactoring…

Well, with a fresh day came a fresh eye, and there was not too much I could really do to make the method more Swift than C/C++. I ended up mainly folding some let statements into inline expressions. Not exactly hard, but when all was completed I think the code is more or less as tight as it could be and still easily readable – opinions to the contrary are very welcome.

Continue reading

Using Swift’s Unit Test Framework

In an earlier blog post I wrote about my solution to one of the homework assignments for Stanford University’s iOS programming course. My conclusion was that, while the code worked, it seemed a little bit too C-like and not really embracing some of the elegance of the Swift programming language.

My intention is to rewrite the code and see if I can get it looking somewhat more Swifty. But of course in doing that I don’t want to break it – there’s a lot of different cases the CalculatorBrain has to handle. This is a classic scenario that can be solved using automated unit testing.

When you create a new application project in XCode, as well as the main build target you get given a test target with boilerplate code for using XCode’s unit testing framework. It is simple to use – just add new functions to the test class, and use XCTAsserts to ensure the right results.

Continue reading

A simple Perforce backup script for the home

I use the free license of Perforce on my home network just to ensure version control and management of home coding projects, university thesis stuff, and general files that I just want to ensure I have previous versions of. It’s a really nice part of the Perforce licensing model that I can get two users and five clients for free. My network has my main PC (with Perforce depot), my personal laptop, my wife’s laptop, and my work laptop all connected. It’ll get worse when my four-year old starts wanting to source control things from his PC!

Having been responsible for some pretty heavyweight Perforce installations in my working life, I did not want to forget the golden rule of checkpointing and backing up. While it would not be a disaster if my Perforce data got lost or messed up, it would be an inconvenience. The scripts published on Perforce user forums, however, tend to be focussed on industrial installations and can be quite complex. For the home it is nice to have something more simple.
Continue reading

Plotting your GPS tracks in Google Earth

Google Earth

As a follow up to my previous post about using Google Maps in conjunction with your own GPS data, you can also do the same thing in Google Earth. Something I missed before was that the same GPSVisualizer site provides the service so that you upload your GPS file, and it generates a Google KMZ file for you. Click on it, and the file gets downloaded and launched in Google Earth directly. Very neat and very easy. Here’s a screenshot:
Continue reading

Playtime with Google Maps and GPS

I’ve been dabbling with Google Maps recently as I want to download some GPS data from my PDA to visualise and analyse journeys that I have made. I also think Google Maps and its 3D sibling Google Earth are the absolute dogs doodads of applications and so any excuse to play with these was welcome.

I started with a .GPS file that was generated automatically by Copilot, which is the in-car satellite navigation software that I use. It’s pretty good, but like all Satnav systems you need to be aware of its foibles to get the best out of it. Never, ever, simply follow the instructions!

The GPS track was a record of my travels on Monday 25th June as I tried to get into work in Sheffield as it was getting hit by freak floods. Getting in was OK(ish), but took a long time. Getting home again was a bit more interesting as I kept trying to avoid all the bad traffic.

Anyway, since I was being forced to turn around and try new routes to avoid flooded roads, jams etc, I wanted to see on my PC where I had been. What I did not know was a quick and easy way to do it.

Copilot has a PC hosted planning application, but that won’t take the GPS tracks that the PDA version generates (sigh….). Ideally I wanted to put the tracks into Google Earth to look at in glorious 3D, but I currently only have the free version that does not allow GPS tracks to be imported.

A quick webhunt brought up GPS Visualizer. This provides a free service that allows me to upload the GPS file, and it generates a Google Map with a vector overlay of the results. Even better, the site contains instructions on hosting the resulting map on your own website.

So I had a go at this. The HTML pathway was a huge faff, to be honest, as I was rather foolishly trying to use Frontpage. The problem was that it was trying to be too smart on the Cut and Paste operation, which screwed HTML tags over. In the end, a quick path was to:

  1. View GPS Visualizer page source
  2. Save source to local HTML file on disk
  3. Open HTML with an editor. Even Frontpage could manage this bit!
  4. Locate the Google API key, and replace it with my own (see below).
  5. Set page titles, modify the default 600×600 window
  6. Upload to my website
  7. The resulting page can be seen here.

    If you want to do this yourself you’ll need a Google API key, which you can get from here

Streamlining your PC to play games

Overview

Before I run a resource intensive game, I execute a little batch file that kills a bunch of background processes that are simply not needed when playing the game. I’ll explain the details below, but don’t forget to click here today to find out about one of my favorite gambling games.

I have also noticed that before I used to do this, I experienced awful crashing problems with my PC just locking when playing. Since killing these extraneous processes, however, I have not had a buy CBD products in-game crash that I used to get regularly with both BF2 and BFV. I think this shows that something in my system is having a bad interaction with the game – probably the graphics driver. I used to think it was an interaction with Panda antivirus, but recently I modified the script to not kill Panda and things still run OK. This makes me a little happier that I can keep my AV program running at all times.
Continue reading