webapi – the elusive 406, AsyncEntitySetController

One of the most annoying things you will encounter while writing WebApi code [and there are many] is the 406 error.


That’s all the server will tell you; ‘Unacceptable’…

Here is one of the harder bugs to find that causes this error;

If you are using an AsyncEntitySetController make sure you do not have ANY async functions in your controller that do not have an await in them; otherwise you will get a 406 without your controller ever being hit.

Forget HTML; Markdown is the way to go!

One of the most annoying things about creating websites is having to write large blocks of text in HTML. No matter how comfortable you are with HTML, it is an unnatural way of writing flowing texts. Having to worry about a hierarchy, a opening and closing tags, indenting, all things too distracting to writer.

This is where Markdown comes in, it is a simpler, text oriented syntax that is a lot simpler and cleaner than HTML for the purpose of constructing documents.

You can read more about markdown here: wikipedia


Install marked:

npm install marked

Include a markdown document into your jade view:

include path/to/document.md

Jade will automatically run document.md through marked and convert it to the proper HTML.

requirejs – load as module if possible

If you are writing a library that might or not be used with a module loader you can make your developers’ life easier by adding the following at the end of your module.

(function( window, undefined ) {

if ( typeof module === "object" && module && typeof module.exports === "object" ) {
    module.exports = __EXPORTED_OBJECT__;
} else {
    if ( typeof define === "function" && define.amd ) {
        define( "__module_name__", [], function () { return __EXPORTED_OBJECT__; } );

require.js – knockout templating plugin

update – this code should be modified to first look in the require.js registry before trying to load using ajax.

Here is a plugin I wrote to help me load and apply knockout templates using require.js.

This same pattern can be used with any other templating engin.

define(['libs/jquery', 'libs/knockout'], function($, ko){
  function load(name, req, onload, config) {
    var url = req.toUrl(name + '.ko');

    function tmplr(err, text) {
      this.err  = err;
      this.text = text;

      this.apply = function(data, $el) {
        if (!this.err) {
          if ($el) {
            ko.applyBindings(data, $el[0]);
          } else {
        } else {
          throw err;

      .done(function (text) {
        onload(new tmplr(undefined, text));
      .fail(function (jqXHR, textStatus, errorThrown){
        onload(new tmplr(errorThrown));

  return {
      load       : load

‘libs/require/plugin/ko’ is the path to this plugin
‘tmpl/app/contacts’ is the path to the template; note that the plugin will add ‘.ko’ to this path, the file would be called ‘contacts.ko’

require(['libs/require/plugin/ko!tmpl/app/contacts'], function(tmplr){
  if (!tmplr.err) {
    tmplr.apply($('#scope_element_id'), res);

#Cordova – 2.7 – InAppBrowser Anonymous Event Handler Bug

If the callback passed to an InAppBrowser event is an anonymous method, said anonymous method will ONLY be called if it does not reference any other functions within the JS code.

function foo(){console.log('hello from foo');}
ref.addEventListener('loadstop', function(e)
  // this callback will not be called
  console.log('hello from loadstop);

Bug Report

#github – Port Subversion repository to github

I’m in the process of porting my subversion repositories to github. This is the main command line that you would need to run from within an empty folder.

svn2git svn://domain/repo_name/ --username svn_user --authors ~/authors.txt --verbose

Push the converted repository to github by running:

git remote add origin git@github.com:username/git-repo-name.git
git push --all
git push --tags

more details can be found in this blog post Converting confused SVN repositories into Git repositories

You may encounter an error regarding the tip of your current repository being behind the remote repository. This could happen if you created a readme.md file in github when you created your repository. To resolve this, you will need to merge your local repository using:

git pull origin master