<?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>Draakwired &#187; Uncategorized</title>
	<atom:link href="http://drakonen.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://drakonen.com</link>
	<description>Here be Dragons  -  Drakonen&#039;s Blog</description>
	<lastBuildDate>Tue, 20 Mar 2012 23:18:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>A small, but funny, fail.</title>
		<link>http://drakonen.com/2012/a-small-but-funny-fail/</link>
		<comments>http://drakonen.com/2012/a-small-but-funny-fail/#comments</comments>
		<pubDate>Tue, 20 Mar 2012 23:18:44 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=238</guid>
		<description><![CDATA[So, I have this bug where when I shoot a bullet from a turret, the cruiser starts to spin! Not the intended behaviour :) On Youtube]]></description>
			<content:encoded><![CDATA[<p>So, I have this bug where when I shoot a bullet from a turret, the cruiser starts to spin! Not the intended behaviour :)</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/o45AZPumD6o" frameborder="0" allowfullscreen></iframe><br />
<a href="http://www.youtube.com/watch?v=o45AZPumD6o" onclick="pageTracker._trackPageview('/outgoing/www.youtube.com/watch?v=o45AZPumD6o&amp;referer=');">On Youtube</a></p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2012/a-small-but-funny-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making a turret in Unity 3D</title>
		<link>http://drakonen.com/2012/making-a-turret-in-unity-3d/</link>
		<comments>http://drakonen.com/2012/making-a-turret-in-unity-3d/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 19:08:14 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=212</guid>
		<description><![CDATA[As a start to Unity3D I tried to make a turret that consists of 2 parts. One base part and one barrel part. The barrel is connected via &#8220;hinges&#8221; to the base part. On this image the base(2) and the barrel(3) is shown whit their intended rotations around their axis. The base rotates on the [...]]]></description>
			<content:encoded><![CDATA[<p>As a start to Unity3D I tried to make a turret that consists of 2 parts. One base part and one barrel part. The barrel is connected via &#8220;hinges&#8221; to the base part.<a href="http://drakonen.com/wp-content/uploads/2012/03/TurrerRotation.png"><img src="http://drakonen.com/wp-content/uploads/2012/03/TurrerRotation.png" alt="Turret Rotation" title="TurrerRotation" width="766" height="234" class="alignnone size-full wp-image-213" /></a></p>
<p>On this image the base(2) and the barrel(3) is shown whit their intended rotations around their axis. The base rotates on the y axis and the barrel moves up and down on the x axis.<br />
It is important to have the z axis point forward, since that is what Unity assumes to be forward. (I discovered that with trail and error instead of just reading up on the subject)</p>
<h2>Hierarchy</h2>
<p><a href="http://drakonen.com/wp-content/uploads/2012/03/TurretHierarchy.png"><img src="http://drakonen.com/wp-content/uploads/2012/03/TurretHierarchy.png" alt="Turret Hierarchy" title="TurretHierarchy" width="129" height="99" class="alignright size-full wp-image-219" /></a>When that was done i needed to place it in a proper hierarchy. The Top is an empty <code>GameObject</code>. In there I put an other empty <code>GameObject</code> and named it Sides, and added 2 pillar cubes to it. The barrel is a cube renamed to CenterPiece, the cube inside it is to show where to front is.</p>
<h2>Scripting</h2>
<p>We have two rotating parts. The rotation is done independently from each other but together they will point at an object.</p>
<h3>Got values?</h3>
<p>I got the rotation values towards the other object with the neat little Unity function: <code><a href="http://unity3d.com/support/documentation/ScriptReference/Transform.LookAt.html" title="Transform.lookat" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/ScriptReference/Transform.LookAt.html?referer=');">LookAt</a></code>. Lookat points the z axis towards the object.<br />
I only need two rotation values. So I saved the values before the lookAt, called lookAt, saved the new rotation values, and set the rotation back to the old values before rotating.</p>
<h3>Turning</h3>
<p>I made two separate scripts for the base and barrel, while the code is very similar there are slight differences like the axis.<br />
I use a simple transform.Rotate with the help of <a href="http://unity3d.com/support/documentation/ScriptReference/Mathf.MoveTowardsAngle.html" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/ScriptReference/Mathf.MoveTowardsAngle.html?referer=');">Mathf.MoveTowardsAngle</a> to smootly turn to <em>only</em> on the required angle. I first tried turning with <a href="http://unity3d.com/support/documentation/ScriptReference/Quaternion.Slerp.html" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/ScriptReference/Quaternion.Slerp.html?referer=');">slerp</a>, but the barrel and base rotated slightly out of sync making the whole thing look terrible. MoveTowardsAngle also gives a nice constant rotation speed, which was exactly what I was looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2012/making-a-turret-in-unity-3d/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Starting a game project with Unity 3D</title>
		<link>http://drakonen.com/2012/starting-a-game-project-with-unity-3d/</link>
		<comments>http://drakonen.com/2012/starting-a-game-project-with-unity-3d/#comments</comments>
		<pubDate>Fri, 09 Mar 2012 22:39:18 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=197</guid>
		<description><![CDATA[Jasper and me are going (at least try) to make a game with Unity 3D. It will be a space opera kind of game. No details yet! I&#8217;ve been playing with Unity 3D for a few days now and the experience so far has been mostly positive. Starting I have never done anything with 3D [...]]]></description>
			<content:encoded><![CDATA[<p>Jasper and me are going (at least try) to make a game with <a href="http://unity3d.com/" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/?referer=');">Unity 3D</a>. It will be a space opera kind of game. No details yet!</p>
<p>I&#8217;ve been playing with Unity 3D for a few days now and the experience so far has been mostly positive.</p>
<h2>Starting</h2>
<p>I have never done anything with 3D really, so this is completely new for me. And I&#8217;m not too good yet at the 3D maths, but that will be a skill to be forcefully improved.</p>
<p>The <a href="http://unity3d.com/support/documentation/" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/?referer=');">documentation</a> is decent. The <a href="http://unity3d.com/support/documentation/ScriptReference/index.html" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/ScriptReference/index.html?referer=');">API docs</a> are very brief, and for someone who does not know all the 3D terminology it is hard read and to decide which function to take. It lacks information about what the benefits are and what the function can and cannot do.</p>
<p>I started out doing a <a href="http://unity3d.com/support/resources/tutorials/3d-platform-game" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/resources/tutorials/3d-platform-game?referer=');">tutorial</a>. Unfortunately this tutorial was for an older Unity version. Much is still the same though, just the interface changed. Unfortunately I found this tutorial to be tedious and lacking excitement. While you do get quick visual results with it, it was not what I wanted to know.</p>
<h2>Scripting Language choice</h2>
<p>We picked JavaScript, or at least the Unity version of it. Just when I thought I was beginning to understand JavaScript in the browser, this dialect comes along. It seems to have better scoping, which is welcome.<br />
Unity comes with a customized version of MonoDevelop. It&#8217;s an IDE, with completion for UnityScript. Quite helpful, it had an <a href="http://unity3d.com/support/documentation/Manual/Debugger.html" onclick="pageTracker._trackPageview('/outgoing/unity3d.com/support/documentation/Manual/Debugger.html?referer=');">integrated debugger</a>. So far I&#8217;ve only used it to edit the scripts.</p>
<h2>Managing Assets</h2>
<p>I&#8217;ve decided to use Mercurial for this project. I&#8217;ve set up a private repository on Bitbucket, and shared it with Jasper. Easy as pie. Just be sure to follow these instructions.<br />
I have not used Mercurial on Windows much but TortoiseHG is manageable, still I would prefer having the command-line tools instead.</p>
<p>We&#8217;ll have to see what we want to do with the actual game assets when textures and sounds come along. Mercurial is not the best tool to handle those.</p>
<p>To be continued&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2012/starting-a-game-project-with-unity-3d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript parent constructor being run when defining inheritance and a solution</title>
		<link>http://drakonen.com/2012/javascript-parent-constructor-being-run-when-defining-inheritance-and-a-solution/</link>
		<comments>http://drakonen.com/2012/javascript-parent-constructor-being-run-when-defining-inheritance-and-a-solution/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 12:53:32 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=188</guid>
		<description><![CDATA[When using the traditional Javascript methods to do some sort of inheritance, the constructor of the parent will always be run when trying to inherit it. This seems to be a unfortunate side effect of using new a(). The problem Consider this code. Here b inherits from a function a&#40;&#41; &#123; console.log&#40;&#34;a&#34;&#41;; &#125; &#160; function [...]]]></description>
			<content:encoded><![CDATA[<p>When using the traditional Javascript methods to do some sort of inheritance, the constructor of the parent will always be run when trying to inherit it. This seems to be a unfortunate side effect of using <code>new a()</code>.</p>
<h2>The problem</h2>
<p>Consider this code. Here b inherits from a</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> a<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> b<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    a.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;b&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
b.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> a<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// a's constructor will be run here!</span>
b.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">new</span> b<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// run once</span>
<span style="color: #003366; font-weight: bold;">new</span> b<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// run twice</span></pre></div></div>

<p>Here a&#8217;s constructor will be run 3 times.</p>
<pre>
a
a
b
a
b
</pre>
<h2>The solution</h2>
<p>There is a simple fix for this, but its only in Ecmascript 5.<br />
Change this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">b.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> a<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Into this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">b.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> Object.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And the constructor will only be run when actually being called:</p>
<pre>
a
b
a
b
</pre>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2012/javascript-parent-constructor-being-run-when-defining-inheritance-and-a-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using hgtools with mercurial tags to automatically version packages</title>
		<link>http://drakonen.com/2012/using-hgtools-with-mercurial-tags-to-automatically-version-packages/</link>
		<comments>http://drakonen.com/2012/using-hgtools-with-mercurial-tags-to-automatically-version-packages/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 21:50:59 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=166</guid>
		<description><![CDATA[I liked to automate my python package versioning a bit more and did this with hgtools. With hgtools it is quite easy to store the version numbers only in your repository as tags, and not having it again in setup.py. A minimal setup.py can look like this: from setuptools import setup, find_packages setup&#40; name=&#34;HelloWorld&#34;, use_hg_version=True, [...]]]></description>
			<content:encoded><![CDATA[<p>I liked to automate my python package versioning a bit more and did this with <a href="http://pypi.python.org/pypi/hgtools" onclick="pageTracker._trackPageview('/outgoing/pypi.python.org/pypi/hgtools?referer=');">hgtools</a>. With hgtools it is quite easy to store the version numbers only in your repository as tags, and not having it again in <code>setup.py</code>.</p>
<p>A minimal <code>setup.py</code> can look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> setuptools <span style="color: #ff7700;font-weight:bold;">import</span> setup, find_packages
setup<span style="color: black;">&#40;</span>
    name=<span style="color: #483d8b;">&quot;HelloWorld&quot;</span>,
    use_hg_version=<span style="color: #008000;">True</span>,
    packages=find_packages<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>,
    setup_requires=<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;hgtools&quot;</span><span style="color: black;">&#93;</span>,
<span style="color: black;">&#41;</span></pre></div></div>

<p>Just give a revision a tag and make an sdist, or bdist and setuptools will use the version from your tag.<br />
Tags have to conform to <a href="http://epydoc.sourceforge.net/stdlib/distutils.version.StrictVersion-class.html" onclick="pageTracker._trackPageview('/outgoing/epydoc.sourceforge.net/stdlib/distutils.version.StrictVersion-class.html?referer=');">strict version formatting from distutils</a> to be used by hgtools.</p>
<p>Later I also made it a step in a Jenkins setup, to always build a <code>sdist</code> and copy it to a HTTP accessible directory so it could be installed with pip. This gave me a nice history of available release packages and also, dev versions.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2012/using-hgtools-with-mercurial-tags-to-automatically-version-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django class based views and testing them</title>
		<link>http://drakonen.com/2010/django-class-based-views-and-testing-them/</link>
		<comments>http://drakonen.com/2010/django-class-based-views-and-testing-them/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 13:41:07 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=139</guid>
		<description><![CDATA[One of the problems described well by Honza Král&#8217;s presentation on Djangocon.eu 2010, is how to test properly and make it easier. In his presentation he touches on using class based views instead of using normal functions (around 14:14 in the link video). This is not as straight forwards as it seems at first. There are [...]]]></description>
			<content:encoded><![CDATA[<p>One of the problems described well by Honza Král&#8217;s <a href="http://djangoconeu.blip.tv/file/3677324/" onclick="pageTracker._trackPageview('/outgoing/djangoconeu.blip.tv/file/3677324/?referer=');">presentation</a> on Djangocon.eu 2010, is how to test properly and make it easier. In his presentation he touches on using class based views instead of using normal functions (around 14:14 in the link video). This is not as straight forwards as it seems at first. There are some problems with thead-safety for one.</p>
<p>To have fast tests you should avoid hitting the database as much as you can, and after using this method I have to agree.</p>
<h2>Making a class based view</h2>
<p>We have this simple view:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">shortcuts</span> <span style="color: #ff7700;font-weight:bold;">import</span> render_to_response, get_object_or_404
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> mysite.<span style="color: black;">polls</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> Poll
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> simple_view<span style="color: black;">&#40;</span>request, poll_id<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; A simple view, which takes an id from a url, shows it in a template. &quot;&quot;&quot;</span>
    poll = get_object_or_404<span style="color: black;">&#40;</span>Poll, pk=poll_id<span style="color: black;">&#41;</span>
    poll.<span style="color: black;">access_counter</span> += <span style="color: #ff4500;">1</span>
    poll.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span style="color: black;">&#40;</span><span style="color: #483d8b;">'polls/detail.html'</span>, <span style="color: black;">&#123;</span><span style="color: #483d8b;">'poll'</span>: poll<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>And now as a Class based view:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Context, loader
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">http</span> <span style="color: #ff7700;font-weight:bold;">import</span> HttpResponse
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> mysite.<span style="color: black;">polls</span>.<span style="color: black;">models</span> <span style="color: #ff7700;font-weight:bold;">import</span> Poll
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> simple_view<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> get_objects<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, poll_id<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot; Return poll object for given poll_id. &quot;&quot;&quot;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> get_object_or_404<span style="color: black;">&#40;</span>Poll, pk=poll_id<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> process<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, poll<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot; Manipulate data and return the manipulated, unsaved object. &quot;&quot;&quot;</span>
        poll.<span style="color: black;">access_counter</span> += <span style="color: #ff4500;">1</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> poll
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> render<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, poll<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot; Return HTML. &quot;&quot;&quot;</span>
        template = loader.<span style="color: black;">get_template</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'polls/detail.html'</span><span style="color: black;">&#41;</span>
        context = Context<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'poll'</span>: poll<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> template.<span style="color: black;">render</span><span style="color: black;">&#40;</span>context<span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__call__</span><span style="color: black;">&#40;</span>request, poll_id<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot; Show a Poll, increment the access_counter each time. &quot;&quot;&quot;</span>
        poll = <span style="color: #008000;">self</span>.<span style="color: black;">get_objects</span><span style="color: black;">&#40;</span>poll_id<span style="color: black;">&#41;</span>
        poll = <span style="color: #008000;">self</span>.<span style="color: black;">process</span><span style="color: black;">&#40;</span>poll<span style="color: black;">&#41;</span>
        poll.<span style="color: black;">save</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        output = <span style="color: #008000;">self</span>.<span style="color: black;">render</span><span style="color: black;">&#40;</span>poll<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> HttpResponse<span style="color: black;">&#40;</span>output<span style="color: black;">&#41;</span></pre></div></div>

<p>What did we do here? We separated the functionality into methods. We have four functions now:</p>
<ul>
<li><code>get_objects</code> which gets and returns the data, not more, not less. If you have more then one piece of data to get, return a tuple.</li>
<li><code>process</code> which manipulates the data, but does not save it.</li>
<li><code>render</code> transform the manipulated data into HTML.</li>
<li><code>__call__</code> the mighty function which ties it all together</li>
</ul>
<p>Each of these functions do one thing, and try to do it well and isolated. Because this is so isolated, testing becomes quite easy since you can test the output of every step and it does not have side effects of the other parts. You still need to run __call__ at least once to check if it is all nicely tied together.</p>
<h2>Testing</h2>
<p>Testing a part of this view is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> SimpleviewTest<span style="color: black;">&#40;</span>TestCase<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> test_simpleview_process_increment<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        view = mysite.<span style="color: black;">view</span>.<span style="color: black;">simple_view</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        poll = Poll<span style="color: black;">&#40;</span>question=<span style="color: #483d8b;">&quot;sample&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
        poll = view.<span style="color: black;">process</span><span style="color: black;">&#40;</span>poll<span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">assertEquals</span><span style="color: black;">&#40;</span>poll.<span style="color: black;">access_counter</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Create an instance of the view, create a poll object and feed it to the function. Check afterwards if the value has increased. This is fast, there is no database interaction!</p>
<h2>Wiring it into urls.py</h2>
<p>I found a <a href="http://github.com/davedash/zamboni/blob/609ec5467dd6db6a6647f375e95abced5203a1b2/apps/api/urls.py#L9" onclick="pageTracker._trackPageview('/outgoing/github.com/davedash/zamboni/blob/609ec5467dd6db6a6647f375e95abced5203a1b2/apps/api/urls.py_L9?referer=');">little lambda helper</a> to call the class based view:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># this wraps a class based view in a lambda, so it is thread safe (and I do not need to use __new__)</span>
<span style="color: #808080; font-style: italic;"># yes this returns a lambda</span>
class_view = <span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #ff7700;font-weight:bold;">lambda</span> <span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs: x<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#40;</span><span style="color: #66cc66;">*</span>args, <span style="color: #66cc66;">**</span>kwargs<span style="color: black;">&#41;</span>
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
    <span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'showpoll'</span>, class_view<span style="color: black;">&#40;</span>mysite.<span style="color: black;">views</span>.<span style="color: black;">simple_view</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>,
<span style="color: black;">&#41;</span></pre></div></div>

<p>Just put the <code>class_view</code> function around the view reference.</p>
<p>This might seem quite a lot of code for this example, and it is, but this will give you some benefits when testing this way. Because this is a lot longer then before, you might not want to use it for every view, just for the more complicated ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2010/django-class-based-views-and-testing-them/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vim, python pep8 and pylint.</title>
		<link>http://drakonen.com/2010/vim-python-pep8-and-pylint/</link>
		<comments>http://drakonen.com/2010/vim-python-pep8-and-pylint/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 14:04:33 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/?p=128</guid>
		<description><![CDATA[When you are making your Python code pep8 conformant or want to have a good pylint score and you are using vim, there are a few ways to make it easier and faster. First you need to know a bit about the vim option -q. -q takes a filename as a argument, and vim then [...]]]></description>
			<content:encoded><![CDATA[<p>When you are making your Python code pep8 conformant or want to have a good pylint score and you are using vim, there are a few ways to make it easier and faster.</p>
<p>First you need to know a bit about the vim option -q. -q takes a filename as a argument, and vim then uses this file to jump to locations in files where the used tool has reported something. Vim expects a very simple format here.</p>
<p>Vim can take the output of the pep8 command:</p>
<p>﻿<code>pep8 --repeat --ignore=E501 *.py  &gt; ~/pep.txt</code></p>
<p>Then start vim with:</p>
<p><code>vim -q ~/pepepep.txt</code></p>
<p>Vim then opens with the first reported issue, to go to the next, use <code>:cn</code>.<br />
Or you can temporarily map <code>z</code> to that for this vim session:</p>
<p><code>:map z :cn&lt;cr&gt;</code></p>
<p>Like with pep8, you can do the same with pylint, but you need to use the <code>--format parseable</code> argument:</p>
<p>﻿<code>pylint views.py -f parseable &gt; ~/pep.txt</code></p>
<h3>Some regexps for common formatting issues</h3>
<p>Remove trailing whitespace all over the file:<br />
<span style="font-family: monospace;">:%s/\s\+$//</span></p>
<p>Remove whitespace in front of a ,<br />
<span style="font-family: monospace;">:s/\s*,/,/</span></p>
<p>Remove whitespace in front of an equal-sign, if any, add a space.<br />
<span style="font-family: monospace;">:s/\s*=/ =/</span></p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2010/vim-python-pep8-and-pylint/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Configuring the Buffalo AP&#8217;s as a Bridge</title>
		<link>http://drakonen.com/2009/configuring-the-buffalo-aps-as-a-bridge/</link>
		<comments>http://drakonen.com/2009/configuring-the-buffalo-aps-as-a-bridge/#comments</comments>
		<pubDate>Tue, 05 May 2009 14:43:52 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/blog/?p=124</guid>
		<description><![CDATA[Configuring the Buffalo WHR-HP-54G as a bridge is quite easy, given that you can get Tomato firmware on there. The default Buffalo firmware doesn&#8217;t support bridging or, I couldn&#8217;t find it. only thing I found was WDS bridging which is not what I want. Install Tomato You need to install an alternative firmware, fortunately most [...]]]></description>
			<content:encoded><![CDATA[<p>Configuring the Buffalo WHR-HP-54G as a bridge is quite easy, given that you can get Tomato firmware on there. The default Buffalo firmware doesn&#8217;t support bridging or, I couldn&#8217;t find it. only thing I found was WDS bridging which is not what I want.</p>
<h2>Install Tomato</h2>
<p>You need to install an alternative firmware, fortunately most WRT derivatives are compatible, most notably <a href="http://www.polarcloud.com/tomato" onclick="pageTracker._trackPageview('/outgoing/www.polarcloud.com/tomato?referer=');">Tomato</a> and <a href="http://openwrt.org/" onclick="pageTracker._trackPageview('/outgoing/openwrt.org/?referer=');">openWRT</a>. I picked Tomato because it has a nice &#8220;out of the box&#8221; experience. It has an easy to use Web interface which is easy to use. OpenWRT is more powerful in the end, but harder to set up at first. I also assume we do not need the extra features that are possible.</p>
<p>Get Tomato from its website, its 7zipped so you might need a more recent <a href="http://wakaba.c3.cx/s/apps/unarchiver.html" onclick="pageTracker._trackPageview('/outgoing/wakaba.c3.cx/s/apps/unarchiver.html?referer=');">unarchiver</a>.</p>
<p>Flashing the AP is more trail and error then science, and it did not work for me, but did work for a colleague.</p>
<p><a href="http://en.wikibooks.org/wiki/Tomato_(firmware)#Installing_on_a_Buffalo_WHR-G54S.2FWHR-HP-G54S_in_OS_X.2C_Linux.2C_and_other_Unix-based_OS.27s" onclick="pageTracker._trackPageview('/outgoing/en.wikibooks.org/wiki/Tomato_firmware_Installing_on_a_Buffalo_WHR-G54S.2FWHR-HP-G54S_in_OS_X.2C_Linux.2C_and_other_Unix-based_OS.27s?referer=');">Here are the Tomato install instructions</a></p>
<h2>Configure a Bridge</h2>
<p><strong>TURN OFF IT&#8217;S DHCP SERVER</strong></p>
<p>Give it an IP address in an other subnet then you main one (this is for performance reasons).</p>
<p>Here are the settings you need to set to be able to bridge:</p>
<div id="attachment_125" class="wp-caption alignnone" style="width: 998px"><img class="size-full wp-image-125" title="wlansettings" src="http://drakonen.com/wp-content/uploads/2009/05/wlansettings.png" alt="Tomato WLAN settings" width="988" height="453" /><p class="wp-caption-text">Tomato WLAN settings</p></div>
<p>This is a nice addition:</p>
<div id="attachment_126" class="wp-caption alignnone" style="width: 475px"><img class="size-full wp-image-126" title="bridge-led" src="http://drakonen.com/wp-content/uploads/2009/05/bridge-led.png" alt="Bridge LED" width="465" height="391" /><p class="wp-caption-text">Bridge LED</p></div>
<p>And its done.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2009/configuring-the-buffalo-aps-as-a-bridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up Suse LTSP with DHCP on another server</title>
		<link>http://drakonen.com/2009/setting-up-suse-ltsp-with-dhcp-on-another-server/</link>
		<comments>http://drakonen.com/2009/setting-up-suse-ltsp-with-dhcp-on-another-server/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 09:33:44 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/blog/?p=113</guid>
		<description><![CDATA[At work, I have been tasked with setting up a Linux terminal server to lighten the load of our exsisting Windows server. LTSP (Linux Terminal Server Project) is quite a nice piece of software. It makes good use of PXE netbooting, but it should also work with RDP. Get Suse Download the openSUSE-Edu-KIWI-LTSP-live-unstable.i686 iso from [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I have been tasked with setting up a Linux terminal server to lighten the load of our exsisting Windows server.</p>
<p>LTSP (Linux Terminal Server Project) is quite a nice piece of software. It makes good use of PXE netbooting, but it should also work with RDP.</p>
<h2>Get Suse</h2>
<p>Download the openSUSE-Edu-KIWI-LTSP-live-unstable.i686 iso from http://download.opensuse.org/repositories/Education/images/iso/</p>
<p>Why Suse? It has good support for LTSP <em>and</em> RDP.</p>
<h2>Setting up RDP on Suse</h2>
<p><a title="Setting up RDP on suse" href="http://en.opensuse.org/Nomad#Installation" onclick="pageTracker._trackPageview('/outgoing/en.opensuse.org/Nomad_Installation?referer=');">Setting up RDP on Suse</a> was very easy (compared to Ubuntu LTSP):<br />
You can skip this if you installed from the live DVD.</p>
<p><code>zypper ar <a title="http://download.opensuse.org/repositories/home:/dreveman:/nomad/openSUSE 11.1" rel="nofollow" href="http://download.opensuse.org/repositories/home:/dreveman:/nomad/openSUSE_11.1" onclick="pageTracker._trackPageview('/outgoing/download.opensuse.org/repositories/home_/dreveman_/nomad/openSUSE_11.1?referer=');">http://download.opensuse.org/repositories/home:/dreveman:/nomad/openSUSE_11.1</a><br />
# nomad zypper in rdesktop xrdp xorg-x11-server-dmx xorg-x11-server-rdp<br />
</code></p>
<p>Now you need to edit /etc/sysconfig/kiwi-ltsp and add:</p>
<p>USE_NOMAD=&#8221;1&#8243;</p>
<p>Run to update the configuration:</p>
<p><code>kiwi-ltsp-setup -c</code></p>
<p>Now start the xrdp server with:</p>
<p><code>rcxrdp start</code></p>
<h2>PXE booting</h2>
<p>PXE booting is a nice feature of network cards. It allows the computer to pull the operating system over the network, and boot the pulled operating system. The user can start applications, but they are not run on the client, but on the server. This is done with several services.</p>
<p>DHCP to tell where to get the boot image from.<br />
TFTP this actually delivers the boot image, based on UDP.<br />
Xorg to display apps on the client side which are actually run on the server.<br />
SSH to provide a secure connection between the Xorg server on the client and Xorg on the server (using option -X)</p>
<p>This should work out of the box when this is the only server in your network, and you do not already have a DHCP server on your network.</p>
<h2>But we already have DHCP</h2>
<p>LTSP assumes that you do not have an DHCP server yet and it runs one for you. This is quite bad if you already have a DHCP server running, which we have. Turning the dhcp server on Suse off is done with this:<br />
<code><br />
insserv -r dhcpd &amp;&amp; rcdhcpd stop</code></p>
<p>To turn it off forever you can remove the dhcp-server package:</p>
<p><code>rpm -e dhcp-server --nodeps</code></p>
<p>This should work until the next time you run <code>kiwi-ltsp-setup</code>, so I&#8217;ve been told.</p>
<p>You need to configure your <em>original DHCP </em>server (<em>not</em> the ltsp) , by editing the dhcpd.conf:<br />
<code><br />
subnet 192.168.0.0 netmask 255.255.255.0 {<br />
option routers 192.168.0.1;<br />
range 192.168.0.1 192.168.0.254;<br />
#add this and replace with your own LTSP server ip:<br />
next-server 192.168.0.2;<br />
filename "pxelinux.0";<br />
}</code></p>
<p>If you try to PXE boot it now, it will fail somewhere at the startup. Press F2 to see the init messages.</p>
<p>You also need to edit /srv/tftpboot/pxelinux.cfg/default</p>
<p>The line (its under <code>LABEL kiwi-ltsp</code>):<br />
<code>append initrd=boot/initrd-ltsp vga=791 splash=silent showopts</code></p>
<p>should become:<br />
<code>append initrd=boot/initrd-ltsp vga=791 splash=silent showopts kiwiserver=192.168.1.231 kiwiservertype=tftp</code></p>
<p>Try booting it now, and it should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2009/setting-up-suse-ltsp-with-dhcp-on-another-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The G1 Experience</title>
		<link>http://drakonen.com/2009/the-g1-experience/</link>
		<comments>http://drakonen.com/2009/the-g1-experience/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 20:09:10 +0000</pubDate>
		<dc:creator>Drakonen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://drakonen.com/blog/?p=104</guid>
		<description><![CDATA[Yesterday when I got home there was a nice present waiting for me. My G1 Phone arrived! I ripped open the packaging and found a phone that was smaller than I expected from the images from the internet. First tries Popping in the sim card and the battery was easy, turning it on was a [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday when I got home there was a nice present waiting for me. My G1 Phone arrived! I ripped open the packaging and found a phone that was smaller than I expected from the images from the internet.</p>
<h2>First tries</h2>
<p>Popping in the sim card and the battery was easy, turning it on was a bit harder&#8230; I did not have much light and didn&#8217;t see the on-sign on the hangup button. After some messing around it turned on and it was booting! Next thing it asks me is to unlock the phone, &#8220;Damn!&#8221; i bought a locked phone. Luckily I knew that it could be unlocked and that it was just a matter of going to a website, entering some details and your emei code, oh and you need to pay 20 bucks too. The rest of the evening I was waiting for the unlock code to arrive. It did not arrive before I had to go to bed. Darn&#8230;</p>
<p>The next morning I got up on my usual time and turned on my laptop. After some morning routine stuff, I checked my email and to great satisfaction I found the unlock code! I turned on the G1 again and entered the code, and my phone was unlocked!</p>
<h2>Sign in with your Google account please</h2>
<p>To be able to use the phone <em>at all</em> you need to log in to your Google account. I tried that but of course that was not working because GPRS/UMTS was not setup for my provider, FONIC. Yet an other &#8220;Damn!&#8221;. Off to work I went and on arrival I spent some time there researching on how to set it up for FONIC, to no avail, nobody had the same problem as me it seemed. But, I knew that my provider was the cheap-ass version of o2. I found the details for that on plenty of sites, but with that information in my G1 I could also not sign in, seemingly&#8230; Back to do some work!</p>
<h2>Later that day</h2>
<p>A few hours later I tried signing in again, and to my amazement it worked flawlessly! Off playing with it some more! (<span style="font-size: xx-small;">not too much Mr. boss!</span>). But the battery was dying.. seemingly the provided usb cable didn&#8217;t work for charging the battery, i pulled out an other usb cable and plugged it in, and charging commenced! I also moved the most important contacts from my old phone, the trusty p900, to the sim card, and mass imported them onto my phone without any problem. I hopped onto the company wifi and synchronized with my Google account so my contacts show up in gmail. This is an awesome feature, and in my opinion the <strong>killer feature</strong>. At my workplace the wifi signal was not good enough to hold a connection to the wifi network, so it switched a lot between wifi and GPRS. This has costed me a few dimes I&#8217;m afraid&#8230; I was able to call and send sms&#8217;s with ease. The search <em>button</em> works in a lot of the standard applications and it is a blessing.</p>
<p>When I arrived home serious play time commenced. I installed a few aplications from the android market. It contains tons and tons of apps, some good some bad. Locale is nice, but is lacking a lot of options that it could really improve it. And the battery wanted to be charged again&#8230; I also used the IM client, and it worked pretty damn well! So far I absolutely LOVE it. it is fast and responsive, didnt crash on me once (knock on wood) and it is easy to use after a short learning period.</p>
<p>I will write about my other experiences an other time.</p>
]]></content:encoded>
			<wfw:commentRss>http://drakonen.com/2009/the-g1-experience/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

