Notes from first project using Backbone Marionette

I really enjoy using Backbone.Marionette.

I was recently tasked with a pretty exciting opportunity at work: build a cross platform mobile web app. This project has been (still is) incredibly challenging for me because I’ve never built anything like this before. It’s probably the most complex JavaScript I’ve ever written and I was able to build a reasonably decent app from the ground up thanks to a few technologies and frameworks that made my life infinitely easier:

  • Backbone.js framework
  • Backbone.Marionette framework
  • Jade javascript templates
  • (Iced) CoffeeScript
  • Stylus CSS
  • jQuery Mobile
  • jQuery + underscore (prereqs anyway)
  • Mobile Boiler Plate
  • Modernizr
  • cdnjs (This has almost all of the above libraries on a CDN! Free! Magnificent.)
  • a handful of utilities (makefiles, etc.) that our build engineer created in-house to package things up real nicely.

Figuring out how to use Backbone and Marionette took a long time for me to grasp but now that I’m comfortable using them I feel like I have the tools and skills necessary to build some cool stuff in the future. Maybe not GMail in complexity nor 8-bit Nintendo Emulator coolness but give me an API and some time, I’ll be able to whip up something that could be pretty neat.

 

Important Resources that helped me understand Marionette

These tutorials and code samples helped me the most when trying to pick up a new framework. I don’t watch a lot of screencasts because they tend to be really slow and I can’t copy-paste the code samples.

Tutorial: a full Backbone.Marionette application – is the first tutorial that I found that actually helped me wrap my head around Marionette. The code is easy to read and well explained. Downside — the structure and style are slightly different from the patterns that Derrick Bailey, creator of Marionette,  uses in his examples. The tutorial is slightly old and does not take advantage of newer features that have been added to Marionette (for instance, AMD-style loading). Nevertheless, this tutorial is what got me used to the basic elements of Marionette. Mr. Bailey’s blogs regarding Marionette are well written but they only started to make sense after 1-2 days of staring at this tutorial first.

Addy Osmani’s TodoMVC implemented in Marionette – A useful example of how to use Marionette but I find the JavaScript AMD code extremely hard to follow because all the code is spread around in different files. The order in which the various modules get included on the page matter.

Stack Overflow questions answered by Derrick Bailey – Back to Mr. Bailey… he is active/proactive in Stack Overflow and he often provides insightful answers and comments to many of the questions about backbone.marionette. It will benefit you to look beyond the big green check “Accepted Answer” blocks to seek out Mr. Bailey’s comments in any S.O. thread.

Backbone Marionette Docs in Github – the documentation is extensive and well written. The problem is that there are so many modules available to use it’s hard to know where to get started. In my first non-trivial Marionette app I only used half of the modules in my code (some of the modules are base classes but I didn’t specifically call them). The Marionette components that I used:

  • Marionette.ItemView
  • Marionette.CompositeView
  • Marionette.Layout
  • Marionette.Region
  • Marionette.AppRouter
  • Marionette.Application.Module
  • Marionette.Application — just 1 instance but it provides the foundation for everything else.
  • Backbone.View — I was easily able to adapt a View I had written before to work fine with Marionette. It would be possible to break my View into ItemView + CompositeView but not worth the time.
  • Backbone.Model — a building block
  • Backbone.Collection — a building block

I chose the jQuery Mobile (jQM) framework to help me organize my HTML and take advantage of its transitions and animation libraries. With a little bit of planning jQuery Mobile has turned out to compliment Marionette, I did however have to throw out a lot of jQM’s default JavaScript behavior.

My app architecture in a nutshell:

  • Marionette.Application is the starting point, basically a singleton to get things started.
  • My Marionette.Application provides a single point of contact for application-level event handling and tying together all of the component pieces of my various Backbone/Marionette Views and Controllers.

In the jQM paradigm Pages are a fundamental component. Each Page is demarcated by a <div data-role="page">. I have 3 basic jQM Pages. Each layout had a unique layout and imagine the wireframe looks something like below:

  • a start page (id=start)
  • a search page (id=search)
  • and a google map page (id=gmap)
Rough layout

Rough layout

Since I had these 3 pages, it made sense to define each as a Region in Marionette. Although a Region has all kinds of bells and whistles I can get a way with using these top-level Page Regions to only hide/show an individual page.

  • Each jQuery Mobile HTML block corresponds to its own Application.Module to maintain separation for the logic of my various views.
  • jQuery Mobile Page. Each Layout has multiple Region areas within. Notice how I have nested Regions by having Region > Layout > Region(s)
  • I get whatever content I need (in this case AJAX data from an API) whereby Backbone.Collection (i.e. a SQL table) contains many Backbone.Models (i.e. individual table rows)
  • ItemView is a View for individual Backbone.Model objects
  • In this case I use a CompositeView for my Backbone.Collection.
  • As a Collection contains multiple Models, so too does a CompositeView contain multiple ItemViews
  • A “show” call to Application.Region.Layout.SubRegion.show(CollectionCompositeView) will automatically cause the entire collection to render whereby the CompositeView wraps all of the individually rendered ItemView HTML. (think UL>LI*5, or TABLE>TR*5). The rendered aggregate HTML block will then be rendered into the region, replacing anything that was there before (may be override available)

US Passport Photo Maker

a.k.a. How to make Passport Photos with a Mac

a.k.a How to make Passport Photos with a PC

The US Department of state has a Flash tool to properly size and crop a passport photo. Since it’s Flash and works in your desktop browser Mac and PC users can easily make their own Passport photos for the US. It doesn’t get any easier than this. No need for Photoshop or rulers. The visual guides shows you where to put the person’s face and then you click save. Boom — a passport photo ready to rock and roll for the next 10 years. So simple!

http://travel.state.gov/_res/flash/cropper/FIG_cropper.html

Condominium Travel Club, Concord, CA

I unwittingly signed up to win s free trip to Hawaii at a home show in Santa Clara in January this year. About two weeks later I start getting a phone call from the same phone number four days in a row but I miss the call each time because I had some friends in town and I was skiing in Tahoe.

Condominium Travel Club (or Condo Travel Club)

http://www.yelp.com/biz/pulaski-tickets-and-tours-concord-2

Impossible-to-meet Terms & Conditions.

http://www.yourtrip.net/CONCORD_TERMS_AND_CONDITION.html

2-way iscroll for tablets and phones

https://github.com/cubiq/2-way-iScroll

The maker of the excellent SwipeView and iScroll 4 library for touch-enabled browsers has a somewhat unpublicized standalone library that has two-axis scrolling. It snaps if you swipe/scroll horizontally across columns (pages) and scrolls smoothly with momentum when you scroll vertically within a column.

Without modification I am able to use the library to create a reasonable snap-to-scroll on both X and Y axes.

The best thing about the library is that it will lock into a single scroll axis as you are scrolling. Beautiful!

MacWorld 2013

Cool notables from MacWorld 2013

Izik by blekko. A search engine user experience designed specifically for use on a tablet.

iPole is an iPhone/iPod-holding retracting stick for taking self portraits. Fully collapsed the iPole mini is about 18-inches long. The key component is the spring-loaded vice grip that holds your iPhone in place. You can connect the device to a standard tripod. The booth was also selling a walking stick for use with the vice grip that will come in handy for hiking.

Olloclip fisheye/macro/wide lens for iphone camera. Nice form factor.

Peculiar things at MacWorld 2013

A bird watching app… How did they afford a booth? I understand that bird-watching is a serious endeavor but this booth was seriously tricked out with some nice HD displays and lights.

Non-dairy grilled cheese. The first thing I happened across upon entering the expo hall was a giant grilled cheese booth giving out samples of non-dairy cream cheese. I have to say it was actually quite enjoyable.

ReadyNAS – Time Machine completed a verification of your backups

Time Machine completed a verification of your backups. To improve reliability, Time Machine must create a new backup for you.

Fix using the instructions: Fix Time Machine Sparsebundle NAS Based Backup Errors

[NOTE] Although the instructions above do indeed work to fix a TM backup, the problem has continued to occur where TM would report the corrupted data and I would have to fix it again every 2-3 weeks. It simply wasn’t worth the trouble so I switched back to my wired USB backup drive.

Net10, Tracfone, or Straight Talk Customers try the third SIM chip.

Have an iPhone but can’t use your data because you’re using Net10, Tracfone, or Straight Talk? Try swapping the Net 10 SIM.

When I bought my Net 10 SIM activation kit it came with 3 SIM chips: 1 micro SIM (for iPhone 4 or newer), 1 regular SIM for GSM networks, and 1 regular size pink SIM card designated for T-Mobile phones specifically.  I know that putting the T-mobile-specific SIM  gave me the “Cellular Data” settings when I put it in the iPhone while trying to perform the SIM swaps.

In the weeks I spent battling with my iPhone’s APN settings I never thought to try to actually activate my phone through the Net10/T-Mobile SIM. By activate I mean putting the Net10/T-mo SIM into my phone, calling Net10 customer service, and having them switch my service over to the EIN number for the Net10/T-mo chip. Since my iPhone can use native T-Mobile airwaves using a T-Mobile SIM, it would seem reasonable to be able to use T-Mobile airwaves via a Net 10 SIM designed for the T-Mobile network.

If you happen to have an iPhone 4 or later you still have options. You can shave down the regular sized SIM card to fit into a micro SIM slot. I did it with an xacto knife in about 20 minutes and does not need to be a perfect replica of a real micro SIM.

Disclaimer: I gave up trying to use my iPhone 4 on Net 10. Since there are no contracts I simply switched to T-Mobile monthly no-contract plans. T-Mobile is network pretty horrendous in my area but I don’t talk on the phone much. With T-Mobile I can use iMessage, MMS, and 2g/3G web — the stuff that matters to me.

Free EPUB readers for Mac Desktops

My iPad has iBooks which allows me to read EPUB format ebooks and PDFs. However, your lovely Mac cannot alone does not come with an EPUB reader. There are a few paid options in the Mac App Store but luckily I found 2 free non-App-Store options. I’m surprised there are not more decent open source options for reading EPUB files.

Calibre ebook management

Although it’s massively bloated (224 MB) I have found Calibre to be a very good e-book reader. It’s interface is somewhat iTunes-like since it attempts to be a one-stop-shop for your EPUB needs. I don’t really like using library management interfaces like this and would like for a reader-only download.

[Update 6/15/2013] I’ve been told that Calibre can convert ebooks from one format to another. This is an interesting feature that I have not tried yet.

Stanza for Mac

Stanza was a great ebook reader for iOS/iPhone/iPad before iBooks or Kindle came out. Unfortunately  Amazon bought Stanza and killed it. I haven’t even checked if Stanza is available in iTunes for iOS anymore. Nevertheless the spammy download sites like CNET and Brothersoft still have the last version of Stanza for Mac available for download. Stanza is a slimmer 35 MB download but its ebook rendering engine is not as good or accurate as Calibre.

Azardi

At 92MB Azardi is much slimmer than Calibre and provides simple EPUB reading pleasure. The rendering is slightly more accurate than Stanza but wow the user interface on Azardi is comically difficult to wade through.

[Update 6/15/2013] – I’ve given Azardi a second look since it’s much smaller than the last time I looked at it. I have a small capacity Macbook Air so every MB counts on my HD! I can say that the rendering seems faithful to the EPUB and the application loads much faster than Calibre. The user interface to manage books is still a bit quirky to me but I don’t have a huge ebook library so it provides the straightforward EPUB-reading ability that I was looking for without a lot of bells and whistles.

Azardi EPUB Reader

Azardi EPUB Reader

List of EPUB reader software (Wikipedia)

 

Net10 and other AT&T MVNO carriers should be pissed off at AT&T right now

Apple’s release of iOS 6.0 has likely caused Net10 (a.k.a. Straight Talk or Tracfone) and other AT&T MVNO mobile carriers a LOT of headaches this year. I think AT&T asked Apple to hide the APN settings menus purposely with the intent to hurt its MVNO partners.

Read a few stories on the web and you’ll find out that Apple hides an “APN settings” screen from AT&T and AT&T MVNO customers that would otherwise allow iPhone owners to use data and MMS through the much-cheaper MVNO carriers. MVNO carriers typically offer non-contract phone plans that are hundreds of dollars cheaper  than a standard AT&T two-year contract.

Hiding these APN settings menus affects the MVNO carriers that piggyback off of AT&T because without access to the APN, your phone won’t work 100%. No data. No MMS. No iMessage. The only “fix” that anyone has found  is to obtain a T-mobile SIM card and follow a sequence of steps in a precise way to trick the iPhone into thinking it had a T-Mobile SIM card so that I could alter the settings that I needed to change. I probably tried a dozen times without any success.  This experience actually turns out to be a good advertisement for T-Mobile because lo and behold a T-Mobile monthly actually allows me to use my phone 100% for the same price as the other MVNO anyway!

The result of this is some serious collateral damage to the AT&T MVNO carriers:

First, the Net10 customer service forums have been littered with dozens of people requesting help to reactivate the data feature on their iPhones. I know this because I was one of the dozens of people clogging the phone support lines trying to figure out why things stopped working. This in itself probably costs Net10/Tracfone/Straight Talk quite a bit of money.

Second, customers can vote with their wallets and leave the affected carriers. Since most of the MVNOs are pre-paid non-contract phones it’s easy for me to pick up and leave. It’s as simple as walking into a T-Mobile store and swapping out a SIM card.

Third, I would think that this has to be a breach of a service-level agreement between AT&T and the MVNOs because an essential offering has been taken away from the MVNO’s customer base, causing customers to leave.

It seems silly that AT&T would want to harm MVNO carriers on its network. After all, the MVNOs must be paying AT&T some amount of money for the bandwidth, regardless of being wholesale price or not. At least they are getting some money back. By switching to T-Mobile (or Virgin Mobile or Verizon pre-paid, etc.) that are off of AT&T’s towers the net profit for AT&T becomes zero dollars instead of the commission that AT&T could have gotten from Net10.