Had the wonderful opportunity to attend TiAppCamp 2013
in Atlanta, GA. I had a wonderful time and learned a lot about the platform I
use at work to make really cool things happen on mobile phones. While there I
had time to take some interesting pictures.
The hotel I stayed at was The Hotel Indigo which is right next to The Fox
Theatre. The theme was all the tickets from people who were fans of The Fox
Theatre. The from lobby was quite impressive and I tried my best to capture it
in this panorama:
I had a little fun with some shots outside. The “Ghosts at the theatre” image
was a tone mapped HDR (High Dynamic Range) Photo constructed my layering
multiple shots with different exposures on top of each other:
I ran into an interesting problem while trying to internationalize a
Titanium application. The recommended way to do so is to use String.format
to interpolate the localized string you grabbed from the L() method. Here is
This was all well and good till some problems presented themselves. If I
passed in a null reference the application would crash! And if I passed
in a non string I would get “null” instead regardless of value. The
String.format used the printf specifications which means the string had to
be aware of both order and type of the values. Either translators needed to
understand variable typing ("%s strings and %d numbers") or I had to convert
all values to strings (String.format("%s", "" + number_value)). Out of order
translations were very cryptic ("out %2$s of order %1$s strings") and the
translator looses context of what they want to translate.
With all these problems I ventured on a quest to find a better alternative. And
I found one. A very simple solution that you can implement today! Follow me on
the journey while I recount my quest and how I found the best solution I know
or L("message_id", "Default text") for short. There was an example when this
format served a hindrance:
Sample titanium i18n usage (sample.js)
hintText:"e.g. 123 Washington Rd. (required)"
hintText:"e.g. firstname.lastname@example.org (required)"
hintText:"e.g. (123) 555-5555 (optional)"
The above asked to localize three strings that were not easily
internationalize-able (e.g. ?) and all of them looked fairly close in concept.
Using string interpolation would be a mess and would still require many message
Sample titanium i18n usage with string interpolation (sample_bad.js)
"%s %s (%s)",
L("example_address","123 Washington Rd."),
I’ll be honest, "%s %s (%s)" looks confusing as hell.
I’m going to show you how I handled this using Underscore’s template engine.
I’ll explain the process progressively so you can see how I ened up with the
cool trick I did. And why I mentioned you should check this out.
I have been working on a lot of Titanium work and on the way I’ve learned a
lot of little tricks. One of which is that you can not use Titanium objects like
will leak memory if your not careful to remove your event listeners. And it will
also double up on events if your not careful. Personally I like the event model
but when my object goes for garbage collection I don’t want to worry did I
remove any left over events?.
I want to discuss my solution to this by showing a neat trick to roll your own
event dispatcher that is object oriented and scoped to your own object. Oh and
it is pretty simple.
objects. As it turns out you can fake this using closures and some tracking
code. I’m going to illustrate this using CoffeeScript.
My last post about making a quick and dirty URL shortener turned out to be
an amazing learning experience in more then just the code. (See this post
to read about the project). I learned how to handle events on objects, Promises
(handling sane asynchronous code) and the value of TDD based development. I’d
like to talk about each and I’ll start in reverse order. But because this is a
lot to go over Ill split it between three posts. (Also because I find the
TL;DR concept (in a blog) a little confusing).
TDD stands for Test Driven Development. What this means is that you focus a good
portion of your development on the test the computer would run to verify your
actual code is working. Phew that was defiantly TL;DR. Ok basically you define
the proper way a piece of code should work using a specifically styled API.
The reason this became so important is that it provided me a much better idea
behind what I actually wanted to accomplish. It showed ways that my code could
work, ways it should not work, and helped hunt down many issues. Although the
lead up was quite steep it was worth it.
I used Jasmine as my test environment and you can see running here.
Feel free to comment for questions. Here is the code used to test:
They say tools are built out of necessity. The trouble is who’s necessity?
In my case I wanted to have a URL Shortener service on my domain. The
problem with that is my website is a static site based off of Octopress
(based on Jekyll). The problem was how do I create a URL Shortener but have
This article steps through the trials and solution I developed for just such a
problem. To see the finished code visit this gist. It was written in
the (sometimes misunderstood) generated code.
This is an exercise of understanding. To do this properly take a look at
hem or browserify. It takes care of this automatically.
into on master file that you can easily load in the browser. It uses the
CommonJS conventions to modularize the code.
I preferred this method because it used one file for many modules. Unlike the
RequireJS way which uses multiple connections to the server to load each
module by itself. Both solutions need wrappings. However, the Stitch way is to
add thenm in one file which allso allow you to prepend libaries that are
not modules unlike ReqireJS which need libraries to be wrapped to handle
I realize this doesn’t make much sense without examples which I’ll get to. The
intent of this post is to offer a compromise solution. This is because I wanted
to load CommonJS modules inside of jsbin and
jsfiddle which use that “one script to rule them all”
methodology. And I’ll explain a possible solution.
DISCLAIMER: Using promises is a much better way to handle asynchronous
situations. Use the advice in this post only as a last resort.
The term “Pyramid of Doom” was coined (as far as I know) from the
function as a callback argument. A common yet ugly style to code this is using
Although these are quick and easy they can really get over complicated producing
a ever increasing indent to the code. This has the effect of making a pyramid
like shape out of the whitespace when you turn it on it side:
One of the great things about CoffeeScript is that it compiles into
often attempt to address it using CoffeeScript in an Object Oriented way so
Object Oriented Programming. So I though I would share those insights here.
Well because I haven’t seen many posts that walk through this in an incremented
by example form. I have to address that there is a much more detailed
explanation in this article and this article. Oh, and lets not forget
gained a ton of understanding but remembering how to implement the concepts and
the best practise on form and style is still left to be desired.
Giving myself a walk through my understanding with the style that I found
delightful from CoffeeScripts’ translations.