<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PyRuby blog &#187; geek</title>
	<atom:link href="http://www.pyruby.com/category/geek/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pyruby.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 12 Dec 2011 11:03:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>HTML 5 Canvas game &#8211; Test Driven</title>
		<link>http://www.pyruby.com/2010/06/08/html-5-canvas-game/</link>
		<comments>http://www.pyruby.com/2010/06/08/html-5-canvas-game/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 05:00:35 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[card game]]></category>
		<category><![CDATA[html5 canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[zen zombie]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=83</guid>
		<description><![CDATA[<p></p>
<p>I&#8217;ve been busy for the last month, working with a couple of friends to put together an online version of Ninja Pirate Zombie Robot.  This was initially going to be an iPhone app, written in Objective C, but after further consideration, we decided to write it using HTML 5 canvas.</p>
<p>The libraries we are using [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://zenzombie.com/wordpress/wp-content/uploads/2010/05/4heads.png" alt="Ninja Pirate Zombie Robot" /></p>
<p>I&#8217;ve been busy for the last month, working with a couple of friends to put together an online version of <a href="http://zenzombie.com/games/ninja-pirate-zombie-robot/">Ninja Pirate Zombie Robot</a>.  This was initially going to be an iPhone app, written in Objective C, but after further consideration, we decided to write it using HTML 5 canvas.</p>
<p>The libraries we are using for our JavaScript card game are <a href="http://jsunittest.com/">JSUnitTest</a>, <a href="http://github.com/kangax/protolicious/blob/master/event.simulate.js">event.simulate.js</a> and <a href="http://www.prototypejs.org/">JS Prototype</a>.  The choices here are largely due to our experience of writing test driven, object oriented code as our day jobs.  This was our first game, so this post may not reflect the very best way to write an HTML5 game, so if there are things we could improve on, please let me know.</p>
<h3>Test first</h3>
<p>This article will just cover our initial set up.  I&#8217;ll write a subsequent article on tips and tricks we learnt along the way.  First we set up a test case using JSUnitTest.  This comprised of 3 files.</p>
<p>HTML web page which runs and displays the results of the tests</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;html&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;title&gt;JavaScript unit test file&lt;/title&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;script src=&quot;../lib/jsunittest.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;script src=&quot;../lib/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;script src=&quot;../lib/event.simulate.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;script src=&quot;../src/game.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &lt;link rel=&quot;stylesheet&quot; href=&quot;unittest.css&quot; type=&quot;text/css&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/head&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div id=&quot;content&quot;&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;div id=&quot;header&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;h1&gt;Ninja Pirate Zombie Robot unit test file&lt;/h1&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;!&#8211; Log output (one per Runner, via {testLog: &quot;testlog&quot;} option)&#8211;&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &lt;p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Running &lt;strong&gt;test_game.js&lt;/strong&gt;.
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;/p&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &lt;div id=&quot;game&quot;&gt;&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;script src=&quot;test_game.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &lt;/body&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/html&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>The TestCase</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">new</span> Test.<span class="me1">Unit</span>.<span class="me1">Runner</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; setup: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">game</span> = <span class="kw2">new</span> Game<span class="br0">&#40;</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; teardown: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">game</span> = <span class="kw2">null</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; testGameStartsWith2Players: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw1">with</span><span class="br0">&#40;</span><span class="kw1">this</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; assertEqual<span class="br0">&#40;</span><span class="nu0">2</span>, game.<span class="me1">players</span>.<span class="me1">length</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>, <span class="br0">&#123;</span> testLog: <span class="st0">&quot;game&quot;</span><span class="br0">&#125;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
</ol>
</div>
<p>And the bare minimum initial game code</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Game = <span class="kw2">Class</span>.<span class="me1">create</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; initialize: <span class="kw2">function</span><span class="br0">&#40;</span>options<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">players</span> = <span class="br0">&#91;</span><span class="br0">&#93;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>This was our starting point for our game, which yielded one failing test.  We decided to build the rules of the game first, before dealing with the rendering and computer player components.  Given that we wouldn&#8217;t have the chance to pair on most of the code, we wanted to get the central domain model for the game sorted, so we could then work on other parts in parallel.</p>
<p>In my next post, I&#8217;ll cover defining the game domain model, which encapsulates all the rules of the game.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2010/06/08/html-5-canvas-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scala JSON Generator</title>
		<link>http://www.pyruby.com/2010/04/29/scala-json-generator/</link>
		<comments>http://www.pyruby.com/2010/04/29/scala-json-generator/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 05:56:08 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[dsl]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=72</guid>
		<description><![CDATA[<p>I am working with Scala more and more at the moment.  I find it a really powerful and fun language to work in.  One of the recent tasks has been to translate various tab delimited data files into a common JSON format.  In java land, I&#8217;ve used Jackson to great effect, but [...]]]></description>
			<content:encoded><![CDATA[<p>I am working with <a href="http://www.scala-lang.org/">Scala</a> more and more at the moment.  I find it a really powerful and fun language to work in.  One of the recent tasks has been to translate various tab delimited data files into a common JSON format.  In java land, I&#8217;ve used <a href="http://jackson.codehaus.org">Jackson</a> to great effect, but it really doesn&#8217;t feel very Scala.  My colleague and I were busy following the Jackson route and had a working implementation, but it just didn&#8217;t feel clean, simple and Scala idiomatic.  That&#8217;s when we decided to define how we thought the api should work.</p>
<p>One of the great things about using Scala, is it&#8217;s a fantastic language for creating <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSLs</a>.  When I really don&#8217;t like the way the code that solves a specific problem looks, I like to write the pseudo code that feels right, and then figure out how to make that work.  With Scala, I have had a great deal of success in this approach.  We started off defining a JSON generator DSL that looked like this:-</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">def mapToJson(myMap: Map[String, String]) = {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; val json = jsonObject {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; field(&quot;cheese&quot;, myMap.get(&quot;name&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; jsonObject(&quot;Score&quot;) {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; field(&quot;aroma&quot;, myMap.get(&quot;smell&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; field(&quot;flavor&quot;, myMap.get(&quot;taste&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; field(&quot;texture&quot;, myMap.get(&quot;squidginess&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; jsonArray(&quot;servedOn&quot;) {
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; jsonObject {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; field(&quot;cracker&quot;, myMap.get(&quot;crackerType&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; field(&quot;maker&quot;, myMap.get(&quot;crackerMaker&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; jsonArray(&quot;sampledOn&quot;) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;firstTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;secondTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; value(myMap.get(&quot;thirdTried&quot;)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li2">
<div class="de2">}</div>
</li>
</ol>
</div>
<p>There was another case for jsonArray, which doesn&#8217;t involve having a field name, i.e. jsonArray { &#8230; }.  Whilst attempting to find a way to implement the DSL that would satisfy this, we had to make a small compromise.  The call jsonObject {&#8230;} and jsonObject(&#8220;fieldName&#8221;) {&#8230;} caused problems because the signatures of the DSL methods were indistinguishable when using them.  The compromise we struck on was jsonObject() {&#8230;} and jsonObject(&#8220;fieldName&#8221;) {&#8230;}, i.e. just adding the empty parenthesis.  This then is the resulting syntax, and the implementation can be found <a href="http://github.com/jtownley/Scala-Json-Generator">here</a>.  </p>
<p>This is a first cut, but as this library was introduced to solve a problem in our production app.  It will be tweaked and maintained so any bugs or extra features will quickly get incorporated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2010/04/29/scala-json-generator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stubserver 0.1 released</title>
		<link>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/</link>
		<comments>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 04:03:41 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[mock]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=63</guid>
		<description><![CDATA[<p>I&#8217;ve released a python stub webserver, described in an earlier blog post, on pypi.  The features include support for any method (i.e. PUT, POST, DELETE, GET, RHUBARB &#8230;), handles chunked encoding, and supports capturing data passed for later assertions.  </p>
<p>Because it&#8217;s on pypi, you can install using:-</p>
<p>pip install stubserver</p>
<p>or</p>
<p>easy_install stubserver</p>
<p>The verification model is [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released a python stub webserver, described in an earlier <a href="http://www.pyruby.com/2009/11/22/testing-against-a-stub-web-server/">blog post</a>, on <a href="http://pypi.python.org/pypi/stubserver">pypi</a>.  The features include support for any method (i.e. PUT, POST, DELETE, GET, RHUBARB &#8230;), handles chunked encoding, and supports capturing data passed for later assertions.  </p>
<p>Because it&#8217;s on pypi, you can install using:-</p>
<p><code>pip install stubserver</code></p>
<p>or</p>
<p><code>easy_install stubserver</code></p>
<p>The verification model is very simplistic, each registered expectation is only expected to occur once.  To get more details, please refer to the <a href="http://www.pyruby.com/pythonstubserver/">documentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2010/02/23/stubserver-0-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing against a Stub Web Server</title>
		<link>http://www.pyruby.com/2009/11/22/testing-against-a-stub-web-server/</link>
		<comments>http://www.pyruby.com/2009/11/22/testing-against-a-stub-web-server/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 04:57:48 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=49</guid>
		<description><![CDATA[<p>I wrote recently about improving the way I usually create a stub web server for testing my applications that call out to external web services.  This is a particularly common occurrence where I work (Point2) because we have separated out our core services which are interacted with through REST apis.  As I&#8217;ve mentioned [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote recently about improving the way I usually create a stub web server for testing my applications that call out to external web services.  This is a particularly common occurrence where I work (<a href="http://www.point2.com">Point2</a>) because we have separated out our core services which are interacted with through REST apis.  As I&#8217;ve mentioned before, this was what started the <a href="http://djangorestmodel.sourceforge.net">Django REST models</a> open source project.</p>
<p>Well, I&#8217;ve written the code to effectively support the previously described testing api.  It is currently part of the above project, and can be found <a href="https://djangorestmodel.svn.sourceforge.net/svnroot/djangorestmodel/test_web.py">here</a>.  It has already proved handy in adding a much needed functional test capability for Django REST models, which has already exposed a bug in the awkward to test rest_client code.  As an example, here is the test:-</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">class</span> FunctionalTest<span class="br0">&#40;</span><span class="kw3">unittest</span>.<span class="me1">TestCase</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">def</span> setUp<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">server</span> = StubServer<span class="br0">&#40;</span><span class="nu0">8998</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">server</span>.<span class="me1">run</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">def</span> tearDown<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">server</span>.<span class="me1">stop</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">server</span>.<span class="me1">verify</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="kw1">def</span> test_get_with_file_call<span class="br0">&#40;</span><span class="kw2">self</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">server</span>.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;GET&quot;</span>, url=<span class="st0">&quot;/address/<span class="es0">\w</span>+$&quot;</span><span class="br0">&#41;</span>.<span class="me1">and_return</span><span class="br0">&#40;</span>mime_type=<span class="st0">&quot;text/xml&quot;</span>, content=<span class="st0">&quot;&lt;address&gt;&lt;number&gt;12&lt;/number&gt;&lt;street&gt;Early Drive&lt;/street&gt;&lt;city&gt;Calgary&lt;/city&gt;&lt;/address&gt;&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; address = Address.<span class="me1">objects</span>.<span class="me1">get</span><span class="br0">&#40;</span>city=<span class="st0">&quot;Calgary&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">assertEquals</span><span class="br0">&#40;</span><span class="st0">&quot;Early Drive&quot;</span>, address.<span class="me1">street</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>With the expanding usage of REST services, and a growing number of Python applications written against those services, this project is starting to gather pace again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/11/22/testing-against-a-stub-web-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why I write Python</title>
		<link>http://www.pyruby.com/2009/11/05/why-i-write-python/</link>
		<comments>http://www.pyruby.com/2009/11/05/why-i-write-python/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 05:12:56 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=44</guid>
		<description><![CDATA[Why do you write Python?  Because it's [...]]]></description>
			<content:encoded><![CDATA[<p>I read an interesting thread asking <a href="http://groups.google.com/group/comp.lang.python/browse_thread/thread/66ccb10d2da5b740">why do you use Python</a>.  I&#8217;ve been using several languages recently, including Python, and this has been a recurring question.  There is much commonality in the responses of others</p>
<ul>
<li>It makes me more productive by removing boiler-plate code.</li>
<li>There are many good libraries for Python which are very consistent, making it easy to produce complex applications with few lines of code.</li>
<li>Meta programming techniques such as missing method and metaclasses make producing sophisticated frameworks easy.</li>
</ul>
<p>These are all interesting points, but none of these things are the real reason I write Python code in preference to Java, Scala, Groovy or Ruby.  The primary reason for me, is that I really enjoy writing Python applications.  I think in a Pythonic way, so writing Python applications is intuitive and enjoyable.  I rarely need to battle with the language to acheive what I want to do.  A common question that gets asked is &#8220;What can Python do that you can&#8217;t do in Language X?&#8221;.  The answer is usually &#8220;Nothing, provided you are prepared to write enough code, you can solve all the same problems.  It&#8217;s just I enjoy writing Python, which means I am more engaged in solving the business problem, and therefore able to consistently get the job done faster, better, and with a greater level of satisfaction in the solution&#8221;.</p>
<p>I know this isn&#8217;t a scientific answer to the question, but writing software is a job done by people who aren&#8217;t mechanised robots.  People need to be motivated in order to produce the best results and that includes being able to choose the tools they use based on what makes them happy.  Recently it&#8217;s been my pleasure to spread a little Python love around my team mates.  It&#8217;s been great to see the enthusiasm with which they have taken to using it, and the stunned awe when the see just how powerful this &#8216;Scripting Language&#8217; really is.  This has increased the motivation of the team, and as a result we are completing more work, to a higher standard, in a shorter time than we were previously while working in C# .NET  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/11/05/why-i-write-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Writing Scala code in IntelliJ IDEA</title>
		<link>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/</link>
		<comments>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:00:47 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=39</guid>
		<description><![CDATA[<p>Just read that IntelliJ IDEA 9 will be split into a Community Edition, and an Ultimate Edition.  The Community Edition will be open sourced, and allows the Scala plugin.  I&#8217;ve been writing Scala code for a few months now, and using IDEA in the office, and TextMate at home.  I&#8217;m really hoping [...]]]></description>
			<content:encoded><![CDATA[<p>Just read that <a href="http://blogs.jetbrains.com/idea/2009/10/intellij-idea-open-sourced/">IntelliJ IDEA 9</a> will be split into a Community Edition, and an Ultimate Edition.  The Community Edition will be open sourced, and allows the <a href="http://www.scala-lang.org">Scala</a> plugin.  I&#8217;ve been writing Scala code for a few months now, and using IDEA in the office, and <a href="http://macromates.com/">TextMate</a> at home.  I&#8217;m really hoping that I&#8217;ll be able to use the open sourced version at home so I don&#8217;t have to context switch so much.  I&#8217;ve tried the Scala plugin for NetBeans, but it is so far off ready, that I prefer using TextMate.  I know the scala plugin for IDEA 8.1 works really well, but it doesn&#8217;t work in the IDEA 9.0 early access release yet.  I hope this gets fixed soon so I can play with scala at home more.</p>
<p>NOTE:  I don&#8217;t recommend using maven with Scala on the Mac, because it just doesn&#8217;t play nicely.  Don&#8217;t know why, but it&#8217;s broken to the point that I no longer even try to use Maven to build my scala code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/10/15/writing-scala-code-in-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Stubbing a REST api in Python</title>
		<link>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/</link>
		<comments>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 04:58:19 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[geek]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=15</guid>
		<description><![CDATA[<p>For the last few jobs I&#8217;ve had, Service Oriented Architecture has been a strong theme.  Having services presenting REST apis that consume and produce XML has been the regular approach.  When it comes to testing consumers of those services, I have found Python to be an extremely useful and convenient tool.  It&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>For the last few jobs I&#8217;ve had, <a href="http://en.wikipedia.org/wiki/Service-oriented_architecture">Service Oriented Architecture</a> has been a strong theme.  Having services presenting REST apis that consume and produce XML has been the regular approach.  When it comes to testing consumers of those services, I have found Python to be an extremely useful and convenient tool.  It&#8217;s quick and easy to <a href="http://docs.python.org/library/basehttpserver.html">throw an HTTP server up</a> in Python, and hard code the values that it returns.  The problem is though, that I have ended up just adding code to the do_GET / do_POST methods as I add tests that handle different expectations.  This ends up separating the expectations and return values from the test, and making maintaining the stub code harder than it should be.  </p>
<p>To resolve this, I&#8217;d like to add expectations of the stub http server in the same way as with defining mocks.  The syntax would look something like this</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"> &nbsp; &nbsp;server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;GET&quot;</span>, url=<span class="st0">&quot;/address/<span class="es0">\d</span>+$&quot;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>mime=<span class="st0">&quot;text/xml&quot;</span>, file_content=<span class="st0">&quot;path/to/response.xml&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; capture = <span class="br0">&#123;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;PUT&quot;</span>, url=<span class="st0">&quot;/address/<span class="es0">\d</span>+$&quot;</span>, data_capture=capture<span class="br0">&#41;</span>.</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>reply_code=<span class="nu0">201</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;POST&quot;</span>, url=<span class="st0">&quot;address/<span class="es0">\d</span>+/inhabitant&quot;</span>, data=<span class="st0">&#8216;&lt;inhabitant name=&quot;Chris&quot;/&gt;&#8217;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>reply_code=<span class="nu0">204</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; server.<span class="me1">expect</span><span class="br0">&#40;</span>method=<span class="st0">&quot;GET&quot;</span>, url=<span class="st0">&quot;/monitor/server_status$&quot;</span><span class="br0">&#41;</span>.</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="me1">and_return</span><span class="br0">&#40;</span>content=<span class="st0">&quot;&lt;html&gt;&lt;body&gt;Server is up&lt;/body&gt;&lt;/html&gt;&quot;</span>, mime_type=<span class="st0">&quot;text/html&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <span class="co1"># execute system under test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">self</span>.<span class="me1">assertEquals</span><span class="br0">&#40;</span><span class="st0">&quot;&lt;expected&gt;&lt;xml/&gt;&lt;/expected&gt;&quot;</span>, capture<span class="br0">&#91;</span><span class="st0">&quot;body&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>So, over the next couple of weeks I&#8217;ll be putting this together, which should among other things allow me to improve the end to end testing story for <a href="http://djangorestmodel.sourceforge.net">djangoRESTModel</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/10/06/stubbing-a-rest-api-in-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django REST models</title>
		<link>http://www.pyruby.com/2009/09/28/django-rest-models/</link>
		<comments>http://www.pyruby.com/2009/09/28/django-rest-models/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 01:05:07 +0000</pubDate>
		<dc:creator>PyRuby</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.pyruby.com/?p=4</guid>
		<description><![CDATA[We wrote an xml_models library, which allowed us to map our models to the XML data, using a declarative style similar to the Django DB models.  The library has been open sourced and can be found on <a [...]]]></description>
			<content:encoded><![CDATA[<h2>Making external XML REST apis more pythonic</h2>
<p>At <a href="http://www.point2.com">work</a> we have a <a href="http://www.djangoproject.com">Django</a> web application where the models are backed by a Java XML <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST api</a>.  The application is read only, so there is no requirement to write back to the REST api.</p>
<p>We started with copying the data into a local DB, and using regular Django DB models, and we wanted something that would feel very similar, but use an XML REST backend. We wrote an xml_models library, which allowed us to map our models to the XML data, using a declarative style similar to the Django DB models.  The library has been open sourced and can be found on <a href="http://djangorestmodel.sf.net">sourceforge</a>.</p>
<p>Here is a simple example:-</p>
<p>Suppose there was an API http://myaddressbook.com/addresses/{addressID} that returns the following XML</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;address</span> <span class="re0">id</span>=<span class="st0">&quot;123&quot;</span> <span class="re0">num</span>=<span class="st0">&quot;3301&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;street<span class="re2">&gt;</span></span></span>8th Street<span class="sc3"><span class="re1">&lt;/street<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;city<span class="re2">&gt;</span></span></span>Saskatoon<span class="sc3"><span class="re1">&lt;/city<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;province<span class="re2">&gt;</span></span></span>SK<span class="sc3"><span class="re1">&lt;/province<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="sc3"><span class="re1">&lt;country<span class="re2">&gt;</span></span></span>Canada<span class="sc3"><span class="re1">&lt;/country<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/address<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>The model might be defined as</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">class</span> Address<span class="br0">&#40;</span>xml_models.<span class="me1">Model</span><span class="br0">&#41;</span>:</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">id</span> = xml_models.<span class="me1">IntField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/@id&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; num = xml_models.<span class="me1">IntField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/@num&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; street = xml_models.<span class="me1">CharField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/street&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; city = xml_models.<span class="me1">CharField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/city&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; province = xml_models.<span class="me1">CharField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/province&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; country = xml_models.<span class="me1">CharField</span><span class="br0">&#40;</span>xpath=<span class="st0">&quot;/address/country&quot;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; finders = <span class="br0">&#123;</span> <span class="br0">&#40;</span><span class="kw2">id</span>,<span class="br0">&#41;</span>: <span class="st0">&quot;http://myaddressbook.com/addresses/%s&quot;</span> ,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>num,street<span class="br0">&#41;</span>: <span class="st0">&quot;http://myaddressbook.com/addresses/num/%s/street/%s&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>And using the finder method would be like this</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">address = Address.<span class="me1">objects</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="kw2">id</span>=<span class="nu0">123</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>That&#8217;s the basics.  We are mapping much more complex relationships with collection fields, date fields and more.  Take a look and let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pyruby.com/2009/09/28/django-rest-models/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

