x-callback-url for iOS Interapp Communication

x-callback-url is an unofficial spec for iOS interapp communication.

The goal of the x-callback-url specification is to provide a standardized means for iOS developers to expose and document the methods they make available to other apps.

If you want that your iOS app can be invoked from other apps or websites you can register URL types in your Info.plist like this:

http://soenkerohde.com/img/xcallbackurl.png

The example above can be invoked with: test://x-callback-url/action?foo=bar Additionally to parameters you are also encouraged to specify x-success, x-error, e-cancel and x-source. These are urls (except x-source which should be the name of invoking app) which will be invoked when the action is completed, was canceled or failed. If your app (which in this example registered myapp as an x-callback-url scheme) wants to use the test app to do a task the call could look like this (Specs):

test://x-callback-url/post?text=Foo
&x-source=My%20App
&x-success=myapp://x-callback-url/post-success
&x-cancel=myapp://x-callback-url/post-cancel
&x-error=myapp://x-callback-url/post-error

However, please consider the implications. When implementing to call the x-error url after completion the user is also leaving your app again.

“Bad app” could look like this:

function spam(){window.location =
  "test://x-callback-url/post&text=spam&x-success=badapp://x-callback-url/bam";}

document.addEventListener("invoke", spam, false);
document.addEventListener("resume", spam, false);

You should consider x-callback-url as an API to your app which is better bullet proof. Also be aware that the URL scheme should be unique. If two apps have the same URL scheme registered only one gets actually invoked. Not sure how this is determinated.

How to use PListBuddy

If you are using PhoneGap to create mobile web apps you might have a different Cordova.plist for development and production. A helpful tool to modify the plist file is PListBuddy.

If you for instance want to remove logging for production this would be the command line:

$ /usr/libexec/PlistBuddy -c "Delete :P lugins:Logger" Cordova.plist

or you want to set the build version dynamically:

$ /usr/libexec/PlistBuddy -c "Set CFBundleVersion #30" AppName-Info.plist

If you are using Ant the target to set the build number to the Jenkins build:

<target name="setBuildNumber">
    <exec executable="/usr/libexec/PlistBuddy">
      <arg value="-c"/>
      <arg value="Set CFBundleVersion #${env.BUILD_NUMBER}"/>
      <arg value="xcode/AppName.plist"/>
    </exec>
</target>

Markdown

This is my first post using the WP-Markdown plugin.

Markdown is a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).”

I think the first time I’ve used Markdown was for GitHub Readme files. It feels very natural to structure text that way and it is very easy to add code snippets. GitHub also added a Markdown syntax cheat sheet. Just go to GitHub, press ‘m’ and you’ll see. For my recent code examples I’ve embedded GitHub gists but sometimes that’s just too much of an effort for small code snippets. If you have longer snippets which are also likely to be changed/versioned gists are the way to go.

As a desktop client I’ve used Mou which works great. Ideally I would like to see this kind of live preview in Sublime Text 2 to not have too many apps open. I guess there is no plugin for that yet, right?

This code here below comes after a newline and is indented by 4 spaces:

addEventListener 'click', (event) =>
  # fat arrow preserves the outer scope
  @foo = event.data

or a CoffeeScript class:

class Util

  @LOGS: ''

  @log: (msg) ->
    LOGS += "#{msg}\n"
    console?.log msg

window?.Util = Util
module?.exports = Util

Another area I started using Markdown is for inline comments in my CoffeeScript files. Docco is great for generating docs:

$ docco src/*.coffee
$ open docs/SomeClass.html

Example:

# ### Load user or list of users
# `id` Id of the user or null to get list
# `callback` Callback function `(err, data)`
getUser: (id, callback) ->
  $.get id, (event) ->
    if event.success
      callback null, event.result
    else
      callback event.error

Now that I am about to finish this post I can say that writing it using Markdown with the WordPress plugin works really great. Using a MySQL database to store Markdown feels kinda weird though but hey, Rome wasn’t build in one day neither.

Anywhere else Markdown is becoming popular or any other good tools?

Using Redis as Node.js Express Session Storage on Heroku

The default way to use sessions with Node.js and Express is using the bundled memory store. However, if you want to deploy your app to Heroku and use multiple dynos it won’t work because the memory store doesn’t work across dynos.

The solution is to use a database for session storage and it seems like Redis or MongoDB are the most common used together with Node.js and Express. Here a quick walk through to setup Redis for this purpose. The example is using CoffeeScript.

First you want to install Redis on your machine to test against localhost. Download the source and then:

Install the Redis add-on on Heroku: $ heroku addons:add redistogo
You can check your config to make sure process.env.REDISTOGO_URL is available: $ heroku config

Now the implementation in your main app.coffee file:

Make sure to add the new dependencies to your package.json:
“connect-redis”: “1.3.0″, “redis”: “0.7.1″

That’s pretty much it. Now just scale your dynos: $ heroku ps:scale web=2

Thanks to Jerod Santo for his blog post which got me started.
Also read the docs on Express Session Handling.

New Machine Setup

Recently I’ve got a new work Mac Book Pro. Here a a summary of my initial setup:

  • Preferences

    • Tap to click
    • Natural scrolling
  • Software

    • 1Password
    • Adium
    • Dropbox
    • Evernote
    • Firefox
    • Fish Shell
    • Git
    • Google Chrome
    • Google Chrome Canary
    • Google Drive
    • Growl Fork
    • Heroku toolbelt
    • Homebrew (ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)")
    • iTerm 2
    • Kindle
    • Mongo DB (brew install mongodb)
    • node.js
    • Skype
    • Spotify
    • Sublime Text 2 (with packages for CoffeeScript and Stylus)
    • Sublime Package Manager
    • Twitter
    • Redis (brew install redis)
    • XCode
  • Global NPM packages

  • Misc

Node.js server-side compile Hogan.js templates

If you are using Node.js with Hogan.js you want to compile your templates on the server.
With Node.js you can create a route which looks like this:

Include it like: <script src=’templates’ type=’text/javascript’></script>
Templates are in the T namespace and can be renderered like this: