![]() The book gives Pratchett the opportunity to look back on how the invention and subsequent rollout of steam engine powered railroad. He's able to show how the discovery of this new technology brings people closer together by reducing the physical impediments that were once in place to separate the different races. You can draw a parallel with our own world where the internet is connecting people all over the place. Sadly, this is not Pratchett's best effort. There is a long period in the middle where not too much happens and it could have probably been edited away. As well I'm not quite sure who the antagonist was in the novel. Certainly there was some conflict between the Grags and the rest of the dwarves but that didn't seem to gel quite right for me. Although, I did enjoy the novel. Like most of Pratchett's books there are laugh out loud moments and I really thought the bit where the main steam engine was compared to a goddess of the earth as it embodied all four elements coal = earth, steam = water/air and fire to burn the coal and generate the steam from the water. |
Saturday, November 30, 2013
Books I've Read This Week
Monday, November 25, 2013
Doctor Who Speculation on the 13th Doctor and Beyond
First off if you haven't watched the 50th anniversary special that aired this past Saturday don't read this post as it will spoil major plot points.
Alright, if you are still reading then you must want to hear this. An established part of Dr Who cannon is that Gallifreyan's can regenerate their bodies 12 times which effectively gives them 13 bodies in total. A fact which has been confirmed by Steven Moffat. This was a plot device originally dreamed up in 60's in order to allow the second Doctor, Patrick Troughton, to replace the first played by William Hartnell.
Looking back the following actors have played the Doctor:
Alright, if you are still reading then you must want to hear this. An established part of Dr Who cannon is that Gallifreyan's can regenerate their bodies 12 times which effectively gives them 13 bodies in total. A fact which has been confirmed by Steven Moffat. This was a plot device originally dreamed up in 60's in order to allow the second Doctor, Patrick Troughton, to replace the first played by William Hartnell.
Looking back the following actors have played the Doctor:
- William Hartnell
- Patrick Troughton
- Jon Pertwee
- Tom Baker
- Peter Davison
- Colin Baker
- Sylvester McCoy
- Paul McGann
- Christopher Eccleston
- David Tennant
- Matt Smith
But as we now know there was a Doctor between McGann and Eccleston, the War Doctor played by John Hurt. Plus it has already been announced that Matt Smith is leaving the show and Peter Capaldi will be taking over. So the list actually looks like:
- William Hartnell
- Patrick Troughton
- Jon Pertwee
- Tom Baker
- Peter Davison
- Colin Baker
- Sylvester McCoy
- Paul McGann
- John Hurt
- Christopher Eccleston
- David Tennant
- Matt Smith
- Peter Capaldi
Oh no, we're at 13 Doctor's now. That must mean that Peter Capaldi will be the last actor to ever play the Doctor. Well of course not, they are going to keep making this show until it stops being profitable. During the 50th anniversary show we see John Hurt's Doctor beginning his regeneration but we never see him fully transforming into Christopher Eccleston. Perhaps this is because Christopher Eccleston was unable or unwilling to participate in the special or maybe it's something a little more timey wimey.
Since we had three Doctor's in the same time and space and they were actively messing around with their own timeline (yes, I know they hand wavey explained this away) I'm surmising that an alternative timeline has been created. Now when Doctor number 9 regenerates he doesn't become Christopher Eccleston but instead Peter Capaldi. This means that Capaldi could be Doctor number 10 and they've been able to stave off the question of a 13th Doctor for at least 3 more actors.
8) Paul McGann
9) John Hurt
10) Peter Capaldi
9) John Hurt
10) Peter Capaldi
11) ?
12) ??
13) ???
But wait, what about Matt Smith's Doctor what happens to him? Well, I believe that he is the 13th Doctor. You see David Tennant actually regenerated twice. Once in Journey's End and then again in his last show The End of Time. So that would make his list:
8) Paul McGann
9) John Hurt
10) Christopher Eccleston
9) John Hurt
10) Christopher Eccleston
11) David Tennant
12) David Tennant
13) Matt Smith
So in closing you probably had to be a real Whovian in order to read this post to the end but I believe we'll see a reboot of the Doctor Who franchise with Peter Capaldi stepping in as the new 10th Doctor and Eccleston, Tennant and Smith's Doctors being relegated to an alternative time line.
Sunday, November 24, 2013
Books I've Read This Week
It seem to me to be exactly the sort of story a father would come up with. It actually reminds me of the time my daughter was worried about dragons setting our house on fire to which I quickly replied that she didn't need to worry as we had dragon scale shingles on the house and obviously dragon scale shingles are impervious to dragon fire as it would be silly for a dragon not to be immune to their own breath. Well that story worked as she went to sleep. It wasn't until a few years later where I had to dance around that when we were getting our roof re-shingled. |
Three Things That Tripped Me Up This Week
I've had a pretty productive week at work but here are three things that tripped me up this week. I'm putting them down in blog post format so that I'll remember them and maybe they'll help you as well.
1) Concurrent Modification Exception
So I was working on some code where I needed to loop through a collection of users and remove one when it meets a certain criteria. Which I coded up as:
To get around this problem I ended up doing an old school iteration through the list.
2) Relative Layouts in Android are Slow for Complex Layout
I've been working on a lot of complex layouts for an Android app I'm working on and I was using the RelativeLayout judiciously. One of my dialogs was taking quite awhile to load and doing some profiling I determined it to be the measure method for the RelativeLayout was being called many, many times. Switching to a LinearLayout helped reduce these calls.
Romain Guy recently posted a slide deck on how RelativeLayout's are getting better in Android 4.4 and here is a video or Romain and Adam Powell talking about writing custom Android views.
3) Android's Handling of Images Sucks
It just sucks so hard. I was doing some performance tuning of one of our dialogs and found that about 90% of the time it was taking before being show was loading the three images it was using. Cache those images folks, doesn't matter how small they are.
1) Concurrent Modification Exception
So I was working on some code where I needed to loop through a collection of users and remove one when it meets a certain criteria. Which I coded up as:
ListDo you see the problem? No, neither did I as I wasn't thinking and luckily enough for most of my test runs the user who isAnAss was at the end of the List so the exception wasn't throw. When the isAnAss user was in the middle of the list BOOM! ConcurrentModificationException.users = um.getUsers(); for (User user : users) { if (user.isAnAss()) { users.remove(user); } }
To get around this problem I ended up doing an old school iteration through the list.
Listusers = um.getUsers(); User user = null; for (int i = 0; i < users.size(); i++) { user = users.get(i); if (user.isAnAss()) { users.remove(user); } }
2) Relative Layouts in Android are Slow for Complex Layout
I've been working on a lot of complex layouts for an Android app I'm working on and I was using the RelativeLayout judiciously. One of my dialogs was taking quite awhile to load and doing some profiling I determined it to be the measure method for the RelativeLayout was being called many, many times. Switching to a LinearLayout helped reduce these calls.
Romain Guy recently posted a slide deck on how RelativeLayout's are getting better in Android 4.4 and here is a video or Romain and Adam Powell talking about writing custom Android views.
3) Android's Handling of Images Sucks
It just sucks so hard. I was doing some performance tuning of one of our dialogs and found that about 90% of the time it was taking before being show was loading the three images it was using. Cache those images folks, doesn't matter how small they are.
Monday, November 18, 2013
Books I Read This Week
I really enjoyed this book. It is a super funny work of satire. Wait, is that it? Don't I usually put up two book reviews every week? Well yeah, I do but...well Attack on Titan is all I can say. I got super hooked on that anime this week and it has been eating up all of my spare leisure time. It's not even like I can watch it while doing something else as it is English sub-titles only. |
Monday, November 11, 2013
Jawbone Up Review
So I purchased the Jawbone UP back in July and I think I've had it long enough to have an informed opinion about the band and that would be, it's not quite ready for prime time. If I had the opportunity to do it all over again I wouldn't purchase the UP instead I'd be talking hard look at the Fitbit Force.
While the UP does a good job of tracking physical activity and sleep it has a number of deficiencies that keep me from recommending it. First there is no wireless sync option. Originally, I didn't think that it would bother me but it has become cumbersome to sync the band by plugging the band into my phone's headphone jack but it's become a PITA. Second, there is no external display where you can check your daily activity progress or see what time it is. Third, there is no website for you to track your progress everything has to be done via the phone interface.
Finally, charging is problematic. In order to charge the band you need to connect it's head phone jack connector to a special cable that connects to a USB port. Also, the battery sometimes will not take a charge, I'm on my second band since July and a friend of mine is in the same boat.
All in all, I love the idea of life tracking I just don't think this is the product for me.
While the UP does a good job of tracking physical activity and sleep it has a number of deficiencies that keep me from recommending it. First there is no wireless sync option. Originally, I didn't think that it would bother me but it has become cumbersome to sync the band by plugging the band into my phone's headphone jack but it's become a PITA. Second, there is no external display where you can check your daily activity progress or see what time it is. Third, there is no website for you to track your progress everything has to be done via the phone interface.
Finally, charging is problematic. In order to charge the band you need to connect it's head phone jack connector to a special cable that connects to a USB port. Also, the battery sometimes will not take a charge, I'm on my second band since July and a friend of mine is in the same boat.
All in all, I love the idea of life tracking I just don't think this is the product for me.
Sunday, November 10, 2013
Book I Read This Week
The whole thing has a post-apocalyptic vibe and it is hard to talk about without giving away some big secrets in the book. I really enjoyed the read and would recommend it to anyone who loves sci-fi. |
I was really impressed with the growth of the Elric brothers in the series. What kicked everything off was their attempt to bring their mother back to life but because of the alchemic principle of equivalent exchange they ended up sacrificing part of their bodies without truly bringing the dead back to life. They originally started by somewhat selfishly trying to restore their own bodies only to realize how much they care for other people and their country. |
Monday, November 4, 2013
Books I've Read Last Week
While all this is going on Peter is trying to figure out who the "Faceless Man" is with Inspector Nightingale. |
![]() I'm really, really enjoying this magical detective series but now I have not more left to read. Bwahahah. If you like Butcher's Dresden Files than this one is for you. I'm purposely trying not to say much about them as I'm four books into the series and I figure most of you will be starting with book one. |
Sunday, October 27, 2013
Book's I've Read This Week
I'm really enjoying this magical detective series, so much so I've already read the next two books in this series but more on that next week. If you like Butcher's Dresden Files than this one is for you. |
Battling Boy by Paul Pope is simply amazing. I've read through it multiple times now and I pick up new bits in the story and art every time. The book was written for 12 year old boys but it works on many levels and is definitely an all ages hit. For long time comic book fans you will pick up on the homage to Jack Kirby and his work on titles like Thor and the entire New Gods line. In Battling Boy we have a young god being sent on walk about basically. He needs to grow up and his father sets him a challenge to clean up a world of the monsters that threaten it. During he first challenge we see how new Battling Boy is to his powers and how naive he is. This is a good story about growing up and I can't wait for volume two to be released. |
Friday, October 18, 2013
Books I've Read This Week
Apparently, there is a bit of a controversy surrounding the truthiness of Gladwell's book. Regardless, he's an excellent story teller and this is an entertaining read. |
Friday, October 11, 2013
Books I've Read This Week
That's why I was so intrigued to get and read Confessions of a Public Speaker. I rather enjoyed Mr. Berkun's insights into public speaking. I was also very glad to find out that most people are more afraid of public speaking than death. Actually, that doesn't make much sense but it is a good anecdote. The book is filled with some great stories and a lot of practical advice. The one piece of advice I'm immediately putting into play is to interrupt those folks who ask rambling 5 minute long questions after your talk. I guess the audience is just as disappointed to have to listen to the ramblings of a mad man as I am. However, you can do it politely. Just offer to take the persons super involved query off line and follow up with your email address so they can contact you. There is also some good bits on "what can go wrong" during a talk. It's great to be prepared for problems. For instance, when I walk into a venue to do a talk I usually have my presentation in 3 separate locations, my laptop, a usb stick and Dropbox. So god forbid anything happens to one of them I have a redundant back up ready to go. You might think that sounds a bit excessive but let me refer you back to my PhoneGap Day US talk. My laptop would mirror it's display with the projector so the audience would only be able to see the left half of my presentation. I didn't get freaked out about it, I just jumped on Tommy's laptop and did the presentation out of my Dropbox account. But that was nothing compared to what Kristofer Joseph was able to pull off at September's PhoneGap Paris meetup. Kris was doing some live coding of Topcoat while presenting to a large Parisian crowd. Now that doesn't sound too bad but here is the picture: Now you have to look at the top right hand corner of the picture to see Kris leaning over the railing on the second floor of this busy bar in Paris. He's presenting to the crowd down below while holding a hand mic, while typing on his computer, while a bunch of people sing happy birthday behind him. Yup, I will never complain about a tough presentation setup ever again. |
But then some time passed and I read an interview with Powers and Gaiman where they agreed that it was an odd co-incidence that the books seemed similar but there was no copying going on by either party so I read it again and loved it! This is actually the third time I've read the book as it was the October book in my book club and I must say I thoroughly enjoyed it once again. The book centers on an ex-con named Shadow. He gets out of jail a few days early in order to attend his wife's funeral. Rudderless after the loss of his wife he takes a job for Mr. Wednesday an embodiment of the Norse god Odin. While on the job Shadow criss crosses America with Mr. Wednesday trying to recruit the old gods, the ones immigrants brought to America, in a war against the new gods of America, the Internet, Fame, TV, etc. It is a pretty great treaties on the conflict between spiritual beliefs and the new gods of technology. It does a good job of exploring the question of whether man creates gods or gods create men. Also, it contains quotes from one of my favourite poems, The Second Coming by W.B. Yeats. |
Monday, October 7, 2013
My PhoneGap Day US Talk on Speech Recognition
Back in July I went out to Portland to talk at PhoneGap Day US. The video has just become available so I figured I would post it up here. The talk I did at PhoneGap Day EU is very similar to this one with a bit of updated information and mostly new jokes.
Friday, October 4, 2013
Books I've Read This Week
The closest comparable I can find for this book is the Dresden Files series by Jim Butcher which is a good thing as that is a really fun series. Anyway, PC Peter Grant is just finishing his probationary period and is hoping to become a detective but after standing guard at a grisley murder scene he discovers that he can talk to ghosts. This leads to Peter being assigned to a special division of the London Metro Police that deals with super natural crime. I really enjoyed this book and I'm looking forward to reading the rest of the series. |
Monday, September 30, 2013
Books I Read Last Week
Whoops, sorry was traveling last week and didn't get a chance to pull together a post.
Check out my post from last week to see how I feel about the second book in this series. |
Friday, September 20, 2013
Books I've Read This Week
I always like these Lost Fleet novels. They are like popcorn, quick and enjoyable reads. They are fun for anyone who enjoys military sci-fi. |
Saturday, September 14, 2013
Book's I've Read This Week
The residents of the town have to deal with their loved ones coming back to life. The government quarantining the town to prevent the "possible" infection from spreading. It seems like the government has watched a lot of George Romero movies and that has informed their opinion of what to do. As well the religious calamity arising from the dead walking. This is a really creepy feeling graphic novel and another great work from Seeley and Norton. |
Friday, September 6, 2013
Books I've Read This Week
I enjoyed the book but I did get skived out at one point where the female lead, Caitlin a 15 year old girl, is about to become "sexually active". I'm not sure why it bothered me so much but it may have something to do with that 8 year old daughter I have and wanting to stick my head in the sand. |
The book does a nice job of filling in the background of the man who is so important to the story but I did feel like it stalled the narrative a bit. By the end of the book we are ready for the fight to between Jardir and Arlen Bales. Only one of they can be the Deliverer and it rightly identifies that the world will remain split as you can't have two generals so one of them has to go. |
Wednesday, September 4, 2013
My SpeechShim for Desktop Development of Speech Recognition and TTS Apps
So I've been working on some plugins for PhoneGap to enable people to develop their apps with Speech Recognition and Text to Speech functionality. I've been following this specification and while it isn't on track to be adopted by the W3C anytime soon it does have two big benefits:
1) The speech recognition bit is already available in Chrome.
2) The specification is "sane". I guess it helps when only a couple of people are credited as authors instead of a committee.
One of the things that has been bugging me for awhile is the inability to develop these type of apps on the desktop using the same API. Yes, as I said above the speech rec bit is available in Chrome but the objects have the "webkit" prefix and there is not TTS support. So during one of the Ottawa Ruby project nights I set out to write a shim that would give everyone the ability to use the same API that will be available from the PhoneGap plugins on their desktop.
Basically that is what SpeechShim is in a nutshell. When you add speechshim.js into your web app you will be able to access the "SpeechRecogntion" object instead of needing to prefix it like "webkitSpeechRecognition". As well if you combine it with the speak.js project the speechshim.js code will add the methods necessary so you can use the SpeechSynthesis interface.
To get up and running you will need:
1) The speech recognition bit is already available in Chrome.
2) The specification is "sane". I guess it helps when only a couple of people are credited as authors instead of a committee.
One of the things that has been bugging me for awhile is the inability to develop these type of apps on the desktop using the same API. Yes, as I said above the speech rec bit is available in Chrome but the objects have the "webkit" prefix and there is not TTS support. So during one of the Ottawa Ruby project nights I set out to write a shim that would give everyone the ability to use the same API that will be available from the PhoneGap plugins on their desktop.
Basically that is what SpeechShim is in a nutshell. When you add speechshim.js into your web app you will be able to access the "SpeechRecogntion" object instead of needing to prefix it like "webkitSpeechRecognition". As well if you combine it with the speak.js project the speechshim.js code will add the methods necessary so you can use the SpeechSynthesis interface.
To get up and running you will need:
- A copy of Google Chrome version 29 or higher.
- A copy of the speak.js project from github.
- A copy of my speechshim.js from github.
Here's an example HTML page:
and you can run the live demo here. It's nothing fancy. Just click the big button then say something. It should get updated under the button and you will hear it spoken out by the TTS. More on plugin availability for PhoneGap is coming soon.
Friday, August 30, 2013
Books I've Read This Week
It's an all graphic novel catch up week. Back with sci-fi and fantasy books next week.
![]() |
![]() The story is a confusing mess. JHW3 and Haden Blackman you are not Alan Moore so while I applaud your attempt at telling a cohesive narrative from six different point of view characters while jumping back and forth the timeline I can't really say you did a good job as the whole thing is confusing as hell. Apparently the next volume is set to guest star Wonder Woman and supposedly it is better but I'm not sure I'll shell out the bucks to pick it up in hard cover. |
Oh and more of the break out star, Lying Cat... ![]() Best. Cat. Ever. This is really some great writing and phenomenal art make this book a standout. One of the best things about it is Staples really lets her imagination go wild when drawing the aliens. Think the Star Wars Mos Eisley cantina scene amped up to 11. |
![]() Lemire is on fire here tugging out our heart strings and eliciting a strong emotional response as we see the ultimate fates of characters we've been following for years. I strongly recommend this whole series to anyone. |
Friday, August 23, 2013
Books I've Read This Week
This is a fantastic grim and gritty fantasy series. There are a lot of memorable characters in these books including a couple of my favourites the northern beserker Logan Ninefingers and Inquisitor Glotka. None of the characters that you encounter in these novels are purely altruistic or purely evil. The first book starts off with the Magus Bayaz putting together a group of adventurers to go off on a quest including Logan Ninefingers, the vain fencer Jezal dan Luthar among others. While this sounds like a typical fantasy setup Abercrombie eschews the normal traps of epic fantasy. The three books are a long read but well worth it especially if you like you fantasy novels to be more like George R R Martin instead of J R R Tolkien. |
Sunday, August 18, 2013
Books I've Read This Week
It's got a creepy faerie tale vibe, combined with the exploration of youthful memories. It is really worth the read even if it is only a short book weighing in under 200 pages. |
Friday, August 9, 2013
Books I've Read This Week
![]() |
Friday, August 2, 2013
Books I've Read this Week
Whoops, haven't done one of these in awhile but that doesn't mean I haven't been reading.
Thursday, July 25, 2013
PhoneGap Day US 2013 Recap
Why, weren't you there? Seriously, what's stopped you? This conference is so great and so cheap that if you are anywhere near Portland, Oregon you need to go. Even if you aren't near Portland you need to convince your boss to send you to the conference.
What's the number one reason to attend PhoneGap Day? Timing, no wait the community. The community really comes out for this conference. I can't think of another conference I've attended where you can meet so many committers. If you were there you could have met all those people you see fixing bugs on JIRA and checking code into GIT.
Beyond the committers there were lots of folks who are building real applications with PhoneGap and they are there for you to talk with, network and generally pick their brains.
There were a lot of great presentations this year but if I was going to single out three they'd be Andy Trice's PhoneGap+Hardware, Michael Brooks super slick PhoneGap Command Line demo/presentation (I only wish I was that smooth) and finally Lyza Danger Gardner's deck on PhoneGap Self-Defense for Web Devs. That one was jam packed with things web devs should know before diving into PhoneGap.
I was sweating my talk a bit before heading up on stage. I was about to give a speech recognition demo on a stage in front of 250 people. There were so many things that could have gone wrong like the (network, crowd volume) and one thing did. For some reason my MBP would not mirror the displays so either I could see the presentation or the audience could. Luckily, as a former boy scout, I was prepared. I was hosting my presentation on Dropbox so I was able to slide over to Tommy-Carlos Williams laptop to do my demo without holding up the show. Thanks again Tommy!
Sacrificing my laptop to the demo gods seemed to appease them and the rest of my presentation went off pretty well with only one unintentionally funny moment. People seemed to have liked it which I was happy about. You can download a PDF version of the presentation but it plays much better as a live demo.
All of these presentation videos will be available soon. In fact when mine is up I'll be posting it here. As well I'm lagging behind posting my source code but I'm kinda busy with some other commitments I'll talk about on a later date.
Beyond catching up with all of the other PhoneGap committers it was a great conference for meeting folks I internet knew, In Real Life. Besides the afore mentioned Tommy-Carlos Williams who shocked me by not having an Australian accent, he is USA born, I got to meet my co-worker Marcel Kinard for the first time. Both Marcel and I work at IBM where he is managing IBM's contributions to the PhoneGap/Cordova code base. Finally I got to know Jim Cowart of Icenium pretty well over the conference. Jim's done a great write up of the conference himself.
Honestly, I will carry to my grave the memory of the taste of Griddled Bacon Wrapped Date with warm honey from Tora Bravo. Jim, Marcel, Burin and I went there after the first day of the conference and we were all blown away with how good the food was. I guess it is not a secret but Portland is a great city for foodies.
Finally I will leave you with this over the shoulder video of me playing Galaga at Ground Kontrol the amazing barcade (bar + arcade) courtesy of Jim.
What's the number one reason to attend PhoneGap Day? Timing, no wait the community. The community really comes out for this conference. I can't think of another conference I've attended where you can meet so many committers. If you were there you could have met all those people you see fixing bugs on JIRA and checking code into GIT.
Beyond the committers there were lots of folks who are building real applications with PhoneGap and they are there for you to talk with, network and generally pick their brains.
There were a lot of great presentations this year but if I was going to single out three they'd be Andy Trice's PhoneGap+Hardware, Michael Brooks super slick PhoneGap Command Line demo/presentation (I only wish I was that smooth) and finally Lyza Danger Gardner's deck on PhoneGap Self-Defense for Web Devs. That one was jam packed with things web devs should know before diving into PhoneGap.
I was sweating my talk a bit before heading up on stage. I was about to give a speech recognition demo on a stage in front of 250 people. There were so many things that could have gone wrong like the (network, crowd volume) and one thing did. For some reason my MBP would not mirror the displays so either I could see the presentation or the audience could. Luckily, as a former boy scout, I was prepared. I was hosting my presentation on Dropbox so I was able to slide over to Tommy-Carlos Williams laptop to do my demo without holding up the show. Thanks again Tommy!
Sacrificing my laptop to the demo gods seemed to appease them and the rest of my presentation went off pretty well with only one unintentionally funny moment. People seemed to have liked it which I was happy about. You can download a PDF version of the presentation but it plays much better as a live demo.
All of these presentation videos will be available soon. In fact when mine is up I'll be posting it here. As well I'm lagging behind posting my source code but I'm kinda busy with some other commitments I'll talk about on a later date.
Beyond catching up with all of the other PhoneGap committers it was a great conference for meeting folks I internet knew, In Real Life. Besides the afore mentioned Tommy-Carlos Williams who shocked me by not having an Australian accent, he is USA born, I got to meet my co-worker Marcel Kinard for the first time. Both Marcel and I work at IBM where he is managing IBM's contributions to the PhoneGap/Cordova code base. Finally I got to know Jim Cowart of Icenium pretty well over the conference. Jim's done a great write up of the conference himself.
Honestly, I will carry to my grave the memory of the taste of Griddled Bacon Wrapped Date with warm honey from Tora Bravo. Jim, Marcel, Burin and I went there after the first day of the conference and we were all blown away with how good the food was. I guess it is not a secret but Portland is a great city for foodies.
Finally I will leave you with this over the shoulder video of me playing Galaga at Ground Kontrol the amazing barcade (bar + arcade) courtesy of Jim.
Wednesday, July 3, 2013
Backup, Remove and Restore your Contacts using PhoneGap
A couple of people have had questions on how to do this recently so I thought I would do a write up on it. As well, it illustrates how you avoid using loops with asynchronous code. Although for an even better explanation of that topic you'll want to read Item 64: Use Recursion for Asynchronous Loops from David Herman's book, Effective JavaScript. Chapter 7 on Concurrency is worth the purchase price of the book but I digress...
First a warning. Try all the code out on an emulator first. The methods below will completely wipe the contacts from your device so you'll want to make sure the backup step works first before continuing. You've been warned!
Anyway, if you want to backup the contacts on your device to a file you'd use the following process:
Next we will delete all the contacts on the device. The steps are:
This might look a little bit weird at first glance but trust me it'll make sense. You'll notice in deleteAllTheContacts the first thing we do is to create a local function called deleteContacts. This is the method that will actually remove the contacts from the device. Then after the definition of deleteContacts we call navigator.contacts.find(). This call will get an array of all the contacts on the device and call it's success function which is deleteContacts.
Now in deleteContacts we do a check to see if the length of the contacts array is zero. If it is zero then we are done, there are no more contacts left to be deleted. If the contact array length is greater than zero we have more work to do. We'll pop the next Contact object off of the contacts array, which reduces the size of the array by one and we'll call the remove method of the Contact object. The success call back for remove method is the deleteContacts method. Keep reading this paragraph until all of your contacts have been deleted. Boom recursion.
But wait, you are wondering how could this possibly work. Your thinking I've got 7 quintillion contacts and there is no way the call stack can support that many recursive calls. Ah, but you are forgetting that asynchronous calls return immediately so they never eat up the call stack. If you tried doing this with a for loop you would blow up the call stack causing your program to crash if you had enough contacts and even if you didn't kill your app how would you know when all of those async calls to remove were complete without doing a lot of JavaScript gymnastics. Just use the recursion approach.
Finally you'll want to be able to restore the contacts you've previously saved to file. I've broken it down into two separate methods to make it easier to read:
This is pretty much just unrolling the two previous steps of backing up and deleting the contacts. If you've gotten this far you should be able to understand what is going on. Although there are two lines I want to draw your attention to:
First a warning. Try all the code out on an emulator first. The methods below will completely wipe the contacts from your device so you'll want to make sure the backup step works first before continuing. You've been warned!
Anyway, if you want to backup the contacts on your device to a file you'd use the following process:
- Find all the contacts
- Request a file system object
- Create a FileEntry object
- Create a FileWriter
- Write the JSON data to file
Next we will delete all the contacts on the device. The steps are:
- Find all the contacts
- Recurse through the contacts deleting one at a time.
The code looks like:
This might look a little bit weird at first glance but trust me it'll make sense. You'll notice in deleteAllTheContacts the first thing we do is to create a local function called deleteContacts. This is the method that will actually remove the contacts from the device. Then after the definition of deleteContacts we call navigator.contacts.find(). This call will get an array of all the contacts on the device and call it's success function which is deleteContacts.
Now in deleteContacts we do a check to see if the length of the contacts array is zero. If it is zero then we are done, there are no more contacts left to be deleted. If the contact array length is greater than zero we have more work to do. We'll pop the next Contact object off of the contacts array, which reduces the size of the array by one and we'll call the remove method of the Contact object. The success call back for remove method is the deleteContacts method. Keep reading this paragraph until all of your contacts have been deleted. Boom recursion.
But wait, you are wondering how could this possibly work. Your thinking I've got 7 quintillion contacts and there is no way the call stack can support that many recursive calls. Ah, but you are forgetting that asynchronous calls return immediately so they never eat up the call stack. If you tried doing this with a for loop you would blow up the call stack causing your program to crash if you had enough contacts and even if you didn't kill your app how would you know when all of those async calls to remove were complete without doing a lot of JavaScript gymnastics. Just use the recursion approach.
Finally you'll want to be able to restore the contacts you've previously saved to file. I've broken it down into two separate methods to make it easier to read:
- Request local file system
- Get the FileEntry
- Request the File object
- Read the data and parse it to JSON
- Recurse through all the contacts and save them to the device
This is pretty much just unrolling the two previous steps of backing up and deleting the contacts. If you've gotten this far you should be able to understand what is going on. Although there are two lines I want to draw your attention to:
contactData.id = null;What I'm doing here is removing the unique ID's from the contact. If you skip this step you will signal the API that you are attempting to modify an existing contact and the save will most probably fail. Hopefully this helps a bunch of folks.
contactData.rawId = null;
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.
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:
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:
- 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.
- 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.
- 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.
Subscribe to:
Posts (Atom)