Should I cycle: choosing APIs

Since I’m going to have to build an API for my app before I write any code I’m going to think about what my API should look like.

To do this I’m going to do some investigation of what APIs are out there which my API will call.

For air quality I found the London Air API. It looks pretty good, easy to use with good documentation. I can get the current air quality for Putney by calling: http://api.erg.kcl.ac.uk/AirQuality/Hourly/MonitoringIndex/SiteCode=WA7/Json

Which Weather API to use?

Yahoo

Choosing a weather API was more difficult. I was originally going to use Yahoo’s weather API, I can get London’s weather like so: http://weather.yahooapis.com/forecastrss?w=44418&u=c

But I couldn’t see any “chance of rain in the next hour” metric in the results. Which is annoying, because Yahoo’s own iOS weather app has that information nicely presented. Using Charles proxy I could see that Yahoo’s iOS app uses https://mobileweather.yql.yahooapis.com and not their own public weather API. Its query for London looks like “select * from yahoo.media.weather.oauth where flickrGroup=’1463451@N25′ AND hourly=’TRUE’ AND hours=’23’ AND days=’10’ AND pw=’1316′ AND ph=’1316′ AND uv=’TRUE’ AND unit=’C’ AND mp=’true’ AND lang=’en’ AND woeid in (44418)”

Anyway, without the “chance of rain in next hour” metric I started looking elsewhere.

Forecast.io

I took a look at Forecast.io’s API and their API looked great – easy to use and it has the hourly forecast which is what I want. But when I tested its results for London a couple of things bothered me. 1. it’s in imperial only, not metric. OK that’s not a showstopper, I can do conversions to metric in my API. But the wind direction was plain incorrect. The weather was blowing an easterly but their API was saying it’s a southerly. Bad data = showstopper.

OpenWeatherMap

I had a quick look at OpenWeatherMap’s API and their API has super easy documentation (London current conditions here and 3 hour forecast here) but I couldn’t see hourly data there either.

Met Office

The UK’s own Met Office has numerous APIs over at http://www.metoffice.gov.uk/datapoint.

But bloody hell, it’s hard work trying to figure out which API call to use and how to call it. The “UK daily site specific forecast” was one option – here’s its results for Wandsworth. But that only has the forecast conditions at noon and midnight. All I want to know is what the conditions are now. Where’s that? Ah let’s try the “UK 3-hourly site-specific forecast” (Wandsworth here). Again, it’s 3 hour forecast feed. All I want to know is the conditions right now and for the next hour. I guess that’s as close as I’m going to get though.

Conclusion

I couldn’t find the perfect weather API – only Forecast.IO had a rain prediction for the next hour but their wind direction was incorrect. OpenWeatherMap and Met Office both had 3 hour predictions, but OpenWeatherMap’s documentation is better, their Free account has better terms, and they work worldwide and not UK only so I’m gonna use them.

Winner: OpenWeatherMap

 

Should I cycle: System design

I spent some time on the weekend thinking about Should I Cycle, the app I want to build. There’s two ways I could do it:

  • standalone iPhone app

or

  • build an API
  • iPhone app will call the API

Given the terms of use of most of the weather APIs out there, I wouldn’t be able to call them directly from my iPhone app. So I should build my own API which the iPhone app will call. OK then.

What should my API look like and what will it do? It’ll be pretty simple – when invoked, all it will do is call the other web services it’ll use – weather, air quality, pollen levels, convert the results into a succinct format, and probably cache the results.

Here’s a simple diagram (created using draw.io):

Should I cycle (1)

A custom tool ‘PublicResXFileCodeGenerator’ is associated… compiler warning

If you ever have a compiler warning saying

A custom tool ‘PublicResXFileCodeGenerator’ is associated with file ‘blah’, but the output of the custom tool was not found in the project. You may try re-running the custom tool by right-clicking on the file in the Solution Explorer and choosing Run Custom Tool.image001

To remove the compiler warning you can just remove the Custom Tool by clicking on the Resource file, pressing F4 to bring up the Properties and then removing the entry for Custom Tool. Easy.

image003

App idea: Should I Cycle?

I’ve come up with an idea for an iPhone app which I’m going to implement if I have time. I don’t expect to make any money off this app, and I’m only going to build it for an audience of one – me! But if it works well I’ll see if I can be bothered putting it on the app store.

The app is pretty simple – at a set time each day (i.e. in the morning) it should send me an alert (i.e. a push notification) as to whether I should cycle to work or not.

As a fair weather cyclist, the criteria on whether I should cycle to work or not are:

  • Weather – likelihood of rain in the next hour
  • Weather – wind direction
  • Air quality – pollution levels
  • Air quality – pollen count

additional criteria in the future could be:

  • Traffic conditions (doesn’t really bother me)
  • Tube conditions (i.e. if there’s tube or train delays then you should probably cycle)

Anyway, here’s a mockup of what I want the app to do (using creately.com):

Screen Shot 2014-08-25 at 17.43.15

Creating a slot machine game using VB

Visual Basic may not the best option for coding games, but it’s possible to create them using it. In fact, there are a lot of simple games on the web created using Visual Basic such as slot machines.

Slot machines may have been around for a long time, but they’re still one of the most popular games around the world. Cryptologic, the company that first offered casino gaming services to the public in the 90s through its InterCasino brand, is still in operation, particularly because slot machines are a very lucrative business. Data by the American Gaming Association reveal that electronic gaming machines yield at least 62% of a casino’s annual revenue.

To the developers who think that games can’t be made using Visual Basic, think again. Here’s a simple one posted on Sourcecodester.com by coder Yorkiebar:

Done! It’s a very simply slot game but it works. The window is small, the numbers on the reels aren’t really very appealing, and the user interface is plain at best. However, this should give you the framework on how to create a simple slot machine game using Visual Basic.

This post is a guest post.

Browse a local Azure Web role from another computer

So, you’re developing an Azure website that runs as a web role, which means you use the Azure Compute Emulator when running it locally. And now you want to test or debug that local website in an older browser, such as IE8.

In this situation I have IE8 running on another computer (or maybe a VM), so I need to open up access to my website which is running locally.

Step 1. Find out your IP address – ipconfig. Mine is 10.200.34.201 (NB. I’ve highlighted the wrong field in the screenshot).
image002

Step 2. Find out which IP address and port the compute emulator is running on, by looking in the System Tray at the IIS Express icon. Note that even though I access the website locally on https://127.0.0.2:447 in my browser, it runs on a different IP and port in the emulator, https://127.255.0.4:448. I don’t know/care why.
image001

Step 3. Download and install Pass Port from http://sourceforge.net/projects/pjs-passport/. Yes it’s old but it does the job of forwarding ports nicely, which is what we need to do.

Step 4. Set up a Pass Port port forwarding rule with your IP address and any port (I’m using 800) to the IP address and port of the emulator. N.B. you may need to run PassPort as an Administrator if it doesn’t seem to be working.

image004Step 5. Open up that port (800) in the Windows Firewall:

image003

That should be it. Now you can connect on the remote computer to your Azure Emulator running locally. Obligatory screenshot of my site running in IE8:

image005

Beginner’s guide to add a toolbar to an iOS iPhone app with a Storyboard

I’ve been playing around with iPhone apps a little bit. I’m certainly no expert though, I’m still a beginner myself.

A basic task is to add a toolbar with buttons to your application using XCode.

Lots of samples online are using old versions of XCode. Allow me to demonstrate how to add a toolbar to an app, using XCode 4.2 with Storyboards.

Create a new Project

In Xcode, File -> New Project. Choose Single View Application. I named my application com.mattfrear.toolbars.

Add a toolbar

If you can’t see it, choose View -> Navigators -> Show Project Navigator.

If you can’t see it, choose View -> Utilities -> Show Object Library.

Open the MainStoryboard_iPhone.storyboard. Click on the View.

In the Object Library (which should be in a window at the bottom right of your screen), scroll to the bottom and choose Toolbar. Drag it onto the View. Your screen should look like this:

Screen Shot 2013-08-29 at 16.05.42

Wire up the button

Now we need to add some code which will be fired when the button is clicked.

Open ViewController.m. At the end of the file, before the last @end, paste the following:

-(IBAction) buttonClicked
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello world"
                                                    message:@"You clicked the button"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

This is the code which will execute when the button is clicked, and it will display a simple Hello World popup.

Our final step is to wire up the button to this method. To make this easier we can use the Assistant Editor.

In Xcode, go View -> Assistant Editors on Right. Then View -> Show Assistant Editor.

If your screen is small, you might want to go View -> Utilities -> Hide Utilities.

The Assistant Editor should have ViewController.h open. In the Assistant Editor toolbar at the top, it should say Automatic > ViewController.h > No Selection. In that toolbar, click on ViewController.h and choose ViewController.m from the dropdown.

Screen Shot 2013-08-29 at 16.30.55

In the main window, click on the toolbar we added to our View, then on our “Item” toolbar button. Now right click it to bring up the “Bar Button Item – Item” menu.
Under Sent Actions, next to selector there is a + button. Click that and then drag it to the buttonClicked method in ViewController.m.

Screen Shot 2013-08-29 at 16.34.40 (2)

Hooray! Now our toolbar button is wired up to the method. Let’s run our app to test it.

In XCode’s toolbar, next to the big Run and Stop button you should see a drop down. Choose iPhone Simulator, then click the Run button.

Screen Shot 2013-08-29 at 16.40.16

Woop!