Android Automation

In my last post about releasing for android, I had a long list of commands that you had to run, to finally create a releasable apk file. It looked something like this:

Here's how I created 20,000 fake contacts on the iPhone

I needed to get a large number of fake contacts onto an iPhone recently for testing purposes, but I couldn't find any example data that I could download. So here's what I did to create it.

Remote Debugging in Phonegap with Chrome Devtools

The requirements are:

How to Get Phonegap Working on Mac OS X Mavericks

After I upgraded from Mountain Lion to Mavericks, all of a sudden, phonegap wasn't working anymore.

How to Precompile Handlebars Templates

First you need to install handlebars with node by running this command. If you don't have node, go ahead and install it first. It's really quick and painless.

npm -g install handlebars

Then put all of your handlebars templates inside js/templates with the extension handlebars. So for example a file named booksList.handlebars would be the booksList template. Inside these files you don't need the script tag that you would normally need if you included the template inside your html page. So instead of this:

<script id="booksList" type="text/x-handlebars-template">
    {{#each books}}

It would just look like this:

  {{#each books}}

Then with all of your templates in that folder, open up the command prompt, navigate to the folder right above the js folder. The reason you don't want to navigate into the js folder is because you're going to run the handlebars command, and if you're in the js folder, it will think you meant to run the javascript file. Then run the handlebars command which will take all of those templates and combine them into one file named tamplates.js. The -m option means that it will minify the file.

handlebars -m js/templates/> js/templates/templates.js

Then in your html, all you have to include is that one file plus handlebars:

<script src="js/handlebars.js"></script>
<script src="js/templates/templates.js"></script>

And when you need to use a template in your javascript, it works the same way as before except that instead of having to compile your template like this:

var source   = $("#booksList").html();
var template = Handlebars.compile(source);

You can now just use it like this:

var template = Handlebars.templates['booksList'];

And you don't have to include the entire javascript library. All you need is the runtime version.