<?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:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>3 Quick Tips for Writing Tests in Node.JS (after some rambling)</title>
      <link>http://niallohiggins.com/2012/03/28/3-quick-tips-for-writing-tests-in-nodejs</link>
      <pubDate>Wed, 28 Mar 2012 17:04:00 PDT</pubDate>
      <category><![CDATA[Node]]></category>
      <category><![CDATA[Testing]]></category>
      <guid>http://niallohiggins.com/2012/03/28/3-quick-tips-for-writing-tests-in-nodejs</guid>
      <description>3 Quick Tips for Writing Tests in Node.JS (after some rambling)</description>
      <content:encoded><![CDATA[

<h3>3 Quick Tips for Writing Tests in Node.Js (after some rambling)</h3>

<img src="http://nodejs.org/images/logo-light.png"/>

<p>
You are probably already aware of <a href="http://nodejs.org">Node.JS</a>,
unless you've been living under a rock for the past year. It's a pretty
ingenious project combining the extremely fast <a
  href="https://code.google.com/p/v8/">Google V8 JavaScript engine</a> with a
  highly-optimized cross-platform asynchronous networking library (<a
  href="https://github.com/joyent/libuv">libuv</a>). The next two paragraphs
  will be some rambling opinions on Node.JS coming from a Python and C hacker.
  Then we shall get down to writing tests.

</p>

<p> Node.JS makes it possible to write very efficient async network demons in a
higher-level language than C without taking a huge performance hit. V8 is
extremely fast and libuv and the NodeJS core library have been heavily optimized
for minimal number of system calls. Also, since absolutely everything in the
ecosystem is asynchronous from the start, you don't have to worry about things
like how you can effectively talk to your database because your MySQL driver
does blocking IO.  Node.JS is a good fit for people who would like to leverage
asynchronous IO in their program but don't want the headaches of programming in
C or using a slower language like Python or Ruby which also carry a legacy of
synchronous-only library code.  </p>

<p>

While I originally really disliked JavaScript as a language before learning
Node.JS, it has since become a lot more enjoyable. I have found its support for
object literals, closures and anonymous functions to be a great fit for async
network programming. Furthermore the lightweight syntax and <a
href="http://wiki.commonjs.org/wiki/Modules/1.1">CommonJS module system</a>
have grown on me. Finally, I am loving the philosophy of a minimalist standard
library married with an awesome, Github-integrated, local-by-default package
system, <a href="http://npmjs.org">npm</a>. I also recommend using the <a
href="http://documentcloud.github.com/underscore/">underscore</a> library to
anybody who finds themselves missing the list and set operations from other
languages.

</p>

<h3>Testing in Node.JS</h3>
<p>
Node.JS is very new, still maturing and pre 1.0 release. I initially found it
hard to know where to begin with writing tests. Which test runner is standard?
How do you do assertions? What about dependency injection / mocking? Are there
easy ways to set up functional (ie full stack) tests?
</p>

<h3>Tip 1 - Choosing a Test Runner</h3>
<p>
It turns out that there are a whole bunch of JavaScript and Node.JS-specific
test runners/frameworks. The major ones I'm aware of:

<ul>
  <li><a href="https://github.com/caolan/nodeunit">Nodeunit</a> - Simple, lightweight test runner for Node and browser. Supports setup and teardown and all the basic stuff you'd expect.</li>
  <li><a href="http://visionmedia.github.com/mocha/">Mocha</a> - Similar to Nodeunit, few more bells and whistles (like a test-creation API) along with a zillion output formatters.</li>
  <li><a href="http://vowsjs.org/">Vows</a> - BDD framework which I couldn't really get into personally but is clearly quite powerful and popular.</li>
</ul>
</p>

<p>

I ended up choosing <a href="http://visionmedia.github.com/mocha/">Mocha</a>
and haven't regretted it. It is easy to use from the command line (reflects
test status via exit code), I can use regular expressions to select narrower
sets of tests and it has an API for defining tests programmatically along with
machine-readable output formats. You can use a few different vocabularies (BDD,
TDD, etc) to write your tests. It reminds me a bit of <a
  href="http://readthedocs.org/docs/nose/en/latest/">Nose</a> from the Python
  world, but not quite as full-featured (yet). Oh, and Mocha makes it easy to
  test asynchronous code, too. Just remember to use the done() function,
  otherwise you can end up with strange bugs in your tests :-)

</p>


<h3>Tip 2 - Choosing an Assertion Library for Node.JS</h3>

<p>

In Python, the standard library contains an assertion library and often the
test runner will provide some more wrappers, for example either <a
  href="http://readthedocs.org/docs/nose/en/latest/testing_tools.html">nose.tools</a>
or <a
  href="http://docs.python.org/dev/library/unittest.html#unittest.TestCase">unittest.TestCase</a>.
In Node, the standard library contains <a
  href="http://nodejs.org/docs/latest/api/assert.html">some basic assert
  functions</a>. If you want more than that (e.g. some convenience wrappers)
you'll need to look for an additional assertion library. It doesn't seem like
the test
runner people are in the business of providing assertion shortcuts at the
moment.

</p>

<p>
I ended up going with <a href="https://github.com/visionmedia/should.js">should.js</a> which patches the Object prototype. This enables you to write code like:


<div class="pygments_murphy"><pre><span class="c1">// copied from example at https://github.com/visionmedia/should.js</span>
<span class="kd">var</span> <span class="nx">user</span> <span class="o">=</span> <span class="p">{</span>
      <span class="nx">name</span><span class="o">:</span> <span class="s1">&#39;tj&#39;</span>
    <span class="p">,</span> <span class="nx">pets</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;tobi&#39;</span><span class="p">,</span> <span class="s1">&#39;loki&#39;</span><span class="p">,</span> <span class="s1">&#39;jane&#39;</span><span class="p">,</span> <span class="s1">&#39;bandit&#39;</span><span class="p">]</span>
<span class="p">};</span>
<span class="nx">user</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">have</span><span class="p">.</span><span class="nx">property</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">,</span> <span class="s1">&#39;tj&#39;</span><span class="p">);</span>
<span class="nx">user</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">have</span><span class="p">.</span><span class="nx">property</span><span class="p">(</span><span class="s1">&#39;pets&#39;</span><span class="p">).</span><span class="kd">with</span><span class="p">.</span><span class="nx">lengthOf</span><span class="p">(</span><span class="mi">4</span><span class="p">);</span>
</pre></div>




<p>
To be honest I'm not sure I like this style because it is a bit wordy and
doesn't work with null or undefined. To assert that a variable is null or
undefined, you have to use something else.  However should.js provides some useful
shortcuts so I've stuck with it.
</p>

<p>
I also came across <a href="http://chaijs.com/">Chai</a> which offers the same
"should" / BDD-type stuff that should.js offers, in addition to having a couple
of other modes, including "assert"-style. The Chai assert-style adds a few nice
convenience methods over the Node.JS stdlib assert module.
</p>

<p>
Next time I might just use the standard Node assert module or try Chai's
convenience wrappers. I am not feeling amazing benefits to the should.js BDD
style right now.
</p>

</p>

<h3>Tip 3 - Mocking / Stubbing / Dependency Injection in Node.JS</h3>

<p>

Let's imagine you have written a module which exports a number of functions. Those
functions depend on another module which you use for communicating with an
external resource - a good example is a database. Consider the following two modules:


<div class="pygments_murphy"><pre><span class="c1">// database.js - functions for talking to persistence store</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">insert</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">cb</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// ... implementation ...</span>
<span class="p">}</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">query</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="nx">cb</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// ... implementation ...</span>
<span class="p">}</span>
</pre></div>




<hr/>


<div class="pygments_murphy"><pre><span class="c1">// user.js - functions to manage users of the system</span>
<span class="kd">var</span> <span class="nx">database</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;./database.js&#39;</span><span class="p">);</span>
<span class="nx">exports</span><span class="p">.</span><span class="nx">get_user</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">username</span><span class="p">,</span> <span class="nx">cb</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">database</span><span class="p">.</span><span class="nx">query</span><span class="p">(</span><span class="s2">&quot;user_&quot;</span> <span class="o">+</span> <span class="nx">username</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">user</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">err</span><span class="p">)</span> <span class="k">throw</span> <span class="nx">err</span><span class="p">;</span>
      <span class="kd">var</span> <span class="nx">res</span> <span class="o">=</span> <span class="p">{};</span>
      <span class="c1">// ... do some additional processing then call cb() ...</span>
  <span class="p">});</span>
<span class="p">}</span>
</pre></div>




<p>
You want to test user.js <b>without actually talking to a real
  database</b>. You want to do this to avoid the performance penalty and
additional complexity involved in actually testing against a real database.
Note that you may also choose to have further
integration/functional/insert-jargon-here tests which <b>do</b> actually talk to
a real database, but that isn't the case I'm talking about here.
</p>

<p>
People use different terms to describe the act of replacing the implementations
of the "database.js" functions when under test. Mocking, stubbing, sandboxing,
dependency injection - all terms I have heard people use. I am used to using
the <a href="http://www.voidspace.org.uk/python/mock/">Python Mock</a> module
for this so I tend to use "mock". I don't think it really matters.
</p>

<p>
I searched around for a few different mocking libraries, but I ended up finding things which would build
mock objects but wouldn't actually handle the cross-module dependency injection problem. For example, <a href="http://sinonjs.org/">Sinon.js</a> is great for building fake objects and then asserting that methods have been called a specific number of times or with particular arguments. However, it won't enable you to stub out module dependencies.
</p>

<p>

Eventually I stumbled upon <a href="https://twitter.com/felixge">@felixge</a>'s <a
  href="https://github.com/felixge/node-sandboxed-module">node-sandboxed-module</a>
which does exactly what I was looking for. It uses the <a href="http://nodejs.org/docs/latest/api/vm.html">Node.js VM module</a> to run a module in a totally new V8 context, and then load in replacement required modules. For example, I have a module which communicates with the Heroku HTTP API. I wish to mock out actual HTTP responses from the API so that my tests run faster and I avoid being IP banned for exceeding an API call limit. My Heroku module lives in a file called "heroku.js" and it uses <a href="https://twitter.com/mikeal">@mikeal</a>'s <a href="https://github.com/mikeal/request">Request</a> HTTP client library. So I use node-sandboxed-module to inject a <a href="https://github.com/nodejitsu/mock-request">Mock-Request</a> instance to fake out the server response:



<div class="pygments_murphy"><pre><span class="nx">it</span><span class="p">(</span><span class="s1">&#39;should correctly set the SSH key and persist details in the user object&#39;</span><span class="p">,</span>
<span class="kd">function</span><span class="p">(</span><span class="nx">done</span><span class="p">)</span> <span class="p">{</span>
  <span class="c1">// Mock the real user object with an object literal</span>
  <span class="kd">var</span> <span class="nx">user_obj</span> <span class="o">=</span> <span class="p">{</span><span class="nx">heroku</span><span class="o">:</span> <span class="p">[],</span> <span class="nx">save</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">cb</span><span class="p">)</span> <span class="p">{</span><span class="nx">cb</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="k">this</span><span class="p">)}};</span>
  <span class="c1">// Fake out the HTTP response: https://github.com/nodejitsu/mock-request</span>
  <span class="kd">var</span> <span class="nx">monkey_request</span> <span class="o">=</span> <span class="nx">mockrequest</span><span class="p">.</span><span class="nx">mock</span><span class="p">({</span>
    <span class="nx">protocol</span><span class="o">:</span> <span class="s2">&quot;https&quot;</span><span class="p">,</span>
    <span class="nx">host</span><span class="o">:</span> <span class="s2">&quot;api.heroku.com&quot;</span>
  <span class="p">})</span>
    <span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="s1">&#39;/user/keys?&#39;</span><span class="p">)</span>
    <span class="p">.</span><span class="nx">respond</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
    <span class="p">.</span><span class="nx">run</span><span class="p">();</span>
    <span class="c1">// Make the result of &quot;require(&#39;request&#39;)&quot; in the heroku module under</span>
    <span class="c1">// test be monkey_request</span>
  <span class="kd">var</span> <span class="nx">heroku</span> <span class="o">=</span> <span class="nx">sandboxed_module</span><span class="p">.</span><span class="nx">require</span><span class="p">(</span><span class="s1">&#39;../heroku.js&#39;</span><span class="p">,</span> <span class="p">{</span>
    <span class="nx">requires</span><span class="o">:</span> <span class="p">{</span><span class="s1">&#39;request&#39;</span><span class="o">:</span><span class="nx">monkey_request</span><span class="p">}</span>
  <span class="p">});</span>

  <span class="c1">// Call the function under test and assert that the expected</span>
  <span class="c1">// side-effects have been realized.</span>
  <span class="nx">heroku</span><span class="p">.</span><span class="nx">setup_account_integration</span><span class="p">(</span><span class="nx">user_obj</span><span class="p">,</span> <span class="nx">TEST_USER_API_KEY</span><span class="p">,</span>
    <span class="kd">function</span><span class="p">(</span><span class="nx">err</span><span class="p">,</span> <span class="nx">user_obj</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">user_obj</span><span class="p">.</span><span class="nx">heroku</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">api_key</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">eql</span><span class="p">(</span><span class="nx">TEST_USER_API_KEY</span><span class="p">);</span>
    <span class="nx">user_obj</span><span class="p">.</span><span class="nx">heroku</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">pubkey</span><span class="p">.</span><span class="nx">length</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">be</span><span class="p">.</span><span class="nx">above</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
    <span class="nx">user_obj</span><span class="p">.</span><span class="nx">heroku</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">privkey</span><span class="p">.</span><span class="nx">length</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">be</span><span class="p">.</span><span class="nx">above</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
    <span class="nx">user_obj</span><span class="p">.</span><span class="nx">heroku</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">account_id</span><span class="p">.</span><span class="nx">should</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/^.*@.*$/</span><span class="p">);</span>
    <span class="nx">done</span><span class="p">();</span>
  <span class="p">});</span>
<span class="p">});</span>
</pre></div>




</p>

<h3>Conclusion</h3>
<p>

Compared to other environments (Rails, Pyramid, Django, etc) there is a bit
more leg work to getting your tests started with Node.JS. Other environments
offer a bit more of a unified, pre-baked testing setup. However, it is
perfectly feasable to write a very comprehensive test suite for your
application, employing unit tests, integration tests (optionally with mocks)
and fullblown, full-stack functional tests.

</p>

<p>

I'm sure that in the relatively near future, people in the Node community will
begin settling on tools and libraries and things will consolidate a bit more.
This should make it easier for newcomers like myself to know where to start.
Tests FTW!

</p>

<p><b>Final note</b>: Make sure your application supports <a href="http://npmjs.org/doc/test.html">npm test</a> :-)</p>
]]></content:encoded>
    </item>
    <item>
      <title>$40,000 USD Funding, No Equity - Startup Chile Uncovered</title>
      <link>http://niallohiggins.com/2011/11/11/40k-usd-funding-no-equity-startup-chile-uncovered</link>
      <pubDate>Fri, 11 Nov 2011 17:04:00 PST</pubDate>
      <category><![CDATA[Startups]]></category>
      <category><![CDATA[Business]]></category>
      <guid>http://niallohiggins.com/2011/11/11/40k-usd-funding-no-equity-startup-chile-uncovered</guid>
      <description>$40,000 USD Funding, No Equity - Startup Chile Uncovered</description>
      <content:encoded><![CDATA[
<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js">
</script>

<h3>An Interview with Startup Chile Company Founder James Kennedy in Santiago</h3>

<img src="/images/startup-chile.jpg"/>

<p>
James Kennedy is the founder of Mineral Rights Worldwide. He has been a participant in the the <a href="http://www.startupchile.org">Startup Chile</a> program for over a year, and I spoke to him in detail about his experiences while visiting Santiago. You can find him on Twitter as <a href="http://twitter.com/JamesKennedy">@JamesKennedy</a>.
</p>

<p id="container1">Please install the Flash Plugin</p>

<script type="text/javascript">
    var flashvars = { file:'/interviews/james-kennedy-interview.mp3',autostart:'true' };
    var params = { allowfullscreen:'true', allowscriptaccess:'always' };
    var attributes = { id:'player1', name:'player1' };
    swfobject.embedSWF('/player/player.swf','container1','420','25','9.0.115','false',
            flashvars, params, attributes);
</script>
<br/>
[<a href="/interviews/james-kennedy-interview.mp3">Download MP3 Interview</a>]

<h3>Transcript</h3>

<p>
<b>Niall</b>: We're sitting here in a german beer hall in Santiago, Chile and I'm 
here with James Kennedy who is a fellow Irishman from Dublin, whose the 
founder of Mineral Rights Worldwide and he's doing the Startup Chile 
program. So James, tell us a bit about what you're doing here.
</p>

<p>
<b>James</b>: Ok well right now I'm working on Mineral Rights Worldwide, I've 
been here for a year and I came down as part of startup Chile last 
November, I'm kind of staying on in the place because I like it and I see 
a couple of opportunities here and now what I'm doing is building a 
mineral rights marketplace where yo ucan buy and sell gold and silver 
mines more or less. so yeah, thats what i'm doing here
</p>

<p>
<b>Niall</b>: Cool, yeah Chile have a lot of commodities and natural resources so 
it seems like it makes sense why you are doing such a thing here. So you're 
from Dublin, Ireland - tell us a bit about how you got into the program in the first place and what was attractive about Startup Chile.
</p>

<p>
<b>James</b>: Sure so about two years ago I left Ireland, I read a book called "The 4
Hour Work Week" and I wanted to work for myself, I was kinda a bootstrapper
working with my girlfriend at the time, couldn't really afford to live in
Ireland off our startup, which was PieHole.ie, which was like a marketplace for
voiceovers. So we decanted to Argentina, lived in Argentina for a while, kind
of built up the business, then we were kind of floating around - South Africa,
London, and then eventually San Fran - and it was when we were in San Fran that
I met Diego, one of the promoters of Startup Chile. He had this brand new idea
which was basically one of the fouders of the program had studied at Stanford,
he had done his MBA there, and he kind of wanted to come up with ways to
promote entrepreneurship in what is traditionally a risk averse country. So he
decided that rather than the traditional approach - you could say the Russian
approach - is to buy a big technology transfer park beside a university, and
spend a couple of billion dollars doing that, which has kind of been proven not
to work.  Because people think they can copy the Stanford model, they think, oh
Stanford was there and they had companies in a park beside it and therefore
Silicon Valley was created. But not really, thats coincidence, what really
creates it is the people not the buildings. So his idea was ok why don't you
just give a bunch of foreigners some money to come to Chile and artificially
create this startup environment, this culture of, you know, its ok to create
new business as opposed to just graduating from college and going to work for a
bank. Which is a little bit what happens down here traditionally. So anyway, he
gave us that whole pitch and he said, listen you guys should apply , we
applied, not really expecting to get accepted but we got in, so basically
within two months - I remember clearly I was sitting in a hotel room in Boulder
and two things happened in the same day. I got a tax bill for about 3 times
more than I had in my bank account and then we were about to jump out the
window and then about 40 minutes later we got a letter from Startup Chile
saying we'd been accepted. 
</p>

<p>
<b>Niall</b>: Good timing!
</p>

<p>
<b>James</b>: Exactly. So I might not be here, on the bigger scale, if it wasn't 
for Startup chile. So anyway we ditched all our plans - we were going to 
go sit on the beach in Mexico for 3 months, instead we packed up all our 
bags and arrived in the airport in Chile, and we met all the Startup Chile 
team. We were kind of half expecting for it to be some elaborate scam, 
like if it was from Nigeria I don't know, like, oh yeah, fly down here, 
will give you forty thousand dollars, and it wasn't totally like that in 
the end, by and large we did get the forty thousand dollars and we 
basically poured that into what was a kind of a dude business and it meant 
that we were able to hire a couple of people to do our sales, it meant we 
were able to take a few more risks with paid advertising, do some more 
experimentation that we couldn't afford to do and it meant now a year 
later we have four people working on it and it's doing reasonably well and 
basically my way of looking at it is it maybe sped up our progress by 
about four years, because they gave you forty grand but they didn't expect 
any equity so we basically had nothing to lose.
</p>

<p>
<b>Niall</b>: Right, well that kind of goes to the next thing, which is when I 
first heard about Startup Chile which was a couple of years ago on Tech 
Crunch or something like that, it almost seemed too good to be true - you 
know, the deal supposedly is you get forty thousand US dollars and they 
take no equity which is obviously great for anyone who wants to maintain control - 
but how does it really work? Is there any catch - could you talk a little 
bit about that?
</p>

<p>
<b>James</b>: Its not totally - they don't give you forty thousand dollars, they 
subsidise you for forty thousand dollars, and there is a subtle difference 
there. The upside is like you said they don't take any equity , the 
downside is that they basically reimburse you for the money that you spend 
- so you spend a couple of grand on this and that and then they give the 
money back to you about six weeks later. So it means that you do need to 
have a float of about 5-10k in order to come down here to start spending 
the money, but once you have that its fine. And so lon gas you're spending 
the money on legitimate business expenses - it's very much like when you 
go on a business trip and you're supposed to submit your business expenses 
when you get back - it's very much like that. Someone will look over it 
and say, ok I see that you spent money on KY jelly, how were you using 
that in your business? How did it really help you? And if you can't come 
up with a good reason then they won't give you the money back. But that 
aside, really, the point is that you're just supposed to be here.
</p>

<p>
<b>Niall</b>: So you have to spend 24 weeks in Chile, that's part of it right, so 
you have to be here for 6 months and do you necessarily have to have a 
company here or do all your founders have to be here or - details like 
that, how does that work?
</p>

<p>
<b>James</b>: No, so you don't have to register a Chilean company, although 
worldwide income for the first three years is tax free, so you may want to 
 consider doing that so you can avoid paying tax for three years, 
depending upon your own domestic tax situation. But you don't have to 
create any entity here - you can do it through any American or European 
entity you already have set up. You can send down one co-foudner, as long 
as you have someone here on the ground, you are supposed to send down a 
founder, it's not good enough to send down an employee. But you can name 
someone as a founder and send them down and they can use that money inside 
or outside the country, so you could hire developers in San Fran if you 
wanted to or you can outsource your work wherever the hell you like, just 
so long as you have an invoice. And then you're expected to basically go 
to networking events and mix with the locals, and kind of the things you 
might want to do anyway if you are looking to hire some people or make 
some contacts, so there is a little bit of expectation that you get out 
there and mingle, it's not like they fine you if you don't do that. So you 
can come here, sit in your apartment for six months and piss off 
afterwards and noone will care. And plenty of people have done that. And 
some people have come down here and just enjoyed their time here, 
networked a lot, create some connections with Chile - other people come 
down here and they're more focused, they're just hammering away all the 
time, so there's a mixture of people and I'm not really sure that one is 
more valid than the other.
</p>

<p>
<b>Niall</b>: Right, because either way you could be contributing to the scene 
here, bringing your own connections. And on a little bit of a different 
note, how've you found living here, in terms of the social life, obviously 
Spanish is the language here, is the language barrier an issue, is there 
any issue say with the banking system, you know, moving money in and out 
of the country, or regulation - how have you found all these kinds of 
things?
</p>

<p>
<b>James</b>: Well the team themselves handle all the visa stuff really well - 
within a week or two of being here I had a bank account and a visa for a 
year. So all the admin side of stuff is taken care of. Spanish, if you're 
single the best way is to find a Chilean chick or a Chilean dude to help 
you practice, and I can definitely see the people who have done that are a 
lot better at Spanish, so if that's an option, that'd be the recommended 
way to learn your Spanish. But there are plenty of schools down here. 
Obviously you can survive, I mean there's a bit of an ecosystem of English 
speaking people because of Startup Chile - you could basically not speak a 
word of Spanish for the 6 months and you could get away with it, but 
obviously it's a lot more fun if you give it a go. 
</p>

<p>
<b>Niall</b>: And what do you think of Santiago as a place to live? Cost of 
living, the kinds of amenities available. I mean I've been here for a few 
days and it seems very well run and very modern in fact. What's your 
impression having been here for a year?
</p>

<p>
<b>James</b>: Well before I came to South America I literally didn't know what to 
expect. I was expecting to like fly into a two bit airport and see two 
guys beating the crap out of donkies outside but that was obviously 
completely ignorant and when you get here you've seen yourself, it's 
basically the standard of any American city. It has fantastic transport 
system, great underground, it's a very comfortable place, it's very 
western, you can get your burger, you can get your Starbucks - it's just 
like anywhere in the world. There is a little more culture clash in that 
there's a difference between the rich and the poor here. You don't really 
see it that much but you might see it more than you'd be used to somewhere 
like London or somewhere like that. But it's definitely a very comfortable 
place to live.
</p>

<p> <b>Niall</b>: Yeah and it's very walkable too, I've been walking around a
lot on foot and it has all these beautiful parks that are all very well
maintained.  </p>

<p>
James: Yeah, and it's afterall a very rich country, they produce 60% of 
the world's copper and it means that services are very good and they have 
a lot of money to spend on services. You've probably seen a lot of the 
architecture in terms of the more modern buildings, it's pretty 
impressive, it's fancier than anything you'd see in a lot of other places. 
It's the richest place in South America and it definitely feels that way 
to be honest with you.
</p>

<p>
<b>Niall</b>: Yeah, certainly compared to Buenos Aires, you can feel there's been 
a lot more investment in the city. And so would you recommend the Startup 
Chile program to - I guess you could call them aspiring entrepreneurs? 
What kind of people should check out the program? Who do you think it 
suits?
</p>

<p>
<b>James</b>: I think there's a couple of different types of people it suits very 
well. One is if you are a tech guy and you're in the early stages of 
getting your prototype, your minimal viable product let's say, out and 
just hang out for six months and put your head down and get that done. 
Because your cost of living is going to be lower. I mean it's not super 
low compared to the rest of South America, it's like, about equivalent to 
about a mid to small-sized American city - I've heard people compare it to 
that. But of course Startup Chile give you forty grand.
</p>

<p>
<b>Niall</b>: That goes quite far.
</p>

<p>
<b>James</b>: Yeah, like you'll live off about 1,500 dollars a month quite 
comfortably, that's going out to eat whenever you want etc. So I'd 
recommend the program to tech guys who just need time to build their 
product. I would say bring your tech co-founders with you, so if you have 
a team convince them all to come down here, work here, build out the 
product - there are good designers here they'll help you with the design 
side of it or maybe some of the UX but the technical side of it - I 
wouldn't necessarily bank on finding a technical person to help you with 
it. Like I've seen people who are Biz Dev quote un quote come down here 
and kind of struggle trying to find someone to build their product. The 
other kind of group - it worked well for us, we were kind of a 
bootstrapping business, and it just meant that we were able to turn things 
up to eleven, without giving away any equity. So if you've got something 
that's making a couple of hundred or a couple of thousand dollars a month 
and you've just always wondered, well what would happen if I focused on 
this more full-time - then that would be a great thing to do as well. I 
mean they are looking for the mythical billion dollar business down here, 
and in terms of furhter funding, there are further sources of so-called 
free money, so you can get a further eighty thousand dollars of funding 
again for no equity if you have a good idea.
</p>

<p>
<b>Niall</b>: So I know that we were talking about this, you've spent several 
months in the Bay Area, and you're quite familiar with the scene there. Do 
you have any comments on how it would stack up or compare - or what's the 
opportunity cost of being here in Santiago, Chile versus say San Francisco 
, California. What are your thoughts there?
</p>

<p> <b>James</b>: Well the biggest thing for me is like, an Irish guy, when I
went to San Francisco I was just another wannabe tech guy. I was just one of
the crowd. Which is good in that there are people there with similar interests
but it is hard to stand out. Now if you compare that with down here, Startup
Chile is a far more focused group of people, ironically I've made much better
contacts with the Bay Area here in Chile than I had when I was in San Fran.
</p>

<p>
<b>Niall</b>: That's very interesting.
</p>

<p>
<b>James</b>: Because like people like yourself, you know, we met up because you 
heard I was here, we had a few beers, and that's happened several times 
where peopel are seeking me out to find out about Startup Chile. And also 
the connections you get inside Chile are pretty phenomenal. I've seen 
several people here start selling into companies here that they just 
wouldn't get a look in the door with in the States or Europe. They just 
wouldn't be able to get the meeting. But because you're part of the 
program you can get a foot in the door quite easily. One guy, he's done a 
deal with CNN Chile which means he has the CNN brand to use elsewhere, 
another guy has done a deal with like the largest retail conglomeration in 
South America. So, comparing the two, I'm getting far more out of it down 
here, because up there I'm kind of a nobody.
</p>
<p>
<b>Niall</b>: Sort of a small pond, big fish. That's a great summary and 
certainly answers a lot of my questions coming from the Bay Area. So James 
can be found as @JamesKennedy on Twitter and he's more than happy to 
answer any questions you may have. Thanks a lot James.
</p>
<p>
<b>James</b>: Cheers!
</p>
]]></content:encoded>
    </item>
    <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>MongoDB with Python, Pylons, and Pyramid at MongoSF 2011</title>
      <link>http://niallohiggins.com/2011/07/08/mongodb-python-pylons-pyramid-mongosf-2011/</link>
      <pubDate>Fri, 08 Jul 2011 17:04:00 PDT</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[MongoDB]]></category>
      <category><![CDATA[Cloud]]></category>
      <guid>http://niallohiggins.com/2011/07/08/mongodb-python-pylons-pyramid-mongosf-2011/</guid>
      <description>MongoDB with Python, Pylons, and Pyramid at MongoSF 2011</description>
      <content:encoded><![CDATA[

<h3>MongoSF 2011</h3>

<p> I was at the <a
  href="https://www.10gen.com/presentation/mongosf-2011/mongodb-with-python-pylons-pyramid">MongoSF
  2011</a> conference in May. Very much enjoyed the 1-day conference, made some
great connections and the 10gen folks hooked me up with O'Reilly to work on a
book "MongoDB and Python", which I hope to have out in a couple of months.
</p>

<h3>My talk: MongoDB with Python, Pylons, and Pyramid</h3>
<p>
I was very happy to be invited to speak at MongoSF.  <a href="https://www.10gen.com/presentation/mongosf-2011/mongodb-with-python-pylons-pyramid">My talk covers using Python with MongoDB</a>, goes into a little bit of detail on the Web frameworks Pylons and Pyramid. <a href="https://www.10gen.com/presentation/mongosf-2011/mongodb-with-python-pylons-pyramid">Watch the video</a>.
</p>
]]></content:encoded>
    </item>
    <item>
      <title>MongoDB with Python, Pyramid and Akhet</title>
      <link>http://niallohiggins.com/2011/05/18/mongodb-python-pyramid-akhet</link>
      <pubDate>Wed, 18 May 2011 12:24:00 PDT</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[MongoDB]]></category>
      <category><![CDATA[Pylons]]></category>
      <category><![CDATA[Database]]></category>
      <guid>http://niallohiggins.com/2011/05/18/mongodb-python-pyramid-akhet</guid>
      <description>MongoDB with Python, Pyramid and Akhet</description>
      <content:encoded><![CDATA[

<img src="/images/pyramid-small.png"/>
&nbsp;
<img src="/images/pylonsfw-small.png"/>
<br/>
<h2>Pylons vs Pyramid</h2>
<p>
If you weren't already aware of it, the <a
  href="http://pylonsproject.org">Pylons project</a> has recently sprouted an
all-new Python Web framework called Pyramid. Pyramid is kinda like Pylons 2.0 -
it is a completely new codebase with no code-level backwards compatibility. It
is actually based on <a href="http://bfg.repoze.org/">repoz.bfg</a>.  However, many of the concepts are very similar
to the older Pylons 1.x.
Pyramid is where all the new development is happening, and it has fantastic
code test coverage and documentation. 
</p>

<p>
You can learn more about Pyramid in the <a href="http://docs.pylonsproject.org/faq/pyramid.html">Pyramid FAQ</a>.</p>

<h2>What Is Akhet</h2>

<p> On its own, Pyramid is just a framework - a set of libraries you can use.
Projects are most easily started from a <a
href="http://docs.pylonsproject.org/projects/pyramid/1.0/narr/project.html#paster-templates-included-with-pyramid">template</a>.
A number of different templates are included, offering different persistence
options, URL mappers and session implementations.  </p>

<p>

<b>Akhet</b> is a Pyramid project template (AKA scaffold) which tries to
give you a more Pylons 1.x-like environment. Personally, I'm much more familiar
with Pylons than Pyramid and so Akhet is a great place to start.
</p>

<p>It is well worth your while <a
  href="http://docs.pylonsproject.org/projects/akhet/dev/index.html">reading
  the Akhet documentation</a>. However, the subject of this post, working with
MongoDB, takes advantage of a few changes I have made myself to <a
  href="https://bitbucket.org/niallohiggins/akhet">my Akhet fork on
  BitBucket</a>. I am hoping Mike Orr will accept my changes upstream, but for
now you will need to build the egg from my sources. I will explain how in the next section. </p>

<h2>Starting A Pyramid Project With MongoDB</h2>
<p>
First you need to create a virtual env for your project. Depending on your
platform, you should be able to install the virtualenv tool through a package
manager (sudo port install virtualenv-2.7 in Mac Ports, for example).
</p>

<h3>Install Pyramid</h3>
<p>
Once you have the virtual env tool installed, create the virtualenv, install
Pyramid and its dependencies into it:
</p>

<div class="pygments_murphy"><pre><span class="gp">$</span> mkdir ~/projects/ahket-example
<span class="gp">$</span> virtualenv --no-site-packages myenv
<span class="gp">$</span> <span class="nb">cd </span>myenv
<span class="gp">$</span> <span class="nb">source </span>bin/activate
<span class="gp">$</span> easy_install pyramid
</pre></div>




<h3>Install Akhet</h3>
<p>
Now you have Pyramid and all its dependencies installed. However, you still
need Akhet and its dependencies like PyMongo etc. We are going to use my fork
of Akhet, because it has MongoDB support at the moment.
</p>
<p>
In a new terminal, type the following (you will need Mercurial installed to
fetch the sources from BitBucket):
</p>

<div class="pygments_murphy"><pre><span class="gp">$</span> <span class="nb">cd</span> ~/projects/akhet-example
<span class="gp">$</span> hg clone https://bitbucket.org/niallohiggins/akhet
<span class="gp">$</span> <span class="nb">cd </span>akhet
<span class="gp">$</span> python setup.py sdist
</pre></div>




<p>
Now you have the Akhet with MongoDB support module available. Install it in
your virtual env (go back to original terminal, or re-source
~/projects/akhet-example/myenv/bin/activate):
</p>


<div class="pygments_murphy"><pre><span class="gp">$</span> pip install ~/projects/akhet-example/akhet/dist/Akhet-1.0.1.tar.gz
</pre></div>




<h3>Create Pyramid Project with Akhet and MongoDB Support</h3>
<p>
Okay, great - you can create your Pyramid project now! We shall call it "mongofu".
<br/>

<div class="pygments_murphy"><pre><span class="gp">$</span> <span class="nb">cd</span> ~/projects/akhet-example
<span class="gp">$</span> paster create -t akhet mongofu
<span class="go">Selected and implied templates:</span>
<span class="go">  Akhet#akhet  A Pylons-like Pyramid project</span>

<span class="go">Enter project name: mongofu</span>
<span class="go">Variables:</span>
<span class="go">  egg:      mongofu</span>
<span class="go">  package:  mongofu</span>
<span class="go">  project:  mongofu</span>
<span class="go">Enter sqlalchemy (Include SQLAlchemy configuration? (y/n)) [True]: n</span>
<span class="go">Enter mongodb (Include MongoDB configuration? (y/n)) [False]: y</span>
</pre></div>



</p>

<h3>Install Akhet Dependencies</h3>
<p>
You are just about ready to go. You need to make sure your virtual environment has all the dependencies needed by your mongofu project (e.g. the PyMongo driver). To do so run the following:

<div class="pygments_murphy"><pre><span class="gp">$</span> <span class="nb">cd </span>mongofu ; python setup.py develop
</pre></div>



</p>
<p>
Assuming all went well, you should now have a directory called "mongofu" with a
whole bunch of stuff in it. The default configuration files tell Pyramid to
connect to a MongoDB server on <b>localhost</b>, and a database called
<b>mydb</b>. If you need to change that, simply edit the <b>mongodb.url</b> and
<b>mongodb.db_name</b> settings in the INI-files.
</p>

<h3>Start The Development Server</h3>
<p>
Now try starting up a development server:


<div class="pygments_murphy"><pre><span class="gp">$</span> paster serve development.ini
</pre></div>




If things are working correctly, you should see a message like this on your terminal:

<div class="pygments_murphy"><pre><span class="go">Starting server in PID 6020.</span>
<span class="go">serving on http://127.0.0.1:5000</span>
</pre></div>



</p>

<h2>Talking to MongoDB with Pyramid/Akhet</h2>
<p>

Now you are ready to write some MongoDB queries! Edit the file <b>mongofu/handlers/main.py</b>.

<br/>

In the Main class, we can add a simple query to the "index" action method, referencing the <b>request.db</b> property - which is a handle to our MongoDB database:


<div class="pygments_murphy"><pre><span class="k">class</span> <span class="nc">Main</span><span class="p">(</span><span class="n">base</span><span class="o">.</span><span class="n">Handler</span><span class="p">):</span>
    <span class="nd">@action</span><span class="p">(</span><span class="n">renderer</span><span class="o">=</span><span class="s">&quot;index.html&quot;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">index</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c"># Do some logging.</span>
        <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s">&quot;testing logging; entered Main.index()&quot;</span><span class="p">)</span>
        <span class="c"># MongoDB Query</span>
        <span class="c"># can just as easily write request.db.mycollection.find()</span>
        <span class="n">records</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">db</span><span class="p">[</span><span class="s">&#39;mycollection&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">find</span><span class="p">()</span>
        <span class="c"># Push a flash message if query param &#39;flash&#39; is non-empty.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">params</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;flash&quot;</span><span class="p">):</span>
            <span class="kn">import</span> <span class="nn">random</span>
            <span class="n">num</span> <span class="o">=</span> <span class="n">random</span><span class="o">.</span><span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">999999</span><span class="p">)</span>
            <span class="n">message</span> <span class="o">=</span> <span class="s">&quot;Random number of the day is:  </span><span class="si">%s</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="n">num</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">flash</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
            <span class="c"># Normally you&#39;d redirect at this point but we have nothing to</span>
            <span class="c"># redirect to.</span>
        <span class="c"># Return a dict of template variables for the renderer.</span>
        <span class="k">return</span> <span class="p">{</span><span class="s">&quot;project&quot;</span><span class="p">:</span><span class="s">&quot;mongofu&quot;</span><span class="p">}</span>
</pre></div>



</p>

<p>
As you can see, we specify a collection in that database to query against. We're not doing anything with the results, but that is enough to demonstrate how to talk to MongoDB with Pyramid and Akhet.
</p>


</p>


]]></content:encoded>
    </item>
    <item>
      <title>New Samsung Android Tabs - iPad killers?</title>
      <link>http://niallohiggins.com/2011/03/22/new-samsung-android-tabs-ipad-killers/</link>
      <pubDate>Tue, 22 Mar 2011 19:46:00 PDT</pubDate>
      <category><![CDATA[Tablet]]></category>
      <guid>http://niallohiggins.com/2011/03/22/new-samsung-android-tabs-ipad-killers/</guid>
      <description>New Samsung Android Tabs - iPad killers?</description>
      <content:encoded><![CDATA[

<h3>Samsung Android Honeycomb Tablets: iPad Killers?</h3>

<p> Today <a href="http://www.samsungunpacked.com/">Samsung announced</a> a
redesigned Galaxy Tab 10.1 and 8.9. After the iPad2 announcement earlier this
month pretty much killed the first round of over-priced, under-achieving
  Android tablets</a> (here's looking at you, $800 Xoom) it is great to see
Samsung coming out with a much more competitive offering.  </p>

<h3>Competitive Tablet Pricing</h3>

<p> One of the most disappointing things about the Motorola Xoom was simply the
rather insane $800 price tag. The Xoom is a nice piece of hardware don't get me
wrong, but there is no way to justify the 60% higher price over the entry-level
16G iPad2.  While they're releasing a $599 32G WiFi-only version in the next
couple of weeks - which is somewhat competitive with the $599 32G iPad 2 - it
feels like too little too late.  </p>

<p>Furthermore, the honest truth is that Honeycomb isn't yet ready for
primetime - with a shortage of apps and a beta-quality OS that often
experiences crashes. Of course, Google are going to fix those bugs over the
coming months and slick, native Honeycomb apps are under frantic development at
this very moment. Still though, that doesn't change the situation today:
Tablets are all about the apps, and it is hard to ignore the 1 year head-start
of the Apple iPad tablet app ecosystem.</p>

<p>For this reason, it is fantastic to see Samsung understand that they simply
cannot charge more than Apple and are releasing models at $499 and $469 for 16G
WiFi-Only 10.1" and 8.9" tabs respectively.</p>

<h3>Form Factor</h4>

<img src="/images/samsung-tab-89.jpg" />

<p>
I find it refreshing to see Samsung releasing an 8.9" tab in addition to the more iPad-like 10.1" offering. I've found the 7" Nook Color to be a real joy to hold with one hand unlike iPad and Xoom which are just a bit too big for that. Am hopeful that the 8.9" model is just about right for one-handed use also.
</p>

<h3>Display Technology</h3>

<img src="/images/super-pls.jpg" />

<p>Samsung are well-known for their screen technology and their latest
development is Super PLS or Plane-to-Line-Switching for LCD displays. Compared
to current In-Plane-Switching (IPS) panels, as found in the Motorola DROID or
the iPad 2, Super PLS displays offer about a 100% improvement in viewing angles
and a 15% improvement in brightness. Furthermore, they are available in
1280x800 resolution as opposed to the iPad 2's lower 1024x768.</p>

<p>It will be interesting to see if the screen alone could make the Samsung
devices quite a bit more compelling. Apple has already been receiving criticism
for giving the iPad 2 the same display as their first-gen iPad instead of
offering Retina Display which they feature in their iPhone 4.</p>


<h3>Video playback: Tegra 2 or Exynos?</h3>
<img src="/images/samsungexynos.jpg" />
<p>
As I wrote in my previous article, <a href="http://niallohiggins.com/2011/03/07/3-surprising-things-about-video-on-android-tablets/">3 Surprising Things About Video On Android Tablets</a>, video is an obvious killer app for tablets but the Tegra 2 chip used in many of the Honeycomb devices has some severe limitations in video playback.
</p>

<p>I speculated in that post that Samsung's then-rumoured 8.9" device might use
their own Exynos CPU in place of Tegra 2 and it appears that may now indeed be
the case.  Samsung have so far been vague about the specifics of what chip they
are putting into the device saying only that it has a dual-core processor.
Analysts suspect this is due to shortages in their own CPU which may be made up
on a per-region basis by some models having Tegra 2.</p>

<p>If the 8.9" Galaxy Tab does ship with Exynos as opposed to Tegra 2 and
carries DivX certification, that could make it a far superior device for video
playback. It would beat both the current crop of Honeycomb tablets in addition
to the Apple iPad2 as much more efficient video streams would be supported.
Beyond higher quality streaming, it would also largely eliminate the need for
time consuming and tedious re-encoding of video files prior to playback on the
device.</p>

<h3>Conclusion</h3>
<p>
To wrap up, the Samsung announcement today is certainly exciting. The Samsung devices look like they are shaping up to be competitive with Apple's iPad2 in industrial engineering, features and price.</p>
<p>
However, with a June 8th US release date for the 10.1" model and a still-vague date for the more interesting 8.9" tab we are still left with quite a wait for a truly compelling and competitive Honeycomb offering.</p>
]]></content:encoded>
    </item>
    <item>
      <title>MongoDB + Pylons at PyCon 2011</title>
      <link>http://niallohiggins.com/2011/03/18/mongodb-pylons-pycon-2011/</link>
      <pubDate>Fri, 18 Mar 2011 17:04:00 PDT</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[MongoDB]]></category>
      <category><![CDATA[Cloud]]></category>
      <guid>http://niallohiggins.com/2011/03/18/mongodb-pylons-pycon-2011/</guid>
      <description>MongoDB + Pylons at PyCon 2011</description>
      <content:encoded><![CDATA[

<h3>PyCon 2011</h3>

<p> I was at the awesome <a href="http://us.pycon.org/2011/home/">PyCon
  2011</a> last week, where I had a fantastic time. Really great conference -
tons of incredible talks and wonderful conversation. Definitely the best
technical conference I've attended. Everyone I met was super friendly,
down-to-earth and just all-around fun.  </p>

<p> Had the pleasure to hang out with the Pylons/Pyramid crew who are a great
bunch. I will certainly be going in 2012, when the event is scheduled to be
held in Santa Clara. Plan to stay for the sprints next time!</p>

<h3>My talk: MongoDB + Pylons at Catch.com</h3>
<p>
I was very happy to be able to present a talk on some of my work at <a href="https://catch.com">Catch.com</a>, where I designed and implemented the platform backend using Pylons and MongoDB. The video of my talk is embedded below:
</p>
<embed src="http://blip.tv/play/g4VigquDWAI%2Em4v" type="application/x-shockwave-flash" width="500" height="405" allowscriptaccess="always" allowfullscreen="true"></embed>
]]></content:encoded>
    </item>
    <item>
      <title>3 Surprising Things About Video On Android Tablets</title>
      <link>http://niallohiggins.com/2011/03/07/3-surprising-things-about-video-on-android-tablets/</link>
      <pubDate>Mon, 07 Mar 2011 11:13:00 PST</pubDate>
      <category><![CDATA[Mobile]]></category>
      <category><![CDATA[Android]]></category>
      <category><![CDATA[Tablet]]></category>
      <guid>http://niallohiggins.com/2011/03/07/3-surprising-things-about-video-on-android-tablets/</guid>
      <description>3 Surprising Things About Video On Android Tablets</description>
      <content:encoded><![CDATA[

<h3>Video: An Obvious Killer App for Tablets</h3>
<br/>
<img src="/images/ipad-netflix.jpg" width="320" height="200" />
<p>
After a decade or so of various failed or underwhelming attempts, it is now
blatantly obvious that Apple kicked off the consumer tablet revolution with
their launch of iPad in 2010. By getting the hardware, pricing, UI and
application ecosystem right, they have managed to sell 15 million units in 2010
alone (April - December), bringing in $9.5 billion.
</p>

<p>An obvious killer app for this kind of device is video. At the distance you hold a tablet it has the same apparent size as a massive TV screen. The easy-to-hold
and carry form factor, the long battery life, the high quality screen and
speakers - and apps like <a
  href="http://www.hulu.com/plus">Hulu Plus</a>, <a
  href="http://blog.netflix.com/2010/04/netflix-available-on-ipad.html">Netflix</a>,
<a href="http://mashable.com/2010/04/01/abc-cbs-ipad/">ABC and CBS</a> pretty
much have the TV and movie situation covered, with more services and apps
coming all the time, to both iOS and Android devices.
</p>

<p>
In the not-too-distant future, practically everyone will have a tablet, and everyone will want to watch video on them. Awesome!
</p>

<h3>1) NVIDIA Tegra2 Chip Performance Surprises: Not What They Claim To Be</h3>
<br/>
<img src="/images/tegra2.jpg" />

<p>
You've probably noticed the recent explosion in Android handsets and tablets
powered by the NVIDIA Tegra 2 chip. It offers extremely impressive performance
with a dual core ARM Cortex-A90 clocked at 1Ghz, and powers the latest devices
including the Motorola Xoom, Atrix, Bionic and Samsung Galaxy Tab 10.1 along
with a host of others just-released or near-release.
</p>

<p>
<b>Tegra 2's Dirty Little Secret</b>
<br/>
What you may not be aware of amidst all the marketing is how poorly these Tegra
2 chips decode video. Tegra 2 is not capable of playing just any old video format. While technically it supports H.264 at 720p and 1080p, it <b>specifically only supports the "Baseline" profile</b> which means two reference frames and no B frames.
</p>
<p>

This means you must take your existing HD video files and re-encode them into a
special format using a program like <a
  href="http://handbrake.fr/">handbrake</a>. According to <a href="http://www.anandtech.com/show/4144/lg-optimus-2x-nvidia-tegra-2-review-the-first-dual-core-smartphone/14">Anandtech</a>, that puts a 2 hour movie at around 8 GB - too big to fit as a single file on a typical microSD card formatted with FAT32.
</p>

<p>Additionally, with those kinds of space requirements, streaming 1080p HD
video for viewing on your device quickly becomes extremely bandwidth intensive
(~10mbps). Almost certainly too high for most consumer Internet
connections - <a href="http://www.dslreports.com/shownews/Akamai-US-16th-In-Broadband-Speed-109597">according to DSL reports</a> average Internet connection speed in USA is 4.7Mbps.</p>

<p>
In other words, your brand spanking new, top-of-the-line 2011 dual core 1Ghz tablet cannot simply play any 720p/1080p HD video file you throw at it. Unlike a cheap PC or media center, in order to watch video on your shiny new Tegra 2-based tablet
you:

<ul>
  <li>Almost certainly will have to re-encode your video specially for the device.</li>
  <li>Need a ton of storage space, approx. 8G per movie, possibly having the video split across multiple files.</li>
  <li>If streaming true HD video in 1080p baseline profile, need a very fast (~10mbps) Internet connection. (FWIW <a href="http://iplayerhelp.external.bbc.co.uk/help/playing_tv_progs/watch_hd">BBC iPlayer HD streams are 720p @ 3.2 MBPS</a>. These HD streams are not available on iPad since that only supports baseline too!)</li>
</ul>
</p>

<p>
Ouch! Rumour suggests this is one of the reasons why HTPC (Home Theater PC) manufacturer Boxee ditched the Tegra 2 platform for the Intel Atom.
</p>

<p>
<h3>2) Samsung's Hummingbird CPU: DivX Certification</h3>
</p>
<img src="/images/samsung_galaxy_s_divx_certified.jpg" />
</p>
<p>
An interesting tidbit about Samsung's Android devices: Many of them - including
7" Galaxy Tab and the Galaxy S phone - are DivX certified! What does this mean?
It means they can play pretty much any old HD video file (<a href="http://forum.xda-developers.com/showthread.php?t=700644">at least 720p high profile</a>) you throw at them without the friction of painful, space-wasting conversion processes!
</p>
<p>
What about the soon-to-be-released Galaxy Tab 10.1? We don't know exactly,
however all information so far suggests it will be powered by the same NVIDIA
Tegra 2 chip. Unless Samsung does something custom, this device will have the
same video limitations as the Motorola Xoom.
</p>
<p>
However, there is speculation that the other tablets Samsung is planning - in particular an 8.9" device - may use the next generation Samsung CPU named Exynos. This dual-core CPU could well have the same DivX certification as the Hummingbird devices, offering these devices superior video playback capabilities compared to Tegra 2.
</p>
<p>
This may mean that consumers interested in good video playback support should hold off on the otherwise very promising Galaxy Tab 10.1 and wait for an Exynos-powered device instead.
</p>

<p>
<h3>3) Tegra 2 Honeycomb Exclusivity: But Won't Last Long</h3>
</p>
<img src="/images/android-honeycomb-logo.jpg" />
<p>
Android 3.0 AKA Honeycomb is the first tablet-optimized version of the OS. If
you want to be able to truly take advantage of the extra screen real estate
afforded by the tablet form-factor, you will want a device with Honeycomb.
</p>
<p>
The first round of Android 3.0 tablets are all powered by Tegra 2. According to the <a href="http://mobile-device.biz/content/item.php?item=29042">SVP of Cellular Products at Qualcomm</a> the reason for this is that Google partnered with Motorola on the initial launch devices. For whatever reason, Motorola chose Tegra. However, Honeycomb will soon be ported to and running on processors from other vendors.
</p>
<p>
As soon as Google open-sources Honeycomb, we should see a flood of Android 3.0 tablets from vendors like Acer, Asus, HTC, Samsung and others with much better video playback support - which means much better value for consumers!
</p>
]]></content:encoded>
    </item>
    <item>
      <title>PyMongo 1.7 and MasterSlaveConnection - TypeError breakage</title>
      <link>http://niallohiggins.com/2010/06/22/pymongo-1-7-and-masterslaveconnection-typeerror-breakage/</link>
      <pubDate>Tue, 22 Jun 2010 10:36:01 PDT</pubDate>
      <category><![CDATA[Python]]></category>
      <guid>http://niallohiggins.com/?p=874</guid>
      <description>PyMongo 1.7 and MasterSlaveConnection - TypeError breakage</description>
      <content:encoded><![CDATA[
<img src="http://api.mongodb.org/wiki/current/attachments/132305/1605653.png" alt="mongodb logo" />

<p>
<b>MasterSlaveConnection: Works in Pymongo 1.6</b>
<br/>
In my previous article <a href="http://niallohiggins.com/2010/06/20/python-mongodb-and-pylons-connection-handles-and-all-that-lark/">Python, MongoDB and Pylons,
Connection handles and all that lark</a> I described the code and configuration we use at <a href="http://snaptic.com">Snaptic</a> for working with Pylons and MongoDB. We use the MasterSlaveConnection class to automatically handle read/write splitting, because we expect to be running a single master/multiple slaves configuration in production.
</p>

<p>
<b>Broken in Pymongo 1.7</b>
<br/>
Well, yesterday I upgraded from <a href="http://pypi.python.org/pypi/pymongo">Pymongo</a> 1.6 to Pymongo 1.7 (just released) and found that unfortunately all the MongoDB stuff breaks, throwing TypeError exceptions when issuing even a simple <i>find_one()</i> query. You will see an error like this one:
<code>
TypeError: 'Database' object is not callable. If you meant to call the 'document_class' method on a 'Collection' object it is failing because no such method exists.
</code>
</p>

<p>
<b>But fixed in tip</b>
<br/>
After talking with <a href="http://dirolf.com/">Mike Dirolf</a> (Pymongo author) on the MongoDB IRC channel, he came up with a fix within a few minutes. Although I don't think its in a release yet, if you grab <a href="http://github.com/mongodb/mongo-python-driver/commit/8b76667b4250187a31e6b12df67f4497fc93991d">this commit to Pymongo from github</a>, MasterSlaveConnection should work again. He also <a href="http://jira.mongodb.org/browse/PYTHON-136">filed this bug</a> to come up with a more general solution. Cheers to Mike for his super quick turnaround on fixing the bug!
</p>
]]></content:encoded>
    </item>
    <item>
      <title>Python, MongoDB and Pylons - Connection handles and all that lark</title>
      <link>http://niallohiggins.com/2010/06/20/python-mongodb-and-pylons-connection-handles-and-all-that-lark/</link>
      <pubDate>Sun, 20 Jun 2010 16:35:43 PDT</pubDate>
      <category><![CDATA[Python]]></category>
      <guid>http://niallohiggins.com/?p=856</guid>
      <description>Python, MongoDB and Pylons - Connection handles and all that lark</description>
      <content:encoded><![CDATA[
<img src="http://api.mongodb.org/wiki/current/attachments/132305/1605645.png" alt="mongodb logo" />

<p> I've been doing a bunch of hacking with <a
href="http://www.pylonshq.com">Pylons</a> and <a
href="http://www.mongodb.org/">MongoDB</a> recently for some backend stuff at
<a href="http://snaptic.com">Snaptic</a>. Right now we are using <a
href="http://pythonpaste.org/paste-httpserver-threadpool.html">Paster</a> as
the webserver and the <a
href="http://pypi.python.org/pypi/pymongo/">Pymongo</a> driver. This all works
fine and is pretty straightforward to set up - but there are a couple of
subtleties.  </p>

<b>MongoDB vs SQLAlchemy</b>

<p>
If you've ever used Pylons with <a href="http://www.sqlalchemy.org/">SQLAlchemy</a>, then you've probably noticed the integration is quite good. All of the glue to get access via the global Session object is done for you. With MongoDB and Pylons, the integration isn't quite there yet. You have to set this up yourself.
</p>

<b>Gotta have some replication</b>

<p>
MongoDB doesn't give you the <a href="http://www.mongodb.org/display/DOCS/Durability+and+Repair">same kind of single-server durability guarantees</a> that a RDBMS like MySQL or PostgreSQL does, so you pretty much <a href="http://www.mongodb.org/display/DOCS/Master+Slave">have to use some kind of replication</a> in production. I'm expecting a master/slave configuration, and Pymongo has <a href="http://api.mongodb.org/python/1.6%2B/api/pymongo/master_slave_connection.html#pymongo.master_slave_connection.MasterSlaveConnection">native support for read/write splitting</a> (writes go to the master, reads go to the slave(s)), so I've used that in my Pylons integration code.
</p>

<b>Getting a handle to the database</b>

<p>
The basic idea is that you define a list of masters and slaves in your Pylons config file, and some code in lib/app_globals.py sets up a global handle to the connection object.
</p>

<p>
Here is what I have at the moment, in the <i>__init__</i> method in lib/app_globals.py:
</p>

<pre lang="python" line="1'>
# ... non-pymongo imports omitted
from pymongo import Connection
from pymongo.master_slave_connection import MasterSlaveConnection
from pymongo.errors import ConnectionFailure

# ... class definition, __init__ method etc omitted for brevity ...

# assumption is a master/slave setup for initial production deployment.
# writes should go to the master
# reads should go to the slave(s)
# with sharding, this may change.
def make_conn(host, port, database, username=None, password=None,
        slave_okay=False):
    try:
        conn = Connection(host, port, slave_okay=slave_okay)
    except ConnectionFailure:
        raise Exception('Unable to connect to MongoDB')
    if username and password:
        auth = conn.authenticate(username, password)
        if not auth:
            raise Exception('Authentication to MongoDB failed')
    return conn

username = None
password = None
if 'mongo.username' and 'mongo.password' in config:
    username = config['mongo.username']
    password = config['mongo.password']
master_conn = make_conn(config['mongo.master_host'],
        int(config['mongo.master_port']), username, password)
slaves = []
for i, slave_host in enumerate(config['mongo.slave_hosts'].split(',')):
    slave_port = int(config['mongo.slave_ports'].split(',')[i])
    slave_conn = make_conn(slave_host.strip(), slave_port,
            username, password, slave_okay=True)
    slaves.append(slave_conn)

self.db_conn = MasterSlaveConnection(master_conn, slaves)
self.db = self.db_conn[config['mongo.db']]
</pre>

Then in <i>development.ini</i> I have:

<pre lang="ini" line="1">
# in production, we will write to the master and read from the slaves
mongo.master_host = localhost
mongo.master_port = 27017
# to supply multiple slaves, use comma as the separator.
mongo.slave_hosts = localhost
mongo.slave_ports = 27017

mongo.db = foo

</pre>

Now, to get a handle to the db object from a controller context, you just do the following:

<pre lang="python" line="1">
db = self._py_object.app_globals.db
# now I can go wild and run:
# db.fooCollection.find_one()
</pre>

If you need a handle to the connection object instead, no problem:

<pre lang="python" line="1">
db_conn = self._py_object.app_globals.db_conn
# now I can run:
# db_conn.end_request() if I want.
</pre>

There might be more elegant ways to do this, but this seems to work fine for us. I will write about connection pooling and end_request() next time. Feel free to comment if I left anything out or you have questions!
]]></content:encoded>
    </item>
  </channel>
</rss>

