<?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>Circles and Crosses &#187; Code</title>
	<atom:link href="http://ox.no/posts/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://ox.no</link>
	<description>Håvard Stranden&#039;s website</description>
	<lastBuildDate>Sun, 22 Apr 2012 22:21:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Binding a DOM element to an observable using Knockout.js</title>
		<link>http://ox.no/posts/binding-a-dom-element-to-an-observable-using-knockout-js</link>
		<comments>http://ox.no/posts/binding-a-dom-element-to-an-observable-using-knockout-js#comments</comments>
		<pubDate>Tue, 17 Apr 2012 19:32:36 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://ox.no/?p=462</guid>
		<description><![CDATA[I&#8217;ve been doing a bit of experimenting with Knockout.js recently. Having written quite a bit of .NET code over the years, I am very used to thinking in (and I prefer thinking in) the MVVM pattern when it comes to &#8230; <a href="http://ox.no/posts/binding-a-dom-element-to-an-observable-using-knockout-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a bit of experimenting with <a href="http://knockoutjs.com">Knockout.js</a> recently. Having written quite a bit of .NET code over the years, I am very used to thinking in (and I prefer thinking in) the MVVM pattern when it comes to UIs, and so Knockout.js is nice.</p>

<p>And, as always, when writing code and living in the real world you sometimes need to do things that do not quite fit the pattern. In this case, I needed to draw on a canvas from my view model whenever some observables on it changed. The pragmatic thing to do when you need to draw on a canvas is to just grab the canvas by ID or whatever, but since this canvas lived in a template, identifying it through selectors quickly got messy (and hard).</p>

<p>Binding to it seemed like a much better idea, so I created the simple <code>element</code> Knockout.js binding. This is a one-way-to-source binding (.NET guys will be familiar with this terminology), meaning that the binding only writes to the view model from the view. In addition, the binding only does this once (when it is initialized), as the element will stay for the lifespan of the page.</p>

<p>So, in all its glory, here is my Knockout.js <code>element</code> binding:</p>

<pre><code>ko.bindingHandlers.element = {
    init: function(element, valueAccessor) {
      var value = valueAccessor();
      value(element);
    }
};
</code></pre>

<p>Use it as you would any other binding:</p>

<pre><code>&lt;canvas width="100" height="60" data-bind="element: yourObservable"&gt;&lt;/canvas&gt;
</code></pre>

<p>Simple as that. Now go use it!</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/binding-a-dom-element-to-an-observable-using-knockout-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing JSUT &#8211; Cross-platform JavaScript Unit Testing</title>
		<link>http://ox.no/posts/introducing-jsut-cross-platform-javascript-unit-testing</link>
		<comments>http://ox.no/posts/introducing-jsut-cross-platform-javascript-unit-testing#comments</comments>
		<pubDate>Mon, 06 Feb 2012 11:09:44 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://ox.no/?p=336</guid>
		<description><![CDATA[I write quite a bit of JavaScript these days, and one observation I have made with regards to Line-of-Business apps is that platforms like Node.js makes me lean more towards sharing business logic between the server and client side (meaning &#8230; <a href="http://ox.no/posts/introducing-jsut-cross-platform-javascript-unit-testing">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I write quite a bit of JavaScript these days, and one observation I have made with regards to Line-of-Business apps is that platforms like Node.js makes me lean more towards sharing business logic between the server and client side (meaning Node.js and the browsers, in practice). This creates an immediate need to unit test &#8220;universally&#8221; (across all platforms and environments), and I couldn&#8217;t find a single tool that quite did it for me.</p>

<p>JSUT (JavaScript Unit Testing) is an attempt at making such a tool for fun and profit (non-monetary).</p>

<p>JSUT stems from me growing tired of the hurdles of unit testing my JavaScript code. There are tons of alternative unit testing tools and libraries readily available, but my experience was that they all exhibited one or more of the following shortcomings:</p>

<ul>
<li>Imposing a &#8220;framework&#8221; or &#8220;philosophy&#8221; or &#8220;style&#8221; on my tests</li>
<li>Bringing me additional dependencies to worry about</li>
<li>Working only in the browser or inside Node.js</li>
</ul>

<p>In addition, I feel that many of the available tools and libraries are either undermaintained or overly featureful, and buggy and/or painful to use as a result of one or both of those. I can&#8217;t and won&#8217;t claim that this will be different in the case of JSUT, so it&#8217;s not really an argument, but more a motivation for me.</p>

<h1>Goals</h1>

<p>I sat down and wrote a few goals for JSUT:</p>

<ul>
<li>Universal, cross-platform</li>
<li>Minimalistic, simple, non-constraining</li>
<li>Accessible</li>
</ul>

<p>I then took to writing code and brushing up my rather rusty shell scripting skills, and a few hours later I wound up with what I present to you now.</p>

<h1>JSUT &#8211; JavaScript Unit Testing &#8211; An introduction</h1>

<p>Writing a test in JSUT is about as simple as it can get. You write a function:</p>

<pre><code>function myTest(test) {
  // JSUTs only requirement:
  // Call test.done() when the test is done
  test.done(); 
}
</code></pre>

<p>Now, let&#8217;s say you save this function to a file called <code>test.js</code>. You can then move to your preferred shell and write the following:</p>

<pre><code>jsut -b chrome test.js
</code></pre>

<p>This will run your test in Chrome. To run your test in Node.js, do:</p>

<pre><code>jsut -n test.js
</code></pre>

<p>You can combine the <code>-b</code> and <code>-n</code> flags any way you like, of course.</p>

<h2>Getting JSUT</h2>

<p>Getting JSUT is very simple. Assuming you have <code>npm</code>, just do:</p>

<pre><code>npm install jsut
</code></pre>

<p>Which will install jsut locally. If you want a global installation, issue:</p>

<pre><code>npm install jsut -g
</code></pre>

<p>Of course, with the goals for JSUT, you can also just download and copy deploy JSUT. Visit <a href="http://github.com/havard/jsut">http://github.com/havard/jsut</a> for source code and further instructions.</p>

<h2>Requirements</h2>

<p>As mentioned in the above sample, the only requirement JSUT imposes on you is to call <code>test.done()</code> when your test is done. Obviously, this seems redundant for the simple case of a synchronously executing function, but since most JavaScript functions these days are asynchronous at some level, there has to be a way to tell JSUT that a test is done. I am actively considering easing this requirement for simple cases, but this has not been a priority so far.</p>

<p>For Node.js, you are required to add the functions you want to test to the <code>exports</code> of each test file. Building on the example above, you can maintain cross-platform compatibility by doing the following:</p>

<pre><code>if (typeof(exports) !== 'undefined') {
  exports.myTest = myTest;
}
</code></pre>

<p>This will add exports only if the <code>exports</code> variable is defined. Now, if you wanted to run your test in Node.js, you simply do:</p>

<pre><code>jsut -n test.js
</code></pre>

<p>This will run your test in Node.js. You are free to combine the <code>-n</code> and <code>-b</code> flags any way you like, so that you can target all required platforms with a single command.</p>

<h2>Assertions</h2>

<p>JSUT automatically injects a CommonJS compatible assert module in your browser tests, so you can write stuff like <code>assert.ok(true);</code> anywhere in your test.</p>

<h2>Planned features</h2>

<p>JSUT currently only runs browser tests on OS X. I plan to support Linux and Windows as soon as possible. Follow <a href="http://github.com/havard">me</a> and <a href="http://github.com/havard/jsut">JSUT</a> on GitHub!</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/introducing-jsut-cross-platform-javascript-unit-testing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenID for Node.js v0.2.0 released</title>
		<link>http://ox.no/posts/openid-for-node-js-v0-2-0-released</link>
		<comments>http://ox.no/posts/openid-for-node-js-v0-2-0-released#comments</comments>
		<pubDate>Tue, 21 Jun 2011 19:58:21 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://ox.no/?p=315</guid>
		<description><![CDATA[I am pleased to announce the release of OpenID for Node.js v0.2.0. It deserves a blog post since the new version is a bump of the minor version number. What does this mean to the users of the library? API &#8230; <a href="http://ox.no/posts/openid-for-node-js-v0-2-0-released">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am pleased to announce the release of OpenID for Node.js v0.2.0. It deserves a blog post since the new version is a bump of the minor version number. What does this mean to the users of the library?</p>

<h2>API changes</h2>

<p>The API of the entire thing has changed. All callbacks exposed and used by the library are now on the form <code>callback(error, args)</code>. This convention is familiar to Node.js developers, and gives us the advantage of simpler integration with other libraries, as well as a slight increase in the fidelity of error messages.</p>

<h3>What has changed?</h3>

<ul>
<li><code>authenticate</code> now expects a callback which will be called with <code>(error, authUrl)</code>. Existing code which expects <code>(authUrl)</code> will not get an authUrl (but possibly an error instead), and so authentication won&#8217;t work after upgrade until you change your code.</li>
<li><code>verifyAssertion</code> also expects a callback of the same form, which will be called with <code>(error, result)</code>. Again, existing code depends on receiving a <code>(result)</code> call, and will break.</li>
<li><code>loadAssociation</code> and <code>saveAssociation</code> must now accept a callback on the form <code>(error, result)</code> as an additional parameter. Previously, these functions were synchronous, so existing implementations will have to adapt so they call the callback rather than return.</li>
</ul>

<h2>What is new?</h2>

<p>As usual, we have fixed several bugs. The library is gaining a community, and there have been several contributions along the 0.1 release path leading up to 0.2.0. Thank you all for your participation!</p>

<p>Apart from the changes above, 0.2.0 also introduces a discovery cache for caching discovered information. This cache is used to avoid additional HTTP requests when verifying assertions from the OpenID providers. The default cache is an in-memory cache, but you can implement your own by overloading two functions:</p>

<ul>
<li><code>loadDiscoveredInformation(claimedIdentifier, callback)</code> is expected to look for and load a cached <code>provider</code> for the given <code>claimedIdentifier</code>. It is expected to call <code>callback(error, provider)</code> when finished, with either an error or a provider (duh).</li>
<li><code>saveDiscoveredInformation(provider, callback)</code> is expected to cache the given <code>provider</code>. The key for this object is <code>provider.claimedIdentifier</code>, which <code>loadDiscoveredInformation</code> uses for lookup. After saving, the function is expected to call <code>callback(error)</code> with an error if something failed, or nothing if all went well. </li>
</ul>

<p>I have been very reluctant to make these significant API changes, but the recent development, reported issues, and feature requests have convinced me that a unified API, and a more familiar API for Node.js developers, is the right way. Also, adapting to the new API is a pretty easy process. I hope you agree with me that the introduction of these changes is best in the long run.</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/openid-for-node-js-v0-2-0-released/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Diffie-Hellman support in Node.js</title>
		<link>http://ox.no/posts/diffie-hellman-support-in-node-js</link>
		<comments>http://ox.no/posts/diffie-hellman-support-in-node-js#comments</comments>
		<pubDate>Tue, 10 May 2011 11:43:07 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ox.no/?p=302</guid>
		<description><![CDATA[Yay! My patch implementing support for Diffie-Hellman key exchange in Node.js has finally been merged into the Node.js master branch. This will simplify the OpenID for Node.js codebase a lot. It will also make the OpenID association phase run a &#8230; <a href="http://ox.no/posts/diffie-hellman-support-in-node-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yay! My patch implementing support for Diffie-Hellman key exchange in Node.js has finally been <a href="https://github.com/joyent/node/commit/9f0b1a9bc60f70b7c5c014743eb1edd69c36db76">merged into the Node.js master branch</a>. This will simplify the <a href="https://github.com/havard/node-openid">OpenID for Node.js</a> codebase a lot. It will also make the OpenID association phase run a lot faster, since the current code does Diffie-Hellman in Javascript while the Node.js crypto version does it all in native code using OpenSSL.</p>

<p>A brief API overview:</p>

<ul>
<li><code>crypto.createDiffieHellman(prime_length)</code>

<ul>
<li>Creates a Diffie-Hellman key exchange object and generates a prime of the given bit length. The generator used is <code>2</code>.</li>
</ul></li>
<li><code>crypto.createDiffieHellman(prime, encoding='binary')</code>

<ul>
<li>Creates a Diffie-Hellman key exchange object using the supplied prime. The generator used is <code>2</code>. Encoding can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.generateKeys(encoding='binary')</code>

<ul>
<li>Generates private and public Diffie-Hellman key values, and returns the public key in the specified encoding. This key should be transferred to the other party. Encoding can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.computeSecret(other_public_key, input_encoding='binary', output_encoding=input_encoding)</code>

<ul>
<li>Computes the shared secret using <code>other_public_key</code> as the other party&#8217;s public key and returns the computed shared secret. Supplied key is interpreted using specified <code>input_encoding</code>, and secret is encoded using specified <code>output_encoding</code>. Encodings can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>. If no output encoding is given, the input encoding is used as output encoding.</li>
</ul></li>
<li><code>diffieHellman.getPrime(encoding='binary')</code>

<ul>
<li>Returns the Diffie-Hellman prime in the specified encoding, which can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.getGenerator(encoding='binary')</code>

<ul>
<li>Returns the Diffie-Hellman prime in the specified encoding, which can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.getPublicKey(encoding='binary')</code>

<ul>
<li>Returns the Diffie-Hellman public key in the specified encoding, which can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.getPrivateKey(encoding='binary')</code>

<ul>
<li>Returns the Diffie-Hellman private key in the specified encoding, which can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.setPublicKey(public_key, encoding='binary')</code>

<ul>
<li>Sets the Diffie-Hellman public key. Key encoding can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
<li><code>diffieHellman.setPrivateKey(public_key, encoding='binary')</code>

<ul>
<li>Sets the Diffie-Hellman private key. Key encoding can be <code>'binary'</code>, <code>'hex'</code>, or <code>'base64'</code>.</li>
</ul></li>
</ul>

<p><strong>NOTE</strong>: The API is still subject to change.</p>

<p>I would appreciate getting a note if you actually do something useful with it. <img src='http://ox.no/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Play around with it and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/diffie-hellman-support-in-node-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OpenID for node.js</title>
		<link>http://ox.no/posts/openid-for-node-js</link>
		<comments>http://ox.no/posts/openid-for-node-js#comments</comments>
		<pubDate>Sat, 08 Jan 2011 22:16:09 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[node.js nodejs openid software library client javascript code]]></category>

		<guid isPermaLink="false">http://ox.no/?p=275</guid>
		<description><![CDATA[I am happy to announce the immediate availability of my implementation of OpenID for node.js. I&#8217;ve spent a few nights working on this, which is my first node.js library, and I finally got to the point where the library was &#8230; <a href="http://ox.no/posts/openid-for-node-js">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am happy to announce the immediate availability of my implementation of <strong>OpenID for node.js</strong>. I&#8217;ve spent a few nights working on this, which is my first node.js library, and I finally got to the point where the library was complete enough for a first public release.</p>

<h2>Installation</h2>

<p>Installing is very simple using <a href="http://npmjs.org"><code>npm</code></a>:</p>

<pre><code>npm install openid 
</code></pre>

<p>If you don&#8217;t use npm, you can of course just download and <code>require</code>. Remember dependencies from the <code>lib</code> folder, and remember adding paths to <code>require.paths</code> if necessary.</p>

<h2>Usage</h2>

<p>One of the main design goals for the library has been simplicity. Using OpenID for node.js is pretty simple, here&#8217;s a minimal sample server:</p>

<pre><code>var openid = require('openid');
var url = require('url');
var server = require('http').createServer(
    function(req, res)
    {
        var parsedUrl = url.parse(req.url, true);
        if(parsedUrl.pathname == '/verify')
        {
            // Verify identity assertion
            var result = openid.verifyAssertion(req); // or req.url
            res.writeHead(200);
            res.end(result.authenticated ? 'Success <img src='http://ox.no/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ' : 'Failure <img src='http://ox.no/wordpress/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> ');
        }
        else if(parsedUrl.pathname == '/authenticate')
        {
            // Resolve identifier, associate, build authentication URL
            openid.authenticate(
                parsedUrl.query.openid_identifier, // user supplied identifier
                'http://example.com/verify', // our callback URL
                null, // realm (optional)
                false, // attempt immediate authentication first?
                function(authUrl)
                {
                    res.writeHead(302, { Location: authUrl });
                    res.end();
                });
        }
        else
        {
            // Deliver an OpenID form on all other URLs
            res.writeHead(200);
            res.end('&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;body&gt;'
                + '&lt;form method="get" action="/authenticate"&gt;'
                + '&lt;p&gt;Login using OpenID&lt;/p&gt;'
                + '&lt;input name="openid_identifier" /&gt;'
                + '&lt;input type="submit" value="Login" /&gt;'
                + '&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;');
        }
    });
server.listen(80);
</code></pre>

<h2>Source</h2>

<p>I use GitHub for source control, so you can follow <a href="http://github.com/havard">me</a> and the <a href="http://github.com/havard/node-openid">node-openid</a> repository there.</p>

<h2>Licensing</h2>

<p>OpenID for node.js is licensed under the MIT license. Details can be found in the <a href="http://github.com/havard/node-openid/raw/master/LICENSE"><code>LICENSE</code></a> file on GitHub. The library includes third-party code released under the MIT and BSD licenses, see <a href="http://github.com/havard/node-openid/raw/master/README.md">README</a> for details.</p>

<h2>Wishes for node.js</h2>

<p>I&#8217;ve come across a couple of missing features which I&#8217;d love to see in node.js in the near future:</p>

<ul>
<li>The <code>crypto</code> module should support Diffie-Hellman key exchange (OpenSSL supports it, so please provide bindings)</li>
<li>A big integer library should be available alongside the <code>crypto</code> module, and preferably seamlessly integrated with the <code>crypto</code> module &#8211; perhaps bindings to the <a href="http://gmplib.org/">GMP</a> library could suffice?</li>
<li>More seamless unit testing libraries would be good</li>
</ul>

<p>In addition, I would love to see a tailored IDE for node.js applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/openid-for-node-js/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Problems running .NET 4.0 tests using NUnit 2.5 with (or without) Continuous Testing?</title>
		<link>http://ox.no/posts/problems-running-net-4-0-tests-using-nunit-2-5-with-or-without-continuous-testing</link>
		<comments>http://ox.no/posts/problems-running-net-4-0-tests-using-nunit-2-5-with-or-without-continuous-testing#comments</comments>
		<pubDate>Wed, 11 Aug 2010 09:11:08 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Continuous Testing]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[continuous testing]]></category>
		<category><![CDATA[nunit]]></category>

		<guid isPermaLink="false">http://ox.no/?p=222</guid>
		<description><![CDATA[NUnit 2.5 up to and including 2.5.4 fails to properly detect certain revisions of .NET 4.0, causing it to crash. The issue is documented in this bug report on LaunchPad. The bug has been fixed in 2.5.5 and later, so &#8230; <a href="http://ox.no/posts/problems-running-net-4-0-tests-using-nunit-2-5-with-or-without-continuous-testing">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>NUnit 2.5 up to and including 2.5.4 fails to properly detect certain revisions of .NET 4.0, causing it to crash. The issue is documented in <a href="https://bugs.launchpad.net/nunitv2/+bug/561487">this bug report on LaunchPad</a>. The bug has been fixed in 2.5.5 and later, so <a href="http://www.nunit.org">go grab the latest version of NUnit 2.5</a> and run your tests smoothly again, preferably on each build using <a href="http://ox.no/software/continuoustesting">Continuous Testing</a>, of course. <img src='http://ox.no/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/problems-running-net-4-0-tests-using-nunit-2-5-with-or-without-continuous-testing/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocking HtmlHelper in ASP.NET MVC 2 and 3 using Moq</title>
		<link>http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq</link>
		<comments>http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq#comments</comments>
		<pubDate>Wed, 11 Aug 2010 08:51:39 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[Mock]]></category>
		<category><![CDATA[Moq]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Test]]></category>

		<guid isPermaLink="false">http://ox.no/?p=226</guid>
		<description><![CDATA[Still having trouble mocking HtmlHelper? This is an update to my previous post on mocking HtmlHelper way back when ASP.NET MVC RC1 was released. Eric notified me through a comment on the post and a question on StackOverflow that the &#8230; <a href="http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Still having trouble mocking HtmlHelper? This is an update to <a href="http://ox.no/posts/mocking-htmlhelper-in-aspnet-mvc-rc1-using-moq">my previous post on mocking HtmlHelper</a> way back when ASP.NET MVC RC1 was released. Eric notified me through <a href="http://ox.no/posts/mocking-htmlhelper-in-aspnet-mvc-rc1-using-moq#comment-840">a comment</a> on the post and a <a href="http://stackoverflow.com/questions/3445770/missingmethodexception-thrown-when-trying-to-mock-htmlhelper-with-moq">question on StackOverflow</a> that the code for ASP.NET MVC RC1 did not work with ASP.NET MVC 2.  The code in this post should work with ASP.NET MVC 2 and ASP.NET MVC 3 Preview 1.</p>

<p><pre class="brush: csharp; ">

public static HtmlHelper CreateHtmlHelper(ViewDataDictionary vd)
{
    Mock&lt;ViewContext&gt; mockViewContext = new Mock&lt;ViewContext&gt;(
        new ControllerContext(
            new Mock&lt;HttpContextBase&gt;().Object,
            new RouteData(),
            new Mock&lt;ControllerBase&gt;().Object),
        new Mock&lt;IView&gt;().Object,
        vd,
        new TempDataDictionary(),
        new Mock&lt;TextWriter&gt;().Object);
    var mockViewDataContainer = new Mock&lt;IViewDataContainer&gt;();
    mockViewDataContainer.Setup(v =&gt; v.ViewData)
        .Returns(vd);
    return new HtmlHelper(mockViewContext.Object,
                            mockViewDataContainer.Object);
}

</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/mocking-htmlhelper-in-asp-net-mvc-2-and-3-using-moq/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Continuous Testing for Visual Studio</title>
		<link>http://ox.no/posts/continuous-testing-for-visual-studio</link>
		<comments>http://ox.no/posts/continuous-testing-for-visual-studio#comments</comments>
		<pubDate>Sat, 08 May 2010 00:36:27 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Continuous Testing]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://ox.no/?p=161</guid>
		<description><![CDATA[The other night is was playing around with a side project. I try to use a rather strict TDD approach for these projects, and so I run my tests a lot of times as I move forward, and spend quite &#8230; <a href="http://ox.no/posts/continuous-testing-for-visual-studio">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The other night is was playing around with a side project. I try to use a rather strict TDD approach for these projects, and so I run my tests <em>a lot</em> of times as I move forward, and spend quite some time waiting for the result before I move forward. This is a tedious and frankly unnecessary manual step; what I needed was continuous testing &#8211; unit tests that test themselves continuously, making sure I don&#8217;t break anything.</p>

<p>I remembered reading about <a href="http://www.threeriversinstitute.org/junitmax/subscribe.html">JUnit Max</a> by <a href="http://www.threeriversinstitute.org/">Kent Beck</a>, a continuous testing plugin for Eclipse, that runs your unit tests in the background and unobtrusively tells you when a test fails, allowing you to do what you do best: write code. JUnit Max seems like a great thing, and now I needed the same thing for Visual Studio. A quick Google didn&#8217;t yield any add-ins, extensions or packages, so I decided to create one.</p>

<p>The result is Continuous Testing for Visual Studio, a small extension which runs your unit tests each time you build your solution, and reports failing tests to the error list so you can navigate to the line that failed and make the test pass. The extension significantly improves my workflow by removing a tedious manual step of running unit tests, so I encourage you to take it for a spin. Continuous Testing can be downloaded for <a href="/downloads/Continuous+Testing+for+Visual+Studio+2008">Visual Studio 2008</a> and <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/c074d3c6-71e2-4628-9e7c-7690e706aef4">Visual Studio 2010</a>. Future updates and versions will be announced on the <a href="/software/continuoustesting">Continuous Testing home page</a>.</p>

<p><strong>UPDATE Jun 17th, 2010</strong>: I&#8217;ve receive a lot of feedback through various solutions online. To be able to help you and/or improve Continuous Testing for Visual Studio, I need samples from you that reproduce the problems you are experiencing. Do not hesitate to leave a comment  here, and provide your e-mail address when commenting, and you will receive a reply.</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/continuous-testing-for-visual-studio/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Copyable available on GitHub</title>
		<link>http://ox.no/posts/copyable-available-on-github</link>
		<comments>http://ox.no/posts/copyable-available-on-github#comments</comments>
		<pubDate>Thu, 10 Dec 2009 23:10:29 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[copyable]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[open source]]></category>

		<guid isPermaLink="false">http://ox.no/?p=144</guid>
		<description><![CDATA[People actually download and use Copyable, and they tend to use it in scenarios I haven&#8217;t used it in. This results in bug reports and patch submissions. So far, these have been given to me by e-mail or by blog &#8230; <a href="http://ox.no/posts/copyable-available-on-github">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>People actually download and use Copyable, and they tend to use it in scenarios I haven&#8217;t used it in. This results in bug reports and patch submissions. So far, these have been given to me by e-mail or by blog comment, neither of which is a particularly great way of receiving them. So after receiving another one today, I finally got around to putting Copyable on <a href="http://github.com">GitHub</a>.</p>

<p>The version I put up includes several enhancements from the latest release:</p>

<ul>
<li>It uses <code>FormatterServices.GetUninitializedObject</code> and hence does not depend on a parameterless constructor or custom instance provider (but you can of course still create an instance provider if you want to control object initialization)</li>
<li>The bug with copy semantics for already visited objects submitted by Walter Oesch has been fixed</li>
<li>The bug with inherited fields found by Alex, and the patch submitted for it, has been incorporated</li>
</ul>

<p>Bleeding edge Copyable can be found at <a href="http://github.com/havard/copyable">http://github.com/havard/copyable</a>. The clone URL is <a href="git://github.com/havard/copyable.git">git://github.com/havard/copyable.git</a>. Now go fix your own bugs! Or even better, enhance the framework.</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/copyable-available-on-github/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Minimalistic MapReduce in .NET 4.0 with the new Task Parallel Library (TPL)</title>
		<link>http://ox.no/posts/minimalistic-mapreduce-in-net-4-0-with-the-new-task-parallel-library-tpl</link>
		<comments>http://ox.no/posts/minimalistic-mapreduce-in-net-4-0-with-the-new-task-parallel-library-tpl#comments</comments>
		<pubDate>Tue, 03 Nov 2009 22:58:52 +0000</pubDate>
		<dc:creator>Håvard</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[Parallel]]></category>
		<category><![CDATA[TPL]]></category>

		<guid isPermaLink="false">http://ox.no/?p=119</guid>
		<description><![CDATA[Among the news in .NET 4.0 are several additions by the Parallel Computing Platform Team. As I wandered through the documentation of the Task library with cloud computing and parallelism buzz in the back of my head, I got the &#8230; <a href="http://ox.no/posts/minimalistic-mapreduce-in-net-4-0-with-the-new-task-parallel-library-tpl">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Among the news in .NET 4.0 are several additions by the <a href="http://blogs.msdn.com/pfxteam/">Parallel Computing Platform Team</a>. As I wandered through the documentation of the Task library with cloud computing and parallelism buzz in the back of my head, I got the idea of using tasks to create a minimalistic MapReduce. Here&#8217;s the result, a rather crude and simple, but efficient MapReduce for you to play with and utilize!</p>

<!-- more -->

<h2>What is MapReduce?</h2>

<p>For those of you who don&#8217;t know what MapReduce is: MapReduce is a simplified interface for parallel data processing. MapReduce was initially described by the Google engineers Jeffrey Dean and Sanjay Ghemawat in the 2004 paper titled <a href="http://labs.google.com/papers/mapreduce.html">MapReduce: Simplified data processing on large clusters</a>.</p>

<p>MapReduce processes data by splitting the processing in to a set of transformations (in functional programming, this is called the &#8220;map&#8221; function (it maps or transforms an input to an output)). The results of the transformations are then combined into a single result (in functional programming, this is called the &#8220;reduce&#8221; function (it reduces a set of values to a single value)). On a sidenote, Linq has equivalent functions, but the names are different, presumably to make them more familiar to people with SQL knowledge. In Linq, map is called <code>Select</code>, and reduce is called <code>Aggregate</code>.</p>

<p>Shortly put, to process a huge set of data, you split the data into chunks and process each chunk in parallel. This eventually creates a new set of intermediary results, which is reduced to a single result.</p>

<h2>Implementing a minimalistic MapReduce in .NET 4.0</h2>

<p>The signature of my MapReduce function is
<pre class="brush: csharp; ">

static Task&lt;TResult&gt; Start&lt;TInput, TPartial, TResult&gt;(
  Func&lt;TInput, TPartial&gt; map, 
  Func&lt;TPartial[], TResult&gt; reduce, 
  params TInput[] inputs);&lt;/pre&gt;

</pre></p>

<p>In other words, to start a MapReduce run, you supply a <code>map</code> function, a <code>reduce</code> function, and a set of inputs. Each input will be turned into an intermediate result (of type <code>TPartial</code>). Inputs are transformed concurrently. When all inputs are transformed, the <code>reduce</code> function is called to transform the partial results into a final result (of type <code>TResult</code>). Cool!</p>

<p>The map part is implemented by starting a task for each supplied input using <code>Task.Factory.StartNew()</code>.</p>

<p><pre class="brush: csharp; ">

Task.Factory.StartNew(() =&gt; map(input));

</pre></p>

<p>The reduce part is implemented as a <a href="http://en.wikipedia.org/wiki/Continuation">continuation</a> of all the map tasks, meaning that the reduce task waits for all the map tasks to complete, and then executes. This is achieved using <code>Task.Factory.ContinueWhenAll</code>.</p>

<p><pre class="brush: csharp; ">

Task.Factory.ContinueWhenAll(
  mapTasks, 
  tasks =&gt; PerformReduce(reduce, tasks));

</pre></p>

<p>As you can see, the implementation is minimalistic and simple, and usage is likewise.</p>

<p>Here&#8217;s a simple example using MapReduce to calculate the <a href="http://en.wikipedia.org/wiki/Root_mean_square">root mean square (MSE)</a> of a set of values:
<pre class="brush: csharp; ">

var task = MapReduce.Start&lt;int, int, double&gt;(
  i =&gt; i * i,
  s =&gt; Math.Sqrt(s.Aggregate((a, b) =&gt; a + b) / 5),
  1, 2, 3, 4, 5);
// Wait for result
task.Wait();
// Prints 3.3166...
Console.WriteLine(task.Result);

</pre></p>

<p>Actual applications of MapReduce are of course far more interesting than this simple example.</p>

<h2>Applications of MapReduce</h2>

<p>MapReduce can essentially be applied to any problem where you need a number of things to be done in parallel. It can even be applied in cases where you don&#8217;t need a final result. Just return an arbitrary value as the result (or even better, implement a variant of my MapReduce which uses <code>Action&lt;T&gt;</code>).</p>

<p>A few obvious use cases:</p>

<ul>
<li>Distributed search</li>
<li>Distributed sort</li>
<li>Tokenization</li>
<li>Indexing</li>
<li>Log processing</li>
<li>Machine learning</li>
<li>General artificial intelligence</li>
<li>General data mining</li>
<li>Large scale image processing</li>
<li>&#8230;</li>
</ul>

<p>The list goes on and on, these are just a few things off the top of my head.</p>

<p>You can grab the <a href="http://ox.no/files/MapReduce.cs">source code for MapReduce here</a>. Since this is done in .NET 4.0, it requires Visual Studio 2010 Beta 2 or later.</p>

<p>As usual, play around with it, have fun, and let me know if you find it useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://ox.no/posts/minimalistic-mapreduce-in-net-4-0-with-the-new-task-parallel-library-tpl/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

