Friday, August 31, 2012

Books I've Read This Week

Finishing off the series with Percy Jackson and the Olympians, Book Four: The Battle of the Labyrinth and Percy Jackson and the Olympians, Book Five: The Last Olympian by Rick Riordan. In the fourth book we hear get to hear a lot about a couple of my favourite myths surrounding Daedalus. Including Icarus and the Labyrinth. Then in the fifth book we get the climatic final battle between the demi-gods and the titans for all of Olympus.  

To repeat what I said last week I like the series because it teaches kids about Greek mythology and quite a bit American geography. So if you have kids in the range of 10-15 who need something to read that is enjoyable but sneaks in some facts as well this series is a good choice.

Tuesday, August 28, 2012

Too Much Security!

Occasionally I help out a local non-profit organization with computer problems. I'm not writing this post to toot my own horn as it were but rather to try and save other sometime if they run into the same situation.

Basically, I got a call from the non-profit that one of their computers could no longer connect to the internet. They get on the internet by using one of those Bell Turbo Sticks. Remembering a previous issue where McAfee updated the firewall and a new exception had to be put in the firewall rules the first thing I tried was turn off the firewall and attempting to connect to the internet. No dice, still no connection.

This led me to a number of other debugging steps:

  1. I tried turning it on and off again.
  2. I uninstalled the turbo stick software rebooted and reinstalled.
  3. I grabbed the latest software from another computer and updated the turbo stick.
  4. I tried the turbo stick in another computer and it worked. What? Wait!
So that meant that there was something wrong with this particular computer and not the turbo stick. I then checked and discovered that McAfee updated it's software on the same day the computer started having problems. I know correlation does not imply causation but it sure did waggle it's eyebrows at me. 

So I started trying other stuff like:
  1. Added another exception in the firewall for the tubo stick software.
  2. Leaving the firewall on but turning the security to its most permissive.
  3. Stopping the firewall altogether.
  4. Stopping the firewall, telling it not to restart, the rebooting the computer.
  5. Getting fed up and un-installing all of McAfee. 
Then I was able to connect to the internet! Apparently, there is some horrible bug, maybe they call it a security feature, that even when you disable the firewall it keeps rejecting connections for you. So my original hunch looks like it was correct all along and I would have wished I'd uninstalled the software a couple of hours earlier.

Needless to say we are going to go with another anti-virus software provider for the non profit. It's not a big deal as the renewal for McAfee was coming due in 45 days but they are certainly not getting our money now.

Although, I have to hand it to Bell for once. I called their help line and a technician was very helpful and patient as we tried to figure things out. So thanks nameless person on 310-BELL.

Monday, August 27, 2012

Getting the Android Emulator to Look Right on your Retina MacBook Pro

If you are lucky enough to have gotten a MacBook Pro with a Retina screen you may have run into a problem with the Android emulator. As you can see below the emulator is squished into the top left quarter of the window. Don't worry Google already knows about this problem and a fix is expected in version 21 of the Android Developer Tools. However, you should still go star it to make sure it gets fixed.

The workaround is to install a tool like SetResX or SwitchResX and setup your screen to be one of the non HiDPI modes. I'm currently using SwitchResX to good results:

Update: SDK/ADT 21 has fixed the issue. Although SwitchResX is still a tool worth downloading.

Friday, August 24, 2012

Books I've Read This Week

The Apocalypse Codex is the latest book in the Laundry Files series by Charles Stross. For those of you not familiar with the Laundry Files it focuses on Bob Howard who starts off as a low level sys admin in a British government agency that protects the world from other dimensional horrors. It is a really great mash up of Lovecraftian horror, spy novels and an IT department. In the latest instalment Bob had to work with some outside contractors to stop an American preacher from taking over the world.

For me this novel works on many levels. First is is funny as hell while still keeping that creepy Lovecraft vibe. There is a particularly difficult scene where Bob and his wife have to congratulate friends of theirs who are now expecting their first baby. Since Bob and his wife both work for the Laundry and are aware of the extra dimensional horrors that are constantly trying to get at the human race they've decided not to have kids. This sends reverberations through my own life as I have a number of friends who are married and decided not to have kids because they don't like where the world is headed with global warming, etc.

The novel is also pretty great if you've ever worked for the government or a really big company. The red tape that Bob needs to cut through in order to do his job will be familiar to many folks. The bit where Bob needs to work with external contractors is spot on for any of us who've had to employ contractors.

Go read all the books in the series.
Percy Jackson #3 - The Titan's Curse by Rick Riordan is a young adult series I started reading after I had finished Harry Potter as I wanted to explore more in the genre. I finished the second book quite awhile ago and have recently decided to plow through the last three books in the series as I hate not knowing the end of the story.

I like the series because it teaches kids about Greek mythology and quite a bit American geography. So if you have kids in the range of 10-15 who need something to read that is enjoyable but sneaks in some facts as well this series is a good choice.

In this book Artemis has been kidnapped and it is up to Percy and his fellow half-bloods to rescue her and foil the titan Kronos from taking over the world. Mwahahahaha! 

Wednesday, August 22, 2012

So You Wanna Write a PhoneGap 2.0.0 Android Plugin?

So you are busily beavering away on your mobile app using PhoneGap. Unfortunately, you've run into a roadblock as you want to do something that the OS will allow you to do but PhoneGap does not provide and API for it. Pop quiz hotshot. What do you do? WHAT DO YOU DO? Well obviously the answer is to write a plugin. I mean, the answer is right there in the title of the post. If you didn't figure it out yourself, then I fear for you.

Well let's get into writing a plugin. Before jumping in writing code we need to have some idea of what our requirements are. Hmmm...let's think of something that will be easy but still require the native side to return success or failure to the JavaScript side. I know, let's get the IP address of our device. If we have an IP address our success callback should be executed with the string value that represents the IP address. If we don't have an IP address the error callback should be executed. Sound good? Great, let's dig in.

First, let's think of our JavaScript code and let's write it the fancy new way that uses the PhoneGap version of define and require. Here read the whole thing then I'll explain it more after the break:

The first thing you will notice is that whole thing is wrapped with a call to cordova.define(). The first argument to define is id of your plugin and the second is the factory method that creates your plugin. Next you'll see the curious line:
var exec = require("cordova/exec");
What is happening here is that we are using the require function to define a local variable called exec, pulling it from the "cordova/exec" id. This is really important as the exec method is the magic part of PhoneGap. It's the bit that handles the communication between the JavaScript and native layer. This really is the value add of PhoneGap as we've already found all the bugs that someone starting from scratch would run into.

The next bits are where we declare our constructors for IPAddress and IPAddressError. You really don't need to define the IPAddressError object for this short example but it is a good practice to get into. Actually in this example I won't even return an IPAddressError object from the native side as I'll leave that as an exercise for the readers. First person to post a solution wins a cookie.

Okay, our IPAddress object will provide one method called get which will, drumroll please, get the IP Address of your device. Again nothing magical here other than the call to exec. The method signature of exec is as follows:

success - your success callback
fail - your error callback
service - your Plugin service name. You'll need this later.
method - the native method to be called
params - a JSON Array of parameters that you can pass to the native side

Finally the last interesting bit is where we create our ipAddress object and export it using modules.export.

Alright so now we have our JavaScript code done so let's do some Java:

Beautiful eh? Well maybe not. Anyway, when writing your Java code you just need to make sure you class extends the org.apache.cordova.api.Plugin class. The only method you need to implement is the exec method. In exec you check to see what action has been called and they execute the proper native code to fullfil the request. If the action does not match anything you have implemented then you want to return a PluginResult with a status of invalid action. This will let the caller know they are attempt to execute a method that is not implemented.

In our example we only have one action, "get". If the "get" method has been requested we will call the getIpAddress method to retrieve the device's IP address. The implementation details are not important you can see them yourself. What is important is if we get a null or zero length string we will return a PluginResult with a status of error. This will cause the error callback of our JavaScript code to be executed. If we do have and IP address we will return a PluginResult with a status of success and we'll also return the IP address. This will cause our JavaScript success callback to be executed with the ip address as the only parameter to the function.

So all the code is done so we are ready to call our plugin from our app right? Well not quite there is one more step. You need to add a plugin line to your res/xml/config.xml file. The line follows the format:

<plugin name="service_name" value="full_name_including_namespace"/>

It is important that the service_name matches the service name you provide as part of the exec command. The full_name_including_namespace must be the full package and class name of our Plugin. In our specific case it would be:

<plugin name="ipAddress" value="org.apache.cordova.plugins.IPAddressPlugin"/>

Now let's look at the HTML code of our example. It will create and call get on our IP address plugin.

Again, there are a few steps to follow before you use your plugin.
  1. Register an onload event handler.
  2. In your onload event handler register an event handler for the deviceready event.
  3. In your deviceready event handler you are ready to begin calling PhoneGap method.
  4. Create and ipAddress using cordova.require("cordova/plugin/ipaddress"). The string passed to require must match the one you provided in the earlier cordova.define() method.
  5. Call the get method on your ipAddress object.
So, that's it. You've built a working plugin from the ground up and it will even get your devices IP address.

Friday, August 17, 2012

Books I've Read This Week

Hulk Season One is the latest in the (now defunct?) line of Season One books from Marvel Comics. The book is written by the always funny Fred Van Lente and art duties are handled by local Ottawa boy, Tom Folwer. I was lucky enough to be able to pop down to the Silver Snail this week where Tom was doing a book signing. So my copy of the book includes an illustration of the Hulk looking like his anger is about to boil over. It really is these extra bits that make me continue to buy physical books instead of going totally over to eBooks.

So let me get into the book a bit more. First the good. Van Lente's writing is at times hilarious. This man really knows how to interject comedy into a story. If you've read his Action Philosophers or his long run on The Incredible Hercules you'll know what I mean. However, it isn't all fun and games. Van Lente gives us a real reason as to why the Hulk's alter ego, Bruce Banner, is such a weakling with repressed rage issues. I thought this was a great portrayal of both sides of the Hulk's persona. Also, the book has a beginning, middle and end so you feel like you are getting a full story. Honestly, that is one of the main reasons I rarely get monthly comic books anymore as you don't get much story anymore.

Although you can't have a great comic without great art to go along with it and Folwer really delivers. This isn't the dumb mindless Hulk that many comic book readers are used to. Tom really brings a very expressive emotional Hulk to the page. You can see a number of panels where you can tell the emotion of the Hulk without needing any words as he goes from anger, pain, rage to cold calculating fury. Check out some of the in progress pictures Tom posted. If you are not familiar with some of Tom's work then you really need to check out Mysterius the Unfathomable by himself and Jeff Parker or some of Tom's recent work on Deadpool or Venom.

Now onto the bad and it's not anything I can pin on the creative team rather it is all on Marvel Comics themselves. First at $28 CDN for 136 pages of story the price is a bit high. Especially when you consider at least 20 of those pages are from a reprint of the recent Incredible Hulk series that Marvel published and is about to reboot anyway. Now I paid $21 for my copy with the discount the Snail was able to provide and as I said I got an illustration on the inside cover so I feel like I got a real deal.

Also, the book is shrink wrapped to protect the digital download code that comes with the book. I thought the point of Season One books were to pull in new readers. Don't you think they'd like to flip through the book first? Also, maybe the price could've been a bit lower without the download code. Maybe, I don't know I'm not in marketing but that just seemed dumb to me.

Anyway, I don't want to end on a down note as I really enjoyed the book. If you saw the Avengers this year and wanted to get a better idea of where the Hulk is coming from than this is a good book for you to pick up. It's filled with good story and great art.

Friday, August 10, 2012

Books I've Read This Week

Quiet by Susan Cain is a great book for anyone who is an introvert (I am) or is the parent of an introvert. She does a wonderful job of of explaining the difference between introverts and extroverts. You know, it is an extrovert world out there but there are a lot of things, including computers, that would not be possible without us crazy focused introverts.

Here is a link to her Ted talk.
The Gift of Fire / On the Head of a Pin by Walter Mosley is a collection of two short stories. The first story, The Gift of Fire, is a modern retelling of the story of Prometheus and I quite enjoyed it. The second, On the Head of a Pin, was a miss for me. This book is a definite library pickup not a buy recommendation.

Wednesday, August 8, 2012

Formspring Account for PhoneGap Questions

Hey all,

I've been off on vacation for a bit and I'm struggling to catch up on the comments to this blog. The commenting features of blogger are actually pretty poor. Just wanted to let you know that I will get to them soon.

Also, as part of being able to react to things better if you have a question for me you should post it on my newly created Formspring account. I think this forum will offer a much better way for us to interact. If someone posts a really interesting question that leads to some coding I will end up posting it back here at the blog. Obviously, I'll be focusing on PhoneGap/Cordova questions but if you want to ask about comic books and coffee that'd be great too.



Wednesday, August 1, 2012

Locks of Love

This is a picture of my daughter with approximately 10 inches of hair that she is donating via Beautiful Lengths to people who are suffering from cancer and would like wigs to be made for them. Anna orginally came up with the idea on her own while seeing an ad on TV that explained the process. She wouldn't let anyone cut her hair for the past two years so it would get long enough to donate.

The entire family, parents and grandparents included could not be more proud of her. I know I'm her Dad but I'm incredibly impressed with compassion for others. Obviously, her mother is doing something right :)