Monday, June 17, 2013

Spartan Race 2013

In the tradition of "pictures or it didn't happen" here are some shots of me and my friends participating in the Spartan Race this past Sunday.

So it begins

Probably the first time I've ever successfully climbed one of those ropes. Amazing what the threat of 30 burpees can do.

Flying Matrix crane fire jump

You're almost done, so guys hit you with sticks

and scene!

Robin and I (pictured above) finished the race in a time of 1:49 which is much longer than I expected to take. However, I think we did pretty well considering the race was done in the pouring rain which made the course slick and muddy. Considering we ran up and down Edelweiss three times I'm thinking 1:49 was a pretty good time.

The race course was advertised as 5km but I've heard it was 6.7 km which makes sense to me. As well each time up/down the mountain was a 200m change in elevation.

Things I learned that are important for Spartan Race competitors:

  1. Cotton fiber underwear is a bad idea. They get soaked and weigh you down. Better to go with lycra biking shorts as they don't absorb quite so much water.
  2. Thiner shoes! I hate to buzz market those Vibram FiveFingers shoes but I can see how they would come in handy in this race. By the time we were heading up the mountain for the 3rd time I believe my shoes and socks gained an extra couple of pounds of water, muck and rocks.
  3. If it is raining I'd go with some gloves as it is pretty tough to grab the rings, monkey bars, etc. when everything is slick with rain.
Anyway, I had a blast and I would definitely do it again. Anna really wants to do one so I'm going to have to look into a kids version for her as she is very, very excited to get full of mud.

Thursday, June 13, 2013

My PhoneGap Presentation to Ottawa JS

So on Wednesday night I did my Introduction to PhoneGap/Apache Cordova (GitHub repo) presentation for Ottawa JS at the beautiful Shopify lounge. I've given this presentation a ton of times so I decided to give it a twist this time around.

The first thing I did was convert my old slide deck into a reveal.js presentation. Then I popped all the assets into a PhoneGap iPad project to see how it looked. Well, reveal.js looks and works great on an iPad.

At this point I started to get fancy. When I got to the part of the presentation where I would usually switch from the presentation software to Eclipse/Xcode to show the code and emulator I decided to call out to PhoneGap to take a picture instead. All I needed to do was include cordova.js in the app and make a call to Camera.getPicture and the results were:


this is my view from the stage


the view from the audience

And Darren took a picture of me taking the picture, while the picture I was taking was being put up on the big screen which is also in this picture. So I was able to do a presentation on PhoneGap in a PhoneGap app calling the PhoneGap API. It got meta pretty damn quick!





Tuesday, June 11, 2013

A Couple of Good Google Apps Scripts

Here are a couple of good Google Apps Scripts I've run into last week. The first script I saw on Lifehacker. It converts a Google Doc to markdown. It is a great way to create a README.md for GitHub. The second is from Pamela Fox which converts a Google Speadsheet to JSON data. Great way to create sample JSON data for your app.

Sunday, June 2, 2013

Why Don't My Plugins Work in PhoneGap Android 2.7?

Well it's pretty simple, the Plugin class which has been deprecated for awhile has been removed from the package and should be replaced with CordovaPlugin.

I'm going to go through the steps needed to upgrade your old style plugins to the new style. For this example I'm going to use the Google Analytics plugin.

The first thing you will notice in 2.7.0+ is that the GoogleAnalyticsTracker class now has 4 errors in Eclipse. To get rid of them you would change:


import org.apache.cordova.api.Plugin;

into:

import org.apache.cordova.api.CordovaPlugin;

and:

public class GoogleAnalyticsTracker extends Plugin {

to:

public class GoogleAnalyticsTracker extends CordovaPlugin {

and now you'll notice you only have one error left in the file and that has to do with the execute method. You'll need to change the method signature from:

public PluginResult execute(String action, JSONArray data, String callbackId) {

to:

public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

then you need to add a new import line at the top of the Java file:


import org.apache.cordova.api.CallbackContext;

and we still have one error which is now the line in which we are returning the PluginResult. That's because the method now expect a boolean to be the return value. To fix this issue you would replace:

return result;

with:

callbackContext.sendPluginResult(result);
return true;

Finally our Java code is free of error messages. Whew, were done but what's with the change to the execute method? Well let's just say there have been improvements in the way the Plugins are handled internally. What you need to know is that when you want to send a result back to the JavaScript side you now have a choice of three methods:

1) callbackContext.sendPluginResult(...)

Use this if you have constructed your own PluginResult and you want to send it to the JavaScript side.

2) callbackContext.error(int | String | JSONObject) 

Skip creating a PluginResult and just invoke the error callback on the JavaScript side sending back an int, a String or a JSONObject as the method payload.

3) callbackContext.success(empty | int | String | JSONObject | JSONArray)

Again, just skip creating the PluginResult and invoke the success callback on the JavaScript side sending back an int, a String, JSONObject or JSONArray as the method payload. If you don't provide any payload the method on the JS side will be executed with no payload.

So that should get you unstuck if you have a Plugin that no longer works for you as of PhoneGap 2.7.0. You should also check out my posts on the GalleryPlugin as shows how to write a Plugin using the new API for JS and Java.

IMPORTANT UPDATE!!!

We've heard your screams of pain and we are putting the Plugin class back for PhoneGap 2.8.1. Go read Joe Bowser's post. The class is back in 2.8.1 and will be in 2.9.0 then gone for good in the 3.0.0 stream!