<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>Niall O'Higgins</title>
    <link>http://niallohiggins.com/</link>
    <description></description>
    <pubDate>Tue, 03 Apr 2012 18:02:45 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>3 Pros and Cons to Building Mobile Apps with JQuery Mobile and HTML5</title>
      <link>http://niallohiggins.com/2011/09/23/3-pros-cons-mobile-apps-with-jquery-mobile-and-html5/</link>
      <pubDate>Fri, 23 Sep 2011 17:04:00 PDT</pubDate>
      <category><![CDATA[Mobile]]></category>
      <category><![CDATA[Android]]></category>
      <category><![CDATA[JavaScript]]></category>
      <category><![CDATA[iOS]]></category>
      <category><![CDATA[HTML5]]></category>
      <guid>http://niallohiggins.com/2011/09/23/3-pros-cons-mobile-apps-with-jquery-mobile-and-html5/</guid>
      <description>3 Pros and Cons to Building Mobile Apps with JQuery Mobile and HTML5</description>
      <content:encoded><![CDATA[

<h3>Quick Introduction</h3>

<p> Over the past month or so, I have been using <a
  href="http://jquerymobile.com/">JQuery Mobile</a> to build a HTML5
mobile/tablet front-end for a <a href="http://dragpushpull.com/m">strength
  training website</a> I've developed. While I have built native Android and
iOS applications before (in Java and Objective-C, respectively) the promise of
a single codebase which would work on most major
platforms, as well as the ability to iterate quickly in HTML and JavaScript,
was very appealing.  </p>

<center><img src="/images/dpp-2.png" /></center>

<h3>JQuery Mobile &amp; HTML5</h3>

<p> To build a mobile app using HTML5 and JavaSript, you will need to write
quite a bit of JavaScript. However, the UI controls and handling for a touch
device are quite different from a standard web application.  You will therefore
want to take advantage of some kind of existing mobile HTML5/JavaScript
framework (unless you have a lot of time and want to write everything from
scratch yourself). There are a number of choices out there: <a
  href="http://www.jqtouch.com/">jQTouch</a>, <a
  href="http://www.sencha.com/products/touch">Sencha Touch</a> etc.  </p>

<p> I have been a fan of JQuery for many years, enjoying its minimalist
philosophy and the excellent core and community-contributed features and
plugins. JQuery made JavaScript development tolerable to me. So, having heard
good things about JQuery Mobile from <a
  href="https://twitter.com/#!/chrismcdonough">Chris McDonough</a> (Author of
the <a href="https://www.pylonsproject.org/">Pyramid Python Web Framework</a>),
I figured I'd give it a try.
</p>

<h3>JQuery Mobile &amp; HTML5: 3 Advantages</h3>

<ol>
  <li><b>Easy to learn and Quick to Iterate:</b>
  <p>
    After reading the <a href="http://jquerymobile.com/demos/1.0b3/">JQuery
    Mobile docs</a> and also reading the <a href="http://bit.ly/mEUfsc">JQuery
    Mobile</a> book from O'Reilly, I was able to build a working, rough version
  of my app over a weekend. That is with no prior HTML5 / JQuery Mobile
  experience. Compared to Android and iOS, it is far faster to build out your
  UI and logic using JQuery Mobile and HTML5 than either platform natively.
  </p>
  <p>
I found the learning curve for Apple's Interface Builder quite steep, and
it also takes time to learn the quirks of the Android layout system.
Furthermore, it is quite complicated to hook up a list view (ListView on
Android, UITableView on iOS) to a remote datasource, and have it looking
pretty, with native code. Using JQuery Mobile, I was able to leverage all my
existing JavaScript and HTML/CSS knowledge to do this very quickly.
I didn't have to learn a whole new abstraction with adapters, delegates etc. I just wrote JQuery code.
</p>
</li>

<li><b>Avoid App Store Approval Madness &amp; Debug Build Hell</b>:<p>
  One of the most painful things in developing for mobile, which by definition means being on iOS, is dealing with the Apple App Store approval process. In order to get a native app to your iOS users, you must go through a lengthy process (days, possibly weeks). Not only must you jump through this hoop on initial release, but for each upgrade, also. This adds greatly to the complexity of the QA and release cycle, in addition to simply adding time. Since JQuery Mobile apps are merely a special type of web app, they inherit all the wonderful qualities of that environment: As soon as the user reloads your site, they are "upgraded" to the latest version. Pushing bugfixes and new features is instantaneous. Even on Android - which with much less stringent Market requirements is the Wild West compared to the Apple environment - it is still nice to simply have the users upgraded without even being aware it is happening.
  </p>
  <p>
An extension to this is how easy it is to distribute beta/test builds to users. Simply tell them to point their browser at a URL and they have it! No DRM madness for iOS nor even APK distribution with Android to think about.
  </p>
  </li>


<li><b>Cross-platform &amp; cross-device:</b>
<p>
The fact that my app worked immediately on both Android and iOS - along with <a href="http://jquerymobile.com/gbs/">many other platforms</a> - is a massive advantage. As an individual developer, it is a huge effort to maintain a separate code base for each platform. Writing a quality mobile application for a single platform is a full-time job, having to re-do that for each platform takes a lot of resources. The fact that my app will work on both my Android and iOS devices equally well is a huge bonus.
</p>
<p>
Furthermore, especially with the massive proliferation of Android devices in all shapes and sizes, making your app look presentable on a huge variety of screen resolutions is a real challenge. For serious Android developers, device fragmentation in terms of screen size (scaling from the downright tiny to quite large) actually represents a considerable development cost. With the browser rendering your application in a way that looks reasonable on every device, you don't have to worry about this to anywhere near the same extent.
</p>

</li>

</ol>

<h3>JQuery Mobile &amp; HTML5: 3 Disadvantages</h3>

<ol>
  <li><b>Slower Than Native:</b>
  <p>
  The biggest drawback in my opinion is that even on the latest Android and iOS hardware (dual core Tegra 2 Android phone, dual core iPad2 tablet), JQuery Mobile applications feel noticeably slower than native. Especially on Android, where the browser is surprisingly (since Google is a web-focused company) far slower and buggier than on iOS. I haven't yet tested my app on older Android devices but it may be downright unusable there (e.g. G1 Android phone).
  </p>
  <p>
  I believe that in the next 12-24 months hardware will catch up sufficiently (e.g. quad-core devices coming in 2011) that this will be less of an issue. But today, it is a definite drawback. Also, if you are solely targetting iOS, you can count on the performance of the browser being at least reasonable (unlike Android, BlackBerry, etc).
  </p>
  </li>

  <li><b>Quirky</b>:
  <p>
  JQuery Mobile is still beta software, and as such I have encountered bugs. That being said, the team is extremely responsive in <a href="https://github.com/jquery/jquery-mobile/issues">addressing issues on GitHub</a>. I think one of the big problems is simply quirks across various browsers on different platforms. I am certain that this will be ironed out over time. The applications also can look quirky in a visual sense - while I think the JQuery Mobile team have done a great job with their widgets and themes, it is still fairly distinct from native. How much this really matters to users is not clear, but it is something to be aware of.
  </p>
  </li>

  <li><b>Limited Capabilities vs Native</b>:
  <p>
  Obviously, JavaScript running in a browser does not have full access to many features of the device. A common example being the camera. However, tools like <a href="http://www.phonegap.com/">PhoneGap</a> help greatly with many common issues. Indeed, I have started working on deploying versions of my app for iOS and Android with PhoneGap - using <a href="https://github.com/davejohnson/phonegap-plugin-facebook-connect">native Facebook bindings</a> - and am quite impressed. I will be writing about my experiences with PhoneGap and native bindings in future posts.
  </p>
  </li>
</ol>

<h3>Conclusion</h3>
<p>
To sum it up, I believe that JQuery Mobile and HTML5 is a viable platform for mobile application development. However, it does not (yet) suit all classes of applications. For simple content display and data entry-type apps (as opposed to very rich multimedia/gaming applications) it can be a great force multiplier compared with native. I certainly am happy with how it has turned out for my app - I simply do not have the time to maintain a port of my strength tracker app for both Android and iOS.
</p>
<p>
Over the course of the next 1-2 years, as hardware gets faster and devices proliferate, I believe HTML5 (and JQuery Mobile, PhoneGap, etc) will be even more important technologies in the mobile app space.
</p>
]]></content:encoded>
    </item>
    <item>
      <title>Autocomplete with Python, Pylons, SQLAlchemy and jQuery</title>
      <link>http://niallohiggins.com/2009/12/21/autocomplete-with-python-pylons-sqlalchemy-and-jquery/</link>
      <pubDate>Mon, 21 Dec 2009 21:51:55 PST</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[JavaScript]]></category>
      <guid>http://niallohiggins.com/?p=667</guid>
      <description>Autocomplete with Python, Pylons, SQLAlchemy and jQuery</description>
      <content:encoded><![CDATA[
<p>
Recently I needed to implement my own autocomplete for a project on <a href="http://snagmachine.com">snagmachine.com</a>.  We had a large database of products and wanted to ease data entry by hinting to the user via autocomplete when possible. In future, we can probably just use <a href="http://www.freebase.com/docs/suggest">Freebase Suggest</a> but right now we needed our own solution.
</p>


<p>
<b>The Pieces</b>
<br/>

Autocomplete is not too hard to understand.  It is comprised of two pieces:
<br/>

<ul>
<li>Client-side javascript</li>
<li>Backend web service</li>
</ul>

<p>
<b>Autocomplete JavaScript Widget</b>
<br/>
The client-side JavaScript code is the thing that watches user input to a given text-entry field, and sends queries to the backend web service.  If the backend has some suggestions for the user, the JavaScript then displays those hints and lets the user pick one.
</p>

<p>
Although not hard to understand, the display code and query timing bits of the client-side component make it not utterly trivial to implement.  For this reason, we decided to use an existing jQuery autocomplete widget, instead of writing our own.
</p>

<p>
Choosing one was a little bit confusing, because there are around four or five distinct jQuery autocomplete widgets floating around.  It took some investigation to find one which fit our needs.  We ended up picking <a href="http://www.devbridge.com/projects/autocomplete/jquery/">Ajax Autocomplete for jQuery</a> by Tomas Kirda.
</p>

<p>
We chose this one because it seemed to be the only widget which easily enabled you to pass arbitrary metadata to the client JavaScript from the backend, in addition to mere text completion.  So, if you need to pass along IDs or other values with your suggestions, I recommend this widget instead of some of the simpler ones.
</p>

Setting up the autocomplete widget in your JavaScript is quite straightforward:
<br/>

<pre lang="javascript">
$("#sometextfield").autocomplete({
            serviceUrl:'/api/product_autocomplete',
            onSelect: function(val, data) {
              /* Handle data here */
            },
});
</pre>
</p>

<p>
<b>Backend Web Service</b>
<br/>

Writing an autocomplete web service is pretty simple.  Your entrypoint is going to accept a string of text (query) and return a set of results to be displayed to the user by the autocomplete widget.  Depending on your usage, you may also wish to include some metadata along with your results - for example, the database ID of each completion, or something like that.
</p>

<p>
The service is especially trivial if you are using a database which supports an analog to the SQL LIKE/ILIKE operator which does basic wild-card text matching.  I believe that all databases supported by <a href="http://sqlalchemy.org">SQLAlchemy</a> will have this feature. 
</p>

<p>
Although I happened to be using SQLAlchemy and a fairly traditional RDBMS (<a href="http://www.postgresql.org">PostgreSQL</a>) for snagmachine.com, something similar should be quite possible with <a href="http://1978th.net/tokyotyrant/">Tokyo Tyrant</a> and the like.
</p>

<p>
We are using <a href="http://pylonshq.com">Pylons</a> and SQLAlchemy for snagmachine.com, but again, it shouldn't be much more complicated with some other web framework:
</p>

<pre lang="python">
    @rest.restrict('GET')
    @jsonify
    def tag_autocomplete(self):
        if 'query' not in request.params:
            abort(400)
        fragment = request.params['query']
        keywords = fragment.split()
        searchstring = "%%".join(keywords)
        searchstring = '%%%s%%' %(searchstring)
        try:
            ac_q = Session.query(Tag)
            res = ac_q.filter(Tag.name.ilike(searchstring)).limit(10)
            return dict(query=fragment,
                    suggestions=[r.name for r in res],
                    data=["%s" %(r.name) for r in res])
        except NoResultFound:
            return dict(query=fragment, suggestions=[], data=[])

</pre>
<br/>

In the above code, we are using a very simple SQLAlchemy model class "Tag" which basically consists of a text `name' field:
<pre lang="python">
tag_table = sa.Table("tag", meta.metadata,
    sa.Column("id", types.Integer, sa.schema.Sequence('taq_seq_id',
        optional=True), primary_key=True),
    sa.Column("name", types.Unicode(50), nullable=False, unique=True),
    sa.Column("extra", types.String),
)
class Tag(object):
    pass
orm.mapper(Tag, tag_table)
</pre>
<p>
  We also use the <a href="http://pylonshq.com/docs/en/0.9.7/modules/decorators_rest/">Pylons rest decorator</a> and the <a href="http://pylonshq.com/docs/en/0.9.7/modules/decorators/#pylons.decorators.jsonify">Pylons jsonify decorator</a> for convenience.
</p>
<br/>

Note that in the above code, we:
<br/>

<ul>
<li>Use the ilike operator</li>
<li>Use wildcards at the beginning and end of the string</li>
<li>Replace whitespace with wildcards</li>
</ul>

<p>
We've found this mode to give us the best user experience, however there are performance implications.  PostgreSQL at least can only utilise text indexes for LIKE, and furthermore only if the wildcards are suffixes [<a href="http://markmail.org/message/ibuw5poeqysiv4h3">This email from Tom Lane has the details</a>].
</p>

<p>
While using the index does yield about an order of magnitude difference in query response time, we are talking about 0.1 ms vs 1.0 ms with our dataset.  For our use case, this is perfectly acceptable!
</p>

<p>
So, thats pretty much everything there is to it.  Hope this article helps!
</p>
]]></content:encoded>
    </item>
    <item>
      <title>jQuery Freebase Suggest In Place</title>
      <link>http://niallohiggins.com/2009/10/27/jquery-freebase-suggest-in-place/</link>
      <pubDate>Tue, 27 Oct 2009 20:56:33 PDT</pubDate>
      <category><![CDATA[Technical]]></category>
      <category><![CDATA[JavaScript]]></category>
      <guid>http://niallohiggins.com/?p=621</guid>
      <description>jQuery Freebase Suggest In Place</description>
      <content:encoded><![CDATA[
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.js"></script>
<script type="text/javascript" src="http://niallohiggins.com/wp-content/uploads/2009/10/jquery.suggestinplace.js"></script>

I just finished my hack of <a href="http://code.google.com/p/jquery-in-place-editor/">JQuery In Place Editor</a> to work with <a href="http://www.freebase.com/docs/suggest">Freebase Suggest</a>.  I call it "JQuery Suggest In Place".  Its pretty much the same as JQuery Edit In Place, except it is stripped down a bit to only give you an input text field with a bound Freebase Suggest.  You can pass along a type (or array of types) and you get back the results by supplying a callback function.

Here's an example of how it works with a <a href="http://www.freebase.com/view/location/citytown">City/Town</a> selector:

<div class="suggest">Click Me!</div>

<script type="text/javascript">
$(".suggest").suggestInPlace({callback: function(e, data) {
alert("Name: " + data.name + " Freebase ID: " + data.id);
}});
</script>

And the code to do the above:

<pre lang="javascript">
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.0.1/suggest.min.js"></script>
<script type="text/javascript" src="jquery.suggestinplace.js"></script>
<div class="suggest"></div>
<script type="text/javascript">
$(".suggest").suggestInPlace({callback: function(e, data) {
alert("Name: " + data.name + " Freebase ID: " + data.id);
}});
</script>
</pre>

<a href="http://niallohiggins.com/wp-content/uploads/2009/10/jquery.suggestinplace.js">Download the source to my jquery.suggestinplace.js hack, under BSD license.</a>

]]></content:encoded>
    </item>
    <item>
      <title>Py Web SF: The San Francisco Python & Web Technology Meet-up</title>
      <link>http://niallohiggins.com/2009/07/24/py-web-sf-the-san-francisco-python-web-technology-meet-up/</link>
      <pubDate>Fri, 24 Jul 2009 19:29:47 PDT</pubDate>
      <category><![CDATA[Technical]]></category>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[UNIX]]></category>
      <category><![CDATA[JavaScript]]></category>
      <category><![CDATA[Windows]]></category>
      <guid>http://niallohiggins.com/?p=563</guid>
      <description>Py Web SF: The San Francisco Python & Web Technology Meet-up</description>
      <content:encoded><![CDATA[
Last month I started <a href="http://pywebsf.org">Py Web SF</a>, the San Francisco Python & Web Technology meet-up.  The idea is 1-2 conversation-style presentations of about 30 minutes with a group of 10-20 people.  My hope is to have a more intimate group than the very good <a href="http://www.baypiggies.net/">Bay Piggies</a> (which I highly recommend).  With a small group, it is possible to have more interaction, discussion and collaboration.  In a typical lecture/audience format, people unfortunately tend to switch into "passive listener" mode.

<p>
<a href="http://pywebsf.org"><img src="http://niallohiggins.com/wp-content/uploads/2009/07/pywebsf.png" alt="pywebsf" title="pywebsf" width="321" height="156" class="aligncenter size-full wp-image-566" /></a>
</p>

<p>
<strong>June meet-up</strong>
<br/>

Anyway, the first meet-up went extremely well - we had 15 people show up, which was a perfect number for the space.  <a href="http://jjinux.blogspot.com/">Shannon -jj Behrens</a> gave an excellent talk on <A href="http://www.pywebsf.org/2009/06/24/shannon-jj-behrens-techniques-for-building-third-party-restful-web-services/">building RESTful Web services</a> and <a href="http://monkey.org/~marius">Marius Eriksen</a> - in fact a colleague from the <a href="http://www.openbsd.org">OpenBSD project</a> - gave an <a href="http://www.pywebsf.org/2009/06/24/marius-a-eriksen-geodjango-a-world-class-geographic-web-framework/">awesome talk on GeoDjango</a>.  Slides for both talks are online, of course.
</p>

<p>
<strong>July meet-up</strong>
<br/>

<a href="http://www.pywebsf.org/2009/07/21/py-web-sf-2-july-28th-6pm-sf-main-public-library%e2%80%99s-stong-room/'>This month's meet</a> should be equally good.  We have two great talks lined up - Aseem Mohanty, a colleague of mine from <a href="http://www.metaweb.com">Metaweb Technologies</a> presenting a comparison of Django and Pylons.  Then we have Alec Flett, another Metaweb'er, speaking about all the issues involved in scaling Python web applications.
</p>

<p>
<strong>Check it out</strong>
<br/>

If you are interested in checking out the event, its <b>July 28th, 6pm @ SF Main Public Libraryâ€™s Stong Room</b>.  Full details can be found <a href=" http://www.pywebsf.org/2009/07/21/py-web-sf-2-july-28th-6pm-sf-main-public-library%E2%80%99s-stong-room/">at pywebsf.org</a>. Or if you are interested in giving a talk, <a href="mailto:niallo@pywebsf.org">just let me know</a>.
</p>
]]></content:encoded>
    </item>
    <item>
      <title>Freebase Suggest and restricting to multiple types </title>
      <link>http://niallohiggins.com/2008/11/14/freebase-suggest-and-restricting-to-multiple-types/</link>
      <pubDate>Fri, 14 Nov 2008 21:43:49 PST</pubDate>
      <category><![CDATA[Technical]]></category>
      <category><![CDATA[JavaScript]]></category>
      <category><![CDATA[Database]]></category>
      <guid>http://niallohiggins.com/?p=98</guid>
      <description>Freebase Suggest and restricting to multiple types </description>
      <content:encoded><![CDATA[
<a href="http://code.google.com/p/freebase-suggest/">Freebase Suggest</a> is a little JavaScript (and <a href="http://jquery.com">jQuery</a>) widget for adding <a href="http://www.freebase.com">Freebase</a>'s <a href="http://www.freebase.com/view/guid/9202a8c04000641f8000000006ad84c9">auto-complete and search API</a> reconciliation features to any of your text boxes.  While this might sound a bit strange or pointless initially, its actually incredibly useful in many applications  

Imagine you are running a site for your own music reviews.  You have a nice web form for writing the reviews, which includes fields for artist name and album.  It can be a pain sometimes to remember the exact album title or band name, and you probably find yourself having to double-check this a few times before posting your review.  However, chances are high that your artist and album are already available in Freebase, and this is where the Freebase Suggest widget comes in.  You simply attach the widget to your artist field, and your album field.  Now by default, you can auto-complete to any topic in Freebase.  This is pretty good, but wait there's more!  You can trivially nail down the types returned by the auto-complete service to just be, say, <a href="http://www.freebase.com/view/music/album">/music/album</a>.  You could do the same for your musical artist box by limiting to <a href="http://www.freebase.com/view/music/artist">/music/artist</a>.  To see what this Freebase Suggest widget looks like in this configuration, <a href="http://mqlx.com/freebase-suggest/examples/suggest_demo2.html">check out some of the examples</a>.

So now you know how to add Freebase Suggest to your web forms to reduce friction on input.  You also know how to nail down the auto-complete results to a specific type.  But what if you have a single input box which accepts, say a more generic 'media title'.  This could be a <a href="http://www.freebase.com/view/film/film">film</a> name, a <a href="http://www.freebase.com/view/tv/tv_program">TV show</a> or a music album.  Again, it would be really nice here to be able to use Freebase Suggest to leverage the already-entered and verified data of Freebase to ease input in your form - but how do you make it work with multiple types?

This is something I wanted to do in one of my own applications today, and its very easy!  In order to limit your Freebase Suggest results to a specific type, you already have some code <a href="http://code.google.com/p/freebase-suggest/wiki/Usage">setting up the ac_param dictionary</a> passed to the widget.  That code probably looks something like this:

<pre lang="javascript" line="1">
var o = { type:'/music/album' };
$(id).freebaseSuggest({ac_param:o});
$(id).bind("fb-select", suggest_cb);
</pre>

Now, to adapt this so that it also handles completion of <a href="">films</a> and <a href="http://www.freebase.com/view/tv/tv_program">TV shows</a>, we simply add multiple type keys to our options dictionary, like so:

<pre lang="javascript" line="1">
var o = { type:'/music/album', 
          type:'/film/film',
          type:'/tv/tv_program' };
$(id).freebaseSuggest({ac_param:o});
$(id).bind("fb-select", suggest_cb);
</pre>

And there you have it!  Freebase Suggest results restricted to multiple types.
]]></content:encoded>
    </item>
  </channel>
</rss>

