<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>The Code Decanter</title>
	<atom:link href="http://thecodedecanter.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecodedecanter.wordpress.com</link>
	<description>Give the code time to breathe and see how it develops...</description>
	<lastBuildDate>Fri, 02 Dec 2011 20:24:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='thecodedecanter.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>The Code Decanter</title>
		<link>http://thecodedecanter.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://thecodedecanter.wordpress.com/osd.xml" title="The Code Decanter" />
	<atom:link rel='hub' href='http://thecodedecanter.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Derivatives of a polynomial in F#</title>
		<link>http://thecodedecanter.wordpress.com/2011/10/08/derivatives-of-a-polynomial-in-f/</link>
		<comments>http://thecodedecanter.wordpress.com/2011/10/08/derivatives-of-a-polynomial-in-f/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 22:39:32 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thecodedecanter.wordpress.com/?p=186</guid>
		<description><![CDATA[Just because I was bored&#8230;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=186&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Just because I was bored&#8230;</p>
<p><pre class="brush: fsharp;">type Term = {Coefficient: int; Power: int}
type Term = {Coefficient: int; Power: int}
type Polynomial = list&lt;Term&gt;

let derivative polynomial =
    polynomial |&gt; List.map (fun term -&gt; {Coefficient = term.Coefficient * term.Power; Power = term.Power - 1}) |&gt; List.filter (fun x -&gt; x.Power &gt;= 0)

let prettyPrint polynomial =
    let sortedTerms = polynomial |&gt; List.sortBy (fun term -&gt; -term.Power)

    let rec printTerms terms =
        match terms with
        | [] -&gt; &quot;&quot;
        | [term] -&gt;
            match term.Power with
            | 0 -&gt; sprintf &quot;%d&quot; term.Coefficient
            | 1 -&gt; sprintf &quot;%dx&quot; term.Coefficient
            | n -&gt; sprintf &quot;%dx^%d&quot; term.Coefficient term.Power                           
        | h::t -&gt; printTerms [h] + &quot; + &quot; + printTerms t

    printTerms sortedTerms

let sample = [{Coefficient=3; Power=2};{Coefficient=5; Power=1};{Coefficient=4;Power=0}]
let derived = sample |&gt; derivative

printfn &quot;Polynomial:\t%s&quot; &lt;| prettyPrint sample
printfn &quot;Derivative:\t%s&quot; &lt;| prettyPrint derived

 </pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/186/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/186/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/186/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=186&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2011/10/08/derivatives-of-a-polynomial-in-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>Town Crier 1.1 now available on NuGet</title>
		<link>http://thecodedecanter.wordpress.com/2011/06/03/town-crier-1-1-now-available-on-nuget/</link>
		<comments>http://thecodedecanter.wordpress.com/2011/06/03/town-crier-1-1-now-available-on-nuget/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 19:07:34 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thecodedecanter.wordpress.com/?p=181</guid>
		<description><![CDATA[Town Crier can now be downloaded from NuGet There is now also some built in markdown support (thanks to friism). This provides a convenient way to send HTML emails where possible but with a human readable plaintext alternative whilst only writing one template: To install Town Crier into your project from the Visual Studio Package [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=181&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Town Crier can now be downloaded from NuGet <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There is now also some built in <a href="http://daringfireball.net/projects/markdown/basics" title="markdown">markdown</a> support (thanks to friism). This provides a convenient way to send HTML emails where possible but with a human readable plaintext alternative whilst only writing one template:<br />
<pre class="brush: csharp;">
            var factory = new MergedEmailFactory(new TemplateParser());

            var tokenValues = new Dictionary&lt;string, string&gt;
                                  {
                                      {&quot;name&quot;, &quot;Joe&quot;},
                                      {&quot;userid&quot;, &quot;123&quot;}
                                  };

            MailMessage message = factory
                .WithTokenValues(tokenValues)
                .WithSubject(&quot;Test Subject&quot;)
                .WithMarkdownBodyFromFile(@&quot;templates\sample-markdown.txt&quot;)
                .Create();
</pre></p>
<p>To install Town Crier into your project from the Visual Studio Package Console:<br />
<code>install-package towncrier</code> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/181/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/181/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/181/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=181&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2011/06/03/town-crier-1-1-now-available-on-nuget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>Temporary file helper class</title>
		<link>http://thecodedecanter.wordpress.com/2010/09/28/temporary-file-helper-class/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/09/28/temporary-file-helper-class/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 13:35:47 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[temporary files]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=171</guid>
		<description><![CDATA[Occasionally it’s necessary to output data into a temporary file, for example in order to pass data to an external program. I threw together this little helper class to help out in such situations. Use it like this:<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=171&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Occasionally it’s necessary to output data into a temporary file, for example in order to pass data to an external program. I threw together this little helper class to help out in such situations.</p>
<p><pre class="brush: csharp;">
public class TemporaryFile : IDisposable
{
    public string FilePath { get; protected set; }

    public TemporaryFile()
    {
        FilePath= Path.GetTempFileName();
    }

    public void Dispose()
    {
        if (File.Exists(FilePath))
            File.Delete(FilePath);
    }
}
</pre></p>
<p>Use it like this:</p>
<p><pre class="brush: csharp;">
using (var tempInputFile = new TemporaryFile())
{
   // Do stuff with tempInputFile.FilePath here...
}

// Dispose will be called at the end of the using statement and so the file will be deleted.
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=171&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/09/28/temporary-file-helper-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Microsoft Reactive Extensions to orchestrate time-bound data retrieval</title>
		<link>http://thecodedecanter.wordpress.com/2010/08/01/orchestrating-asynchronous-data-retrieval-with-reactive-extensions/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/08/01/orchestrating-asynchronous-data-retrieval-with-reactive-extensions/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 15:04:31 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[asynchronous programming]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[reactive extensions]]></category>
		<category><![CDATA[rx]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=142</guid>
		<description><![CDATA[Reactive Extensions makes it easy to orchestrate and synchronise asynchronous operations.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=142&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx">Microsoft Reactive Extensions</a> (usually referred to simply as <em>Rx</em>) is a library for orchestrating and synchronising asynchronous operations. It’s based on a <a href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/">beautiful mathematical duality</a> between IEnumerable/IEnumerator and their new counterparts (included in .NET 4), IObservable/IObserver. Documentation is unfortunately somewhat scarce and beyond the clichéd dictionary suggest and drag-and-drop examples it’s quite hard to find sample code. As ever though, the best way to learn something is to try and use it to solve a real-world problem.</p>
<p>Essentially you can think observables as push-based collections. Instead of <strong>pulling</strong> from an enumerable (e.g. with a for-each loop), the data is <strong>pushed</strong> at you by the observable.</p>
<h3>A little background</h3>
<p>One of my company&#8217;s websites displays statistics on various pages. The queries are dynamic enough and plenty enough that it is not practical to pre-calculate and cache all the results every few minutes, so instead we operate on an 80/20 rule. That is, 80% of our website views occur on 20% of the pages (usually new content on the homepage, or content that is newly linked to from other popular sites). Therefore we cache result of the each database query in memcached for a few minutes, the cache-key being a hashcode of the SQL query (<span style="font-size:xx-small;">that’s a simplification &#8211; we actually serialize the LINQ expression tree, but that’s for another blog post</span>).</p>
<p>Sometimes uncached statistics take a while to retrieve depending database load and latency. Since our primary concerns are total page load time/responsiveness we simply abort the request and hide the statistics from the page if they are not retrieved within a fixed amount of time. The <a href="http://stackoverflow.com/questions/299198/implement-c-generic-timeout/990566#990566">initial implementation</a> of this simply aborted the thread if a certain timeout had elapsed. Unfortunately this solution has a big problem.</p>
<h3>The death spiral</h3>
<p>The trouble with aborting the thread is that if a database operation times out, the result never makes it into the cache. This means the next time the page is hit another cache miss occurs and the SQL database gets hit again. Since this query is identical to the first it will probably also time out. The database load keeps increasing because it is repeatedly being hit with the same query whilst the result is never cached.</p>
<h3>The requirements in brief</h3>
<p>The basic logic we need is therefore as follows:</p>
<ul>
<li>Page view generates request for data.</li>
<li>Cache is checked for a specific key.
<ul>
<li>On cache timeout/error – cancel operation. Don’t hit SQL because if the cache is down it’s better to display the pages without the statistics and avoid hammering the SQL server.</li>
<li>On cache hit – return data.</li>
<li>On cache miss – request data from SQL.
<ul>
<li>On SQL timeout – hide the control but continue fetching the data in the background and place it into the cache when it finally returns.</li>
<li>On SQL success – return data, enter it into the cache.</li>
<li>On SQL error – abort, hide control.</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3>The problem</h3>
<p>Trying to write this logic using threading, locks and traditional synchronisation constructs is difficult, bug-prone, and results in horrific spaghetti-code.</p>
<h3>Reactive Extensions to the rescue</h3>
<p>Reactive Extensions provides us with a much nicer way to deal with these kinds of asynchronous operations.</p>
<p>To keep the example simple, I’ll use a console application instead of a web-app, and simulate the cache and SQL database. I’ll also forget about using the SQL query as the cache key and use an entity id instead. In order to run this example you will need to have the reactive extension assemblies installed which can be <a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx">downloaded from devlabs</a>.</p>
<p>The example makes use of a number of extension methods provided by Rx:</p>
<ul>
<li><strong>Defer</strong> – This defers an operation until an observable is subscribed to.</li>
<li><strong>Return</strong> – This creates an observable that returns a single result.</li>
<li><strong>Timeout</strong> – Causes an observable to throw an exception after a specified timeout. Note that although this means the observable is disposed and no further results will be yielded, the operation will continue to run. This is useful when you have side effects that need to occur, in this case, placing the result of long-running SQL query into the cache.</li>
<li><strong>Catch</strong> – Specifies another observable sequence to continue with when an exception occurs.</li>
<li><strong>Take</strong> – This is analogous to traditional LINQ. Remember though that unlike <strong>First</strong>() this does not cause execution of the query and so does not block.</li>
</ul>
<p>It also makes use of the <strong>Subject </strong>class. This is a special class that acts as both an observer and an observable. It allows multiple subscriptions to a single stream of events. It may not strictly be necessary in this example but I have found introducing subjects helps to avoid the easy mistake of subscribing twice to an observer and causing two lots of side-effects to occur.</p>
<p><strong>With further ado, the code. You will need to add project references to System.CoreEx and System.Reactive.</strong></p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:156bfe8a-1fd7-4969-b28e-22192b6c806f" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: csharp;">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace CacheExample
{
    public class CacheMissException : ApplicationException
    {

    }

    // Represents the entity we are trying to retrieve from the cache
    // or database
    public class ResultEntity
    {
        public ResultEntity(string value)
        {
            Value = value;
        }

        public string Value { get; set; }
    }

    public interface IResultRepository
    {
        ResultEntity GetResultById(int id);
    }

    public class DatabaseRepository : IResultRepository
    {
        public ResultEntity GetResultById(int id)
        {
            Console.WriteLine(&quot;Retrieving results from database...&quot;);

            // Increment the following wait time to simulate a
            //database timeout.
            Thread.Sleep(150);

            // Note that this code is still executed even if the
            // observer is disposed.
            // This, conveniently, allows for &quot;side-effects&quot;.
            // In this case we could put the result into the
            //cache so the next user gets a cache hit!
            Console.WriteLine(&quot;Retrieved result from database.&quot;);
            return new ResultEntity(&quot;Database Result&quot;);
        }
    }

    public class CacheRepository : IResultRepository
    {
        public ResultEntity GetResultById(int id)
        {
            Console.WriteLine(&quot;Retrieving result from cache...&quot;);

            //Increment the following value to simulate a cache timeout.
            Thread.Sleep(20);

            //Uncomment the next line to simulate a cache miss
            //throw new CacheMissException();

            Console.WriteLine(&quot;Retrieved result from cache!&quot;);
            return new ResultEntity(&quot;Cached Result&quot;);
        }
    }

    class Program
    {
        static readonly IResultRepository cacheRepository =
            new CacheRepository();
        static readonly IResultRepository databaseRepository =
            new DatabaseRepository();

        static void Main(string[] cmdLineParams)
        {
            int id = 123;
            var cacheTimeout = TimeSpan.FromMilliseconds(50);
            var databaseTimeout = TimeSpan.FromMilliseconds(200);

            var cacheObservable = Observable.Defer(
                        ()=&gt;Observable.Return(
                              cacheRepository.GetResultById(id)));
            var databaseObservable = Observable.Defer(
                        ()=&gt;Observable.Return(
                              databaseRepository.GetResultById(id)));

            // Try to retrieve the result from the cache, falling over
            // to the DB in case of cache miss.
            var cacheFailover = (cacheObservable
                .Timeout(cacheTimeout))
                .Catch&lt;ResultEntity, CacheMissException&gt;(
                    (x) =&gt;
                        {
                        Console.WriteLine(&quot;Cache miss. Attempting to
                                    retrieve from database.&quot;);
                        return databaseObservable
                                 .Timeout(databaseTimeout);
                        }
                )
                .Catch&lt;ResultEntity, TimeoutException&gt;(
                    (x) =&gt;
                    {
                        Console.WriteLine(&quot;Time out retrieving result
                                    from cache. Giving up.&quot;);
                        return Observable.Empty&lt;ResultEntity&gt;();
                    }
                );

            var result = new Subject&lt;ResultEntity&gt;();
            result.Take(1).Subscribe(
                  x=&gt; Console.WriteLine(&quot;SUCCESS: Result: &quot; + x.Value),
                  x=&gt; Console.WriteLine(&quot;FAILURE: Exception!&quot;),
                  () =&gt; Console.WriteLine(&quot;Sequence finished.&quot;));

            cacheFailover.Subscribe(result);

            Console.WriteLine(&quot;Press any key to exit.&quot;);
            Console.ReadKey();
        }
    }
}

</pre></p>
</div>
<p>I would recommend playing around with the code. Experiment with adjusting the timeouts and uncommenting the lines with notes by them to see what happens in different scenarios. If you haven’t used Rx before wrapping your head around observables can take a while. I would thoroughly recommend taking some time to watch the various <a href="http://channel9.msdn.com/tags/Rx/">channel 9 videos</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=142&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/08/01/orchestrating-asynchronous-data-retrieval-with-reactive-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>Town Crier &#8211; An open-source e-mail templating engine for .NET</title>
		<link>http://thecodedecanter.wordpress.com/2010/07/19/town-crier-an-open-source-e-mail-templating-engine-for-net/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/07/19/town-crier-an-open-source-e-mail-templating-engine-for-net/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 22:20:56 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[mail-merge]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[mass mail]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[templating]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=129</guid>
		<description><![CDATA[Most .NET developers tried to send HTML or text-based e-mail templates from their code at some point. Town Crier is an open-source library to try to remove some of the pain-points involved.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=129&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In medieval times, town criers were the primary means of making announcements to a community. Nowadays a man with a bell is a very imaginative &#8211; but not particularly practical &#8211; means of communication.</p>
<p>One common scenario, especially in the business world, is the need to send out an email to a large number of people. Of course a big anonymous email lacks the friendliness of the local loud-mouthed peasant and so we try to personalise the emails with individuals&#8217; names etc.</p>
<p>I suspect most .NET developers have come across this problem at some point in their career. This generally leads to a lot of messy string concatenation and trying to manhandle the System.Net.Mail.SmtpClient into doing what you want. With text-based emails this is ugly, when HTML is involved it becomes a world of pain.</p>
<p><a href="http://github.com/endeavour/town-crier">Town Crier</a> is a project I have been working on to simplify this scenario. The basic workflow for sending a templated e-mail is as follows:</p>
<ol>
<li>Create an email template.<br />
This can be either a plain-text or HTML file (or both). Tokens to be replaced are written like this: {%= customersname %}</p>
<p><strong>Sample email templates: </strong><br />
<a href="http://thecodedecanter.files.wordpress.com/2010/07/image.png"><img style="display:inline;border-width:0;" title="Sample HTML e-mail template" src="http://thecodedecanter.files.wordpress.com/2010/07/image_thumb.png?w=488&#038;h=340" border="0" alt="Sample HTML e-mail template" width="488" height="340" /></a><br />
<a href="http://thecodedecanter.files.wordpress.com/2010/07/image1.png"><img style="display:inline;border-width:0;" title="Sample text e-mail template" src="http://thecodedecanter.files.wordpress.com/2010/07/image_thumb1.png?w=495&#038;h=129" border="0" alt="Sample text e-mail template" width="495" height="129" /></a></li>
<li>Write some very simple code in the CLR language of your choice, in this case C#:<br />
<pre class="brush: csharp;">var factory = new MergedEmailFactory(new TemplateParser());

var tokenValues = new Dictionary&lt;string, string&gt;
                      {
                          {&quot;name&quot;, &quot;Joe Bloggs&quot;},
                          {&quot;age&quot;, &quot;21&quot;}
                      };

MailMessage message = factory
    .WithTokenValues(tokenValues)
    .WithSubject(&quot;Test Subject&quot;)
    .WithHtmlBodyFromFile(@&quot;templates\sample-email.html&quot;)
    .WithPlainTextBodyFromFile(@&quot;templates\sample-email.txt&quot;)
    .Create();

var from = new MailAddress(&quot;sender@test.com&quot;, &quot;Automated Emailer&quot;);
var to = new MailAddress(&quot;recipient@test.com&quot;, &quot;Joe Bloggs&quot;);
message.From = from;
message.To.Add(to);

var smtpClient = new SmtpClient();
smtpClient.Send(message);
</pre><br />
Of course it’s then trivial to loop through rows in a database, populate the dictionary and perform a “mail-merge” programatically.</p>
<p>One final handy tip &#8211; there is included a handy extension method to allow you to save the message to a .eml file:<br />
<pre class="brush: csharp;">message.Save(new FileStream(@&quot;output.eml&quot;, FileMode.CreateNew));</pre>
</li>
</ol>
<p>That’s pretty much it! It’s fairly basic but I’ve found it to be very useful. It’s also my first open-source project so please be nice!</p>
<p>I am releasing it under the <a href="http://www.gnu.org/copyleft/lesser.html">Lesser GNU Public Licence</a>. <strong><em>Go grab the sources at <a href="http://github.com/endeavour/town-crier">GitHub</a>.</em></strong></p>
<p><!-- Creative Commons License --><a href="http://creativecommons.org/licenses/LGPL/2.1/"><img src="http://creativecommons.org/images/public/cc-LGPL-a.png" border="0" alt="CC-GNU LGPL" /> </a></p>
<p><!-- /Creative Commons License --></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/129/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/129/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/129/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=129&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/07/19/town-crier-an-open-source-e-mail-templating-engine-for-net/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/07/image_thumb.png" medium="image">
			<media:title type="html">Sample HTML e-mail template</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/07/image_thumb1.png" medium="image">
			<media:title type="html">Sample text e-mail template</media:title>
		</media:content>

		<media:content url="http://creativecommons.org/images/public/cc-LGPL-a.png" medium="image">
			<media:title type="html">CC-GNU LGPL</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing map-reduce in F#</title>
		<link>http://thecodedecanter.wordpress.com/2010/05/24/implementing-map-reduce-in-f-sharp/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/05/24/implementing-map-reduce-in-f-sharp/#comments</comments>
		<pubDate>Mon, 24 May 2010 01:35:15 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[distributed computing]]></category>
		<category><![CDATA[mapreduce]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=106</guid>
		<description><![CDATA[Introduction MapReduce is a software paradigm popularised by Google in which we take a set of tuples (key-value pairs), transform (map) them into an intermediate set of key-value pairs, and then perform some aggregation (reduce) operation on the intermediate values to obtain a result set. This is a useful way to express a problem because [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=106&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="http://en.wikipedia.org/wiki/MapReduce">MapReduce</a> is a software paradigm popularised by Google in which we take a set of tuples (key-value pairs), transform (map) them into an intermediate set of key-value pairs, and then perform some aggregation (reduce) operation on the intermediate values to obtain a result set. This is a useful way to express a problem because it yields an obvious way to “divide and conquer” the computation in a way that lends itself to parallel/distributed computing, thus providing a fairly simple way to perform computations on extremely large data sets.</p>
<p>It can be quite difficult to grok at first, so I decided to try implementing one of the examples from the MongoDB documentation in F# (if interested, see <a href="http://www.mongodb.org/display/DOCS/MapReduce">shell example 2</a>). In this example, we have a list of people and the types of pet each of them has. We wish to calculate the total number of each animal.</p>
<h2>The Code</h2>
<p>Again, F# proves to be a remarkably succinct language to express problems, in this case the built in syntactic sugar for tuples is a godsend!</p>
<p>UPDATE (25-May-2010) – <em>Controlflow</em> helpfully suggested that I could make my original code somewhat neater by <a href="http://msdn.microsoft.com/en-us/library/dd547125.aspx">using pattern matching to decompose tuples</a>. I’ve updated the code below with these improvements.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:5d1372b4-11dd-4d2a-8aeb-625c307cc9de" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: fsharp;">
#light

// Simple example of map-reduce  in F#
// Counts the total numbers of each animal

// Map function for our problem domain
let mapfunc (k,v) =
    v |&gt; Seq.map (fun(pet) -&gt; (pet, 1))

// Reduce function for our problem domain
let reducefunc (k,(vs:seq&lt;int&gt;)) =
    let count = vs |&gt; Seq.sum
    k, Seq.ofList([count])

// Performs map-reduce operation on a given set of input tuples
let mapreduce map reduce (inputs:seq&lt;_*_&gt;) =
    let intermediates = inputs |&gt; Seq.map map |&gt; Seq.concat
    let groupings = intermediates |&gt; Seq.groupBy fst |&gt; Seq.map (fun(x,y) -&gt; x, Seq.map snd y)
    let results = groupings |&gt; Seq.map reduce
    results

// Run the example...
let alice = (&quot;Alice&quot;,[&quot;Dog&quot;;&quot;Cat&quot;])
let bob = (&quot;Bob&quot;,[&quot;Cat&quot;])
let charlie = (&quot;Charlie&quot;,[&quot;Mouse&quot;; &quot;Cat&quot;; &quot;Dog&quot;])
let dennis = (&quot;Dennis&quot;,[])

let people = [alice;bob;charlie;dennis]

let results = people |&gt; mapreduce mapfunc reducefunc

for result in results do
    let animal = fst result
    let count = ((snd result) |&gt; Seq.toArray).[0]
    printfn &quot;%s : %s&quot; animal (count.ToString())

printfn &quot;Press any key to exit.&quot;

System.Console.ReadKey() |&gt; ignore

</pre></p>
</div>
<p>This yields the expected results:</p>
<p><em>Dog : 2</em></p>
<p><em>Cat : 3</em></p>
<p><em>Mouse : 1</em></p>
<h2>Exercise for the reader</h2>
<p>Parallelise this implementation (for a single machine this should be trivial by using the Parallel LINQ integration provided in the <a href="http://fsharppowerpack.codeplex.com/">F# Powerpack</a>).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=106&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/05/24/implementing-map-reduce-in-f-sharp/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>Modelling heat transfer in F# using 100 lines of code</title>
		<link>http://thecodedecanter.wordpress.com/2010/04/30/modelling-the-2d-heat-equation-in-f-using-100-lines-of-code/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/04/30/modelling-the-2d-heat-equation-in-f-using-100-lines-of-code/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 22:01:14 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[F#]]></category>
		<category><![CDATA[Difference Equations]]></category>
		<category><![CDATA[Differential Equations]]></category>
		<category><![CDATA[Heat Equation]]></category>
		<category><![CDATA[Modelling]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=35</guid>
		<description><![CDATA[The aim Imagine we have a square coaster upon which we place a hot mug of tea. We wish to model the distribution of temperature across the coaster over time. For the sake of simplicity we will model the coaster only in two dimensions and we take the initial temperature across the surface to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=35&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>The aim</h2>
<p>Imagine we have a square coaster upon which we place a hot mug of tea. We wish to model the distribution of temperature across the coaster over time. For the sake of simplicity we will model the coaster only in two dimensions and we take the initial temperature across the surface to be <img src='http://s0.wp.com/latex.php?latex=20%5C%2C%5E%7B%5Ccirc%7D%5Cmathrm%7BC%7D&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='20&#92;,^{&#92;circ}&#92;mathrm{C}' title='20&#92;,^{&#92;circ}&#92;mathrm{C}' class='latex' /> except for a circle where the rim of the bottom of the mug touches the coaster, at which the temperature is <img src='http://s0.wp.com/latex.php?latex=80%5C%2C%5E%7B%5Ccirc%7D%5Cmathrm%7BC%7D&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='80&#92;,^{&#92;circ}&#92;mathrm{C}' title='80&#92;,^{&#92;circ}&#92;mathrm{C}' class='latex' />.</p>
<p>In this post I’m going to show how we can model the heat equation succinctly in F#. I’m going to consider the two-dimensional case and approximate the solution at discrete spatial mesh points and at discrete time periods.</p>
<p>We will also plot the results by mapping the temperature onto the brightness (i.e. a heat or intensity map).</p>
<p><a href="http://thecodedecanter.files.wordpress.com/2010/04/mug.png"><img style="display:inline;border-width:0;" title="100x100mm coaster with a hot mug of diameter 50mm placed upon it." src="http://thecodedecanter.files.wordpress.com/2010/04/mug_thumb.png?w=461&#038;h=370" border="0" alt="100x100mm coaster with a hot mug of diameter 50mm placed upon it." width="461" height="370" /></a></p>
<h2>The mathematics</h2>
<p>In two dimensions the <a href="http://en.wikipedia.org/wiki/Heat_equation">heat equation</a> &#8211; taking the size of the coaster to be 100mm square – is given by:</p>
<p><img src='http://s0.wp.com/latex.php?latex=u_%7Bt%7D+%3D+c+%5Ccdot+%28u_%7Bxx%7D+%2B+u_%7Byy%7D%29%2C+0+%5Cleq+x%2Cy+%5Cleq+100%2C+t+%5Cgeq+0&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='u_{t} = c &#92;cdot (u_{xx} + u_{yy}), 0 &#92;leq x,y &#92;leq 100, t &#92;geq 0' title='u_{t} = c &#92;cdot (u_{xx} + u_{yy}), 0 &#92;leq x,y &#92;leq 100, t &#92;geq 0' class='latex' /></p>
<p>where <img src='http://s0.wp.com/latex.php?latex=u%28t%2Cx%2Cy%29&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='u(t,x,y)' title='u(t,x,y)' class='latex' /> represents the temperature at time <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='t' title='t' class='latex' /> and at coordinates <img src='http://s0.wp.com/latex.php?latex=%28x%2Cy%29&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='(x,y)' title='(x,y)' class='latex' />.</p>
<p>We need to apply boundary conditions at the edges of the coaster. We will assume for simpliciy that the temperature along the edges of the coaster remains constant, that is:</p>
<p><img src='http://s0.wp.com/latex.php?latex=u%28t%2C0%2Cy%29+%3D+u%28t%2C100%2Cy%29+%3D+u%28t%2Cx%2C0%29+%3D+u%28t%2Cx%2C100%29+%3D+k&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='u(t,0,y) = u(t,100,y) = u(t,x,0) = u(t,x,100) = k' title='u(t,0,y) = u(t,100,y) = u(t,x,0) = u(t,x,100) = k' class='latex' /></p>
<p>We also need to set our initial conditions:</p>
<p><img src='http://s0.wp.com/latex.php?latex=u%280%2Cx%2Cy%29+%3D+x%5E2+%2B+y%5E2+%3D+r%5E2%2C+r%3D25&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='u(0,x,y) = x^2 + y^2 = r^2, r=25' title='u(0,x,y) = x^2 + y^2 = r^2, r=25' class='latex' /></p>
<p>To model this in F# we are going to represent the surface of the coaster using a 100&#215;100 matrix (the matrix class is included in the <a href="http://fsharppowerpack.codeplex.com/">F# powerpack</a>).</p>
<p>Using the <a href="http://en.wikipedia.org/wiki/Euler_method">Euler method</a> we can convert our continuous differential equation into a discrete difference equation:</p>
<p><img src='http://s0.wp.com/latex.php?latex=u_%7Bi%2Cj%7D%5E%7Bt%2B1%7D+%3D+u_%7Bi%2B1%2Cj%7D%5E%7Bt%7D+%2B+c+%5Ccdot+%28u_%7Bi-1%2Cj%7D%5E%7Bt%7D+%2B+u_%7Bi%2B1%2Cj%7D%5E%7Bt%7D+-+4u_%7Bi%2Cj%7D%5E%7Bt%7D+%2B+u_%7Bi%2Cj-1%7D%5E%7Bt%7D+%2B+u_%7Bi%2Cj%2B1%7D%5E%7Bt%7D%29&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='u_{i,j}^{t+1} = u_{i+1,j}^{t} + c &#92;cdot (u_{i-1,j}^{t} + u_{i+1,j}^{t} - 4u_{i,j}^{t} + u_{i,j-1}^{t} + u_{i,j+1}^{t})' title='u_{i,j}^{t+1} = u_{i+1,j}^{t} + c &#92;cdot (u_{i-1,j}^{t} + u_{i+1,j}^{t} - 4u_{i,j}^{t} + u_{i,j-1}^{t} + u_{i,j+1}^{t})' class='latex' /></p>
<p>For some constant <img src='http://s0.wp.com/latex.php?latex=c&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='c' title='c' class='latex' /> which represents the thermal conductivity of the surface. Note that <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='t' title='t' class='latex' /> here is a natural number representing discrete time values.</p>
<h2>Show me the code!</h2>
<p>The F# code runs very close to the mathematics so it should be self-documenting (although I’ve added some comments for readability). Plotting the results is relatively straightforward: we normalize the temperatures and represent them as shades of grey, white being hottest and black being coolest.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:dd8c7b17-a0df-4076-ba21-6b6daf56d6d9" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: fsharp;">
#light
open Microsoft.FSharp.Math
open System.Drawing
open System.Drawing.Imaging
open System.Windows.Forms
open Microsoft.FSharp.Collections
open System.Linq

// Flattens a 2D array into a sequence
let array2D_to_seq arr =
   seq {for i in 0..Array2D.length1 arr - 1 do
            for j in 0..Array2D.length2 arr - 1 do yield arr.[i,j]}

// Find maximum value in a matrix
let max_value_in_matrix m =
    m
    |&gt; Matrix.toArray2D
    |&gt; array2D_to_seq
    |&gt; PSeq.max

// Normalizes a matrix so its maximum value is 1
let normalize_matrix m = m * (1.0/(max_value_in_matrix m))

let mug_diameter = 50.0     //mm
let coaster_length = 100.0  //mm
let tolerance = 5.0         //we're operating on discrete space so the rim of the mug needs to have some thickness
let num_steps = 1000        //number of iterations to be modelled

// Number of rows and columns in the matrix
let rows = (int)coaster_length
let cols = (int)coaster_length

// Equation for a circle
let circle r x y = (x-coaster_length/2.0)**2.0 + (y-coaster_length/2.0)**2.0 - (mug_diameter/2.0)**2.0

// Inital conditions function
let initialValues (x:int) (y:int) =
    match x,y with
    | (x,y) when circle (mug_diameter/2.0) (float(x)) (float(y)) &gt;= 0.0 &amp;&amp; circle (mug_diameter/2.0) (float(x)) (float(y)) &lt;= tolerance**2.0 -&gt; 80.0
    |_ -&gt; 20.0

// Create matrix representing initial conditions
let initialConditions = Matrix.init rows cols initialValues |&gt; normalize_matrix

let c = 0.6                         //Thermal conductivity
let delta_t = ((1.0) / 2.0*c)/2.0   //Time interval

// Our difference equation
let rec temp_at x y (o:float) (l:float) (r:float) (t:float) (b:float) = o + c * delta_t * (r+l+4.0*o+t+b)

// Mapping matrix u(t) to u(t+1)
let newMatrix (m:matrix) = m |&gt; Matrix.mapi(fun i j temp -&gt;
    match (i,j) with
    | (i,j) when i = 0 || j = 0 || i = rows-1 || j = cols-1 -&gt; 0.0 //Boundary conditions
    |_ -&gt; temp_at i j (m.[i,j]) (m.[i-1,j]) (m.[i+1,j]) (m.[i,j+1]) (m.[i,j-1]))

// Recursive function to determine the temperatures at time t
let rec heatmap_at t = match t with
                       | 0 -&gt; initialConditions
                       |_ -&gt; heatmap_at (t-1) |&gt; newMatrix

let format = Imaging.PixelFormat.Format24bppRgb

let toBitmap (arr:Color[,]) =
    // Create the bitmap
    let image = new Bitmap(arr.GetLength(0),arr.GetLength(1),Imaging.PixelFormat.Format24bppRgb)
    for i=0 to image.Width-1 do
      for j=0 to image.Height-1 do
        image.SetPixel(i, j, (arr.[i,j]))
      done
    done
    image

let intensityMap intensity = Color.FromArgb((int (intensity * 255.0)),(int (intensity * 255.0)),(int (intensity * 255.0)))

let intensities =
    heatmap_at num_steps |&gt; normalize_matrix
    |&gt; Matrix.toArray2D
    |&gt; Array2D.map intensityMap

let heatBitmap = intensities |&gt; toBitmap

let form = new Form(
                Text = &quot;F# Heat Map&quot;,
                Size = heatBitmap.Size)

let pic_box = new PictureBox(
                   BorderStyle = BorderStyle.Fixed3D,
                   Image = heatBitmap,
                   Size = heatBitmap.Size,
                   Dock = DockStyle.Fill,
                   SizeMode = PictureBoxSizeMode.StretchImage)

form.Controls.Add( pic_box )

#if INTERACTIVE
form.Show()
#else
Application.Run(form)
#endif
</pre></p>
</div>
<h2>Let’s take it for a spin!</h2>
<p>Here I have taken snapshots at discrete times <img src='http://s0.wp.com/latex.php?latex=t&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='t' title='t' class='latex' /> 0, 50, 100, …, 1000 with <img src='http://s0.wp.com/latex.php?latex=c+%3D+0.6&amp;bg=ffffff&amp;fg=222222&amp;s=0' alt='c = 0.6' title='c = 0.6' class='latex' />.</p>
<p><a href="http://thecodedecanter.files.wordpress.com/2010/04/0.png"><img style="display:inline;border:0;" title="0" src="http://thecodedecanter.files.wordpress.com/2010/04/0_thumb.png?w=104&#038;h=104" border="0" alt="0" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/1.png"><img style="display:inline;border:0;" title="1" src="http://thecodedecanter.files.wordpress.com/2010/04/1_thumb.png?w=104&#038;h=104" border="0" alt="1" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/2.png"><img style="display:inline;border:0;" title="2" src="http://thecodedecanter.files.wordpress.com/2010/04/2_thumb.png?w=104&#038;h=104" border="0" alt="2" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/3.png"><img style="display:inline;border:0;" title="3" src="http://thecodedecanter.files.wordpress.com/2010/04/3_thumb.png?w=104&#038;h=104" border="0" alt="3" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/4.png"><img style="display:inline;border:0;" title="4" src="http://thecodedecanter.files.wordpress.com/2010/04/4_thumb.png?w=104&#038;h=104" border="0" alt="4" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/5.png"><img style="display:inline;border:0;" title="5" src="http://thecodedecanter.files.wordpress.com/2010/04/5_thumb.png?w=104&#038;h=104" border="0" alt="5" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/6.png"><img style="display:inline;border:0;" title="6" src="http://thecodedecanter.files.wordpress.com/2010/04/6_thumb.png?w=104&#038;h=104" border="0" alt="6" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/7.png"><img style="display:inline;border:0;" title="7" src="http://thecodedecanter.files.wordpress.com/2010/04/7_thumb.png?w=104&#038;h=104" border="0" alt="7" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/8.png"><img style="display:inline;border:0;" title="8" src="http://thecodedecanter.files.wordpress.com/2010/04/8_thumb.png?w=104&#038;h=104" border="0" alt="8" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/9.png"><img style="display:inline;border:0;" title="9" src="http://thecodedecanter.files.wordpress.com/2010/04/9_thumb.png?w=104&#038;h=104" border="0" alt="9" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/10.png"><img style="display:inline;border:0;" title="10" src="http://thecodedecanter.files.wordpress.com/2010/04/10_thumb.png?w=104&#038;h=104" border="0" alt="10" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/11.png"><img style="display:inline;border:0;" title="11" src="http://thecodedecanter.files.wordpress.com/2010/04/11_thumb.png?w=104&#038;h=104" border="0" alt="11" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/12.png"><img style="display:inline;border:0;" title="12" src="http://thecodedecanter.files.wordpress.com/2010/04/12_thumb.png?w=104&#038;h=104" border="0" alt="12" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/13.png"><img style="display:inline;border:0;" title="13" src="http://thecodedecanter.files.wordpress.com/2010/04/13_thumb.png?w=104&#038;h=104" border="0" alt="13" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/14.png"><img style="display:inline;border:0;" title="14" src="http://thecodedecanter.files.wordpress.com/2010/04/14_thumb.png?w=104&#038;h=104" border="0" alt="14" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/15.png"><img style="display:inline;border:0;" title="15" src="http://thecodedecanter.files.wordpress.com/2010/04/15_thumb.png?w=104&#038;h=104" border="0" alt="15" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/16.png"><img style="display:inline;border:0;" title="16" src="http://thecodedecanter.files.wordpress.com/2010/04/16_thumb.png?w=104&#038;h=104" border="0" alt="16" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/17.png"><img style="display:inline;border:0;" title="17" src="http://thecodedecanter.files.wordpress.com/2010/04/17_thumb.png?w=104&#038;h=104" border="0" alt="17" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/18.png"><img style="display:inline;border:0;" title="18" src="http://thecodedecanter.files.wordpress.com/2010/04/18_thumb.png?w=104&#038;h=104" border="0" alt="18" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/19.png"><img style="display:inline;border:0;" title="19" src="http://thecodedecanter.files.wordpress.com/2010/04/19_thumb.png?w=104&#038;h=104" border="0" alt="19" width="104" height="104" /></a> <a href="http://thecodedecanter.files.wordpress.com/2010/04/20.png"><img style="display:inline;border:0;" title="20" src="http://thecodedecanter.files.wordpress.com/2010/04/20_thumb.png?w=104&#038;h=104" border="0" alt="20" width="104" height="104" /></a></p>
<p>Quite an impressive simulation for just 100 lines of code &#8211; including comments and white space!</p>
<h2>References</h2>
<p><a href="http://www.cosy.sbg.ac.at/events/parnum05/book/horak1.pdf">Parallel Numerical Solution of 2-D Heat Equation</a>, Verena Horak and Peter Gruber.</p>
<p><a href="http://en.wikipedia.org/wiki/Heat_equation">The Heat Equation</a>, Wikipedia</p>
<p><a href="http://en.wikipedia.org/wiki/Euler_method">Euler method</a>, Wikipedia</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=35&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/04/30/modelling-the-2d-heat-equation-in-f-using-100-lines-of-code/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/mug_thumb.png" medium="image">
			<media:title type="html">100x100mm coaster with a hot mug of diameter 50mm placed upon it.</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/0_thumb.png" medium="image" />

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/1_thumb.png" medium="image">
			<media:title type="html">1</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/2_thumb.png" medium="image">
			<media:title type="html">2</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/3_thumb.png" medium="image">
			<media:title type="html">3</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/4_thumb.png" medium="image">
			<media:title type="html">4</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/5_thumb.png" medium="image">
			<media:title type="html">5</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/6_thumb.png" medium="image">
			<media:title type="html">6</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/7_thumb.png" medium="image">
			<media:title type="html">7</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/8_thumb.png" medium="image">
			<media:title type="html">8</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/9_thumb.png" medium="image">
			<media:title type="html">9</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/10_thumb.png" medium="image">
			<media:title type="html">10</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/11_thumb.png" medium="image">
			<media:title type="html">11</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/12_thumb.png" medium="image">
			<media:title type="html">12</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/13_thumb.png" medium="image">
			<media:title type="html">13</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/14_thumb.png" medium="image">
			<media:title type="html">14</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/15_thumb.png" medium="image">
			<media:title type="html">15</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/16_thumb.png" medium="image">
			<media:title type="html">16</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/17_thumb.png" medium="image">
			<media:title type="html">17</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/18_thumb.png" medium="image">
			<media:title type="html">18</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/19_thumb.png" medium="image">
			<media:title type="html">19</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/20_thumb.png" medium="image">
			<media:title type="html">20</media:title>
		</media:content>
	</item>
		<item>
		<title>Generating ISO-compliant timestamp strings in Javascript</title>
		<link>http://thecodedecanter.wordpress.com/2010/04/02/generating-iso-compliant-timestamp-strings-in-javascript/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/04/02/generating-iso-compliant-timestamp-strings-in-javascript/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 12:13:27 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=14</guid>
		<description><![CDATA[This Javascript snippet generates an ISO 8601-compliant timestamp string, for example: 2010-04-08T01:38:03.181Z. Very useful for making AJAX calls to ASP.NET websites since you can pass such a string to the System.DateTime.Parse(…) method in the .NET Framework.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=14&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This Javascript snippet generates an ISO 8601-compliant timestamp string, for example: <strong>2010-04-08T01:38:03.181Z</strong>. Very useful for making AJAX calls to ASP.NET websites since you can pass such a string to the System.DateTime.Parse(…) method in the .NET Framework.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:50b21975-3249-4612-bee8-44635854ca32" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: jscript;">
function PadZeros(value, desiredStringLength)
{
    var num = value + &quot;&quot;;
    while (num.length &lt; desiredStringLength)
    {
        num = &quot;0&quot; + num;
    }
    return num;
}
function ToIsoString(d)
{
return d.getUTCFullYear() + '-' + PadZeros(d.getUTCMonth() + 1, 2) + '-' + PadZeros(d.getUTCDate(), 2) + 'T' + PadZeros(d.getUTCHours(), 2) + ':' + PadZeros(d.getUTCMinutes(), 2) + ':' + PadZeros(d.getUTCSeconds(), 2) + '.' + PadZeros(d.getUTCMilliseconds(), 3) + 'Z';
}

// Example usage:
var myUtcString = ToIsoString(new Date());
</pre></p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=14&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/04/02/generating-iso-compliant-timestamp-strings-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>
	</item>
		<item>
		<title>One-click website deployment using TeamCity, NAnt, Git and Powershell.</title>
		<link>http://thecodedecanter.wordpress.com/2010/03/25/one-click-website-deployment-using-teamcity-nant-git-and-powershell/</link>
		<comments>http://thecodedecanter.wordpress.com/2010/03/25/one-click-website-deployment-using-teamcity-nant-git-and-powershell/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 11:53:18 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Deployment]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">https://thecodedecanter.wordpress.com/?p=3</guid>
		<description><![CDATA[Problem Until recently my organisation relied on FTP to push site updates. Whilst this certainly seems like a simple solution at first glance it soon becomes unmanageable. To name but a few of the difficulties: For large sites re-uploading every file takes a long time, so developers tend to try and push individual files relating [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=3&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Problem</h2>
<p>Until recently my organisation relied on FTP to push site updates. Whilst this certainly seems like a simple solution at first glance it soon becomes unmanageable. To name but a few of the difficulties:</p>
<ul>
<li>For large sites re-uploading every file takes a long time, so developers tend to try and push individual files relating to their set of changes. Nobody really knows which version of the build is live and files soon get out of sync and the site collapses.</li>
<li>If something does go wrong things have to be restored from a backup, which again takes time.</li>
<li>Tracking down bugs is difficult it’s nigh-on impossible to correlate the live site to a particular build source control.</li>
<li>Web farms are particularly problematic because the files have to manually be pushed to multiple nodes.</li>
</ul>
<h2>Requirements</h2>
<p>We needed a deployment solution to fit the following requirements:</p>
<ul>
<li>Bandwidth-friendly – deploys should only be transferring changes, not re-uploading the entire site.</li>
<li>Quick to switch between builds to minimise downtime</li>
<li>Easy to revert to previous builds</li>
<li>Able to easily deploy to multiple servers (web farms)</li>
<li>Platform-independent. We are primarily a Microsoft shop but didn’t want the deployment system to be tied to Visual Studio/ASP.NET.</li>
<li>Easy to deploy. Ideally it should be as simple as clicking ‘Build’ in Teamcity.</li>
<li>Ability to have multiple configurations, for example testing, staging and live.</li>
</ul>
<h2>Solution</h2>
<h3>Overview</h3>
<p>The solution essentially boils down to the following:</p>
<ul>
<li>Use NAnt to build our solutions and apply any configuration-specific changes (for example, web.config changes which need to be made for staging/live).</li>
<li>Use a version control system (git) to hold each successful build.</li>
<li>Have each server in the web farm frequently pull and apply the latest changes from the build server.</li>
</ul>
<p><a href="http://lh6.ggpht.com/_vyc5b2oyDVc/S6KNVN6jTqI/AAAAAAAAAB4/tcvcZQcxrbI/s1600-h/image5%5B3%5D.png"></a><a href="http://thecodedecanter.files.wordpress.com/2010/04/git-deploy.png"><img class="alignnone size-full wp-image-7" title="Deployment process" src="http://thecodedecanter.files.wordpress.com/2010/04/git-deploy.png?w=480" alt="Flow diagram of deploy process"   /></a></p>
<h3>Requirements</h3>
<p>You will need the following tools installed:</p>
<p>On the build server:</p>
<ul>
<li><a href="http://nant.sourceforge.net/">NAnt</a></li>
<li><a href="http://git-scm.com/">Git</a> (My suggestion would be to install <a href="http://code.google.com/p/gitextensions/">Git Extensions</a> which includes everything you need plus a few nice GUI tools for windows users)</li>
</ul>
<p>On each web server:</p>
<ul>
<li><a href="http://support.microsoft.com/kb/968929">Powershell</a></li>
<li><a href="http://git-scm.com/">Git</a> (again, I would recommend installing <a href="http://code.google.com/p/gitextensions/">Git Extensions</a>)</li>
</ul>
<h3>Step 1 – Build configurations</h3>
<p>Create a ‘DeploymentOverrides’ directory in the root of your solution and a subdirectory for each configuration (development, testing, staging, live etc.) The idea is that the contents of the relevant folder will be copied over the top of each successful build. In the case of ASP.NET for example you might want to put a different web.config in each folder.</p>
<h3>Step 2 – Create Git Repositories for the build outputs</h3>
<p>On the build server you’ll need to create git repositories to hold the successful outputs from each build. For example:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:09ee3c29-353b-4538-92f3-39bf16cffcb0" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: powershell;">
mkdir F:\GitRepositories\Testing\MyWebsite
mkdir F:\GitRepositories\Staging\MyWebsite
mkdir F:\GitRepositories\Live\MyWebsite

F:
cd F:\GitRepositories\Testing\MyWebsite
git init

cd F:\GitRepositories\Staging\MyWebsite
git init

cd F:\GitRepositories\Live\MyWebsite
git init
</pre></p>
</div>
<h3>Step 3 – NAnt build script</h3>
<p>NAnt is a great tool to automate builds. It uses an XML configuration to describe the different ‘targets’. The following example script holds a few different configuration options (Local, Testing, Staging and Live).</p>
<p>When NAnt is run the solution is compiled using MSBuild, the overrides are copied over from the relevant subdirectory of DeploymentOverrides, and the resultant output is committed its corresponding git repository.</p>
<p>By convention this file should be called <em>default.build</em> and placed in the root of your solution.</p>
<h3>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:6b267c37-b237-4715-9f1b-58b0efb24c29" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: xml; pad-line-numbers: true;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;project name=&quot;YourProjectName&quot; default=&quot;default&quot;&gt;

    &lt;!--
    Build configurations:
    Local        - For local builds/testing
    Testing    - Teamcity deploy to development server
    Staging - Teamcity deploy to staging server
    Live        - Teamcity deploy to live servers
    --&gt;

  &lt;property name=&quot;solutionFilename&quot; value=&quot;${project::get-name()}.sln&quot; /&gt;

    &lt;!-- This is the source folder. i.e. set this to the folder containing the output of the build --&gt;
  &lt;property name=&quot;msBuildOutputFolder&quot; value=&quot;Website&quot; /&gt;

  &lt;!-- manual targets to override above default --&gt;
  &lt;target name=&quot;local&quot;&gt;
      &lt;property name=&quot;deployTarget&quot; value=&quot;local&quot; /&gt;
  &lt;/target&gt;
  &lt;target name=&quot;testing&quot;&gt;
    &lt;property name=&quot;deployTarget&quot; value=&quot;testing&quot; /&gt;
  &lt;/target&gt;
  &lt;target name=&quot;staging&quot;&gt;
      &lt;property name=&quot;deployTarget&quot; value=&quot;staging&quot; /&gt;
  &lt;/target&gt;
  &lt;target name=&quot;live&quot;&gt;
      &lt;property name=&quot;deployTarget&quot; value=&quot;live&quot; /&gt;
  &lt;/target&gt;

  &lt;target name=&quot;setEnvironmentalProperties&quot;&gt;
    &lt;!-- Set deployment target to local if not explictly specified --&gt;
    &lt;if test=&quot;${not property::exists('deployTarget')}&quot;&gt;
          &lt;fail message=&quot;Must specify valid build target.&quot;/&gt;
      &lt;/if&gt;

    &lt;call target=&quot;setEnvironmentalPropertiesLocal&quot; if=&quot;${deployTarget=='local'}&quot; /&gt;
  &lt;call target=&quot;setEnvironmentalPropertiesTesting&quot; if=&quot;${deployTarget=='testing'}&quot; /&gt;
  &lt;call target=&quot;setEnvironmentalPropertiesStaging&quot; if=&quot;${deployTarget=='staging'}&quot; /&gt;
  &lt;call target=&quot;setEnvironmentalPropertiesLive&quot; if=&quot;${deployTarget=='live'}&quot; /&gt;

  &lt;/target&gt;

  &lt;target name=&quot;setEnvironmentalPropertiesLocal&quot;&gt;
    &lt;!-- Web config settings --&gt;
    &lt;property name=&quot;deploymentOverridesSource&quot; value=&quot;DeploymentOverrides/Local&quot; /&gt;

    &lt;!-- This is the destination git repository used to hold successful builds --&gt;
    &lt;property name=&quot;gitRepository&quot; value=&quot;SuccessfulBuilds/Local&quot; /&gt;
  &lt;/target&gt;

    &lt;target name=&quot;setEnvironmentalPropertiesTesting&quot;&gt;
    &lt;!-- Web config settings --&gt;
    &lt;property name=&quot;deploymentOverridesSource&quot; value=&quot;DeploymentOverrides/Testing&quot; /&gt;

    &lt;!-- This is the destination git repository used to hold successful builds --&gt;
    &lt;property name=&quot;gitRepository&quot; value=&quot;F:/GitRepositories/Testing/MyWebsite&quot; /&gt;
    &lt;/target&gt;

    &lt;target name=&quot;setEnvironmentalPropertiesStaging&quot;&gt;
    &lt;!-- Web config settings --&gt;
    &lt;property name=&quot;deploymentOverridesSource&quot; value=&quot;DeploymentOverrides/Staging&quot; /&gt;

    &lt;!-- This is the destination git repository used to hold successful builds --&gt;
    &lt;property name=&quot;gitRepository&quot; value=&quot;F:/GitRepositories/Staging/MyWebsite&quot; /&gt;
  &lt;/target&gt;

  &lt;target name=&quot;setEnvironmentalPropertiesLive&quot;&gt;
        &lt;!-- Web config settings --&gt;
    &lt;property name=&quot;deploymentOverridesSource&quot; value=&quot;DeploymentOverrides/Live&quot; /&gt;

    &lt;!-- This is the destination git repository used to hold successful builds --&gt;
    &lt;property name=&quot;gitRepository&quot; value=&quot;F:/GitRepositories/Live/MyWebsite&quot; /&gt;
  &lt;/target&gt;

  &lt;target name=&quot;default&quot; depends=&quot;compile&quot; /&gt;

  &lt;target name=&quot;compile&quot;&gt;
    &lt;msbuild project=&quot;${solutionFilename}&quot;&gt;
        &lt;property name=&quot;Configuration&quot; value=&quot;Release&quot;/&gt;
    &lt;/msbuild&gt;
  &lt;/target&gt;

  &lt;target name=&quot;deploy&quot; depends=&quot;compile, addToGit&quot; /&gt;

  &lt;target name=&quot;updateSettings&quot; depends=&quot;setEnvironmentalProperties&quot;&gt;
      &lt;!-- Copy config files for this build configuration over the output from the build --&gt;
      &lt;copy todir=&quot;${gitRepository}&quot; overwrite=&quot;true&quot;&gt;
      &lt;fileset defaultexcludes=&quot;false&quot; basedir=&quot;${deploymentOverridesSource}&quot;&gt;
          &lt;include name=&quot;**/*&quot; /&gt;
          &lt;exclude name=&quot;.do-not-delete&quot; /&gt;
    &lt;/fileset&gt;
  &lt;/copy&gt;
  &lt;/target&gt;

    &lt;!-- ************************************************************** --&gt;
    &lt;!-- *** Tasks to add successful build output to git repository *** --&gt;
    &lt;!-- ************************************************************** --&gt;

  &lt;target name=&quot;copyBuildOutputToGit&quot; depends=&quot;setEnvironmentalProperties&quot;&gt;

  &lt;!-- Delete entire working folder from git leaving only the main .git folder behind --&gt;
  &lt;delete&gt;
      &lt;fileset defaultexcludes=&quot;false&quot; basedir=&quot;${gitRepository}&quot;&gt;
          &lt;include name=&quot;**/*&quot; /&gt;
          &lt;exclude name=&quot;.git&quot; /&gt;
          &lt;exclude name=&quot;.git/**&quot; /&gt;
    &lt;/fileset&gt;
  &lt;/delete&gt;

  &lt;!-- Copy entire output of successful build into the git working folder --&gt;
  &lt;copy todir=&quot;${gitRepository}&quot;&gt;
      &lt;fileset defaultexcludes=&quot;false&quot; basedir=&quot;${msBuildOutputFolder}&quot;&gt;
          &lt;include name=&quot;**/*&quot; /&gt;
    &lt;/fileset&gt;
  &lt;/copy&gt;
  &lt;/target&gt;

  &lt;target name=&quot;addToGit&quot; depends=&quot;setEnvironmentalProperties, copyBuildOutputToGit, updateSettings&quot;&gt;
  &lt;!-- Commit the contents of the working folder to the git repository --&gt;

  &lt;!-- Write timestamp of build into a file. Useful for reference but also ensures there is always
       a change to commit. This way if commit fails we know there was actually an error.
       (git commit fails if the index is empty)
   --&gt;
  &lt;tstamp /&gt;
  &lt;echo message=&quot;NAnt build successful at ${tstamp.now}&quot; file=&quot;${gitRepository}/build.log&quot; append=&quot;false&quot;/&gt;

  &lt;!-- This check is necessary so that we don't inadvertently end up checking in files
  to the source code repository if the build repository doesn't exist! --&gt;
  &lt;if test=&quot;${not directory::exists(gitRepository + '/.git')}&quot; &gt;
         &lt;fail message=&quot;Git repository for build output is not initalised!&quot;/&gt;
  &lt;/if&gt;

  &lt;!-- Stage files to git index --&gt;
  &lt;exec append=&quot;true&quot; workingdir=&quot;${gitRepository}&quot; program=&quot;git&quot;&gt;
      &lt;arg value=&quot;add&quot; /&gt;
      &lt;arg path=&quot;${gitRepository}/.&quot; /&gt;
  &lt;/exec&gt;

  &lt;!-- Commit files --&gt;
  &lt;exec append=&quot;true&quot; workingdir=&quot;${gitRepository}&quot; program=&quot;git&quot;&gt;
      &lt;arg line=&quot;commit&quot; /&gt;
      &lt;arg value=&quot;-a&quot; /&gt;
      &lt;arg value=&quot;-m&quot; /&gt;
      &lt;arg value=&quot;Successful build: ${tstamp.now}&quot; /&gt;
  &lt;/exec&gt;

  &lt;!-- Update server info (for HTTP repositories) --&gt;
  &lt;exec append=&quot;true&quot; workingdir=&quot;${gitRepository}&quot; program=&quot;git&quot;&gt;
      &lt;arg line=&quot;update-server-info&quot; /&gt;
  &lt;/exec&gt;
  &lt;/target&gt;

&lt;/project&gt;
</pre></p>
</div>
</h3>
<h3>Step 4 – Set up Teamcity (optional)</h3>
<p>You will want to create a teamcity build for each different configuration (Testing, Staging, Live etc). Be sure to choose nant as the runner and set the target appropriately.</p>
<p>You can of course skip this step and simply call nant manually from the command line if you wish.</p>
<p><a href="http://thecodedecanter.files.wordpress.com/2010/04/teamcity-config.png"><img class="alignnone size-full wp-image-8" title="Teamcity configuration" src="http://thecodedecanter.files.wordpress.com/2010/04/teamcity-config.png?w=480" alt="Configuration settings for NAnt within teamcity"   /></a></p>
<h3>Step 5 – Expose the git repositories</h3>
<p>There are various ways to do this, but since we are only going to be pulling from the repository then setting it up as HTTP is the simplest method and provides some simple security (basic authentication).</p>
<p>I simply pointed create a new IIS website with its root at F:\GitRepositories and enabled basic authentication. Depending on your security requirements etc you may want to contemplate using SSL or other means of exposing the repository to the web servers (VPN, SCP, Samba etc).</p>
<h3>Step 6 – Clone the git repositories onto the web servers</h3>
<p>On the web servers, you will need to clone the appropriate git repository from the build server into the root each of your IIS applications, for example:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:e1b7773f-2e51-4607-b786-81a8ca07c92b" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: powershell; gutter: false;">
git clone http://username:password@mybuildserver.com/Live/MyWebsite
</pre></p>
</div>
<h3>Step 7 – Set up the servers to regularly pull the latest updates</h3>
<p>For simplicity, and because we needed to be able to spin up servers on demand without adjusting the configuration,we chose to have the web servers continuously poll for updates from the build server. This means that the build server doesn’t need to know anything about the web servers.</p>
<p>A push-based system might be more efficient (less network chatter, no need for polling) but it is left as an exercise for the reader!</p>
<p>In order to pull updates we just need to tell git to fetch and merge the latest changes. The following powershell script will automate this process and automatically fetch updates for every git repository. As a bonus, it also writes status updates to the windows event log.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:c0b10585-e337-4e85-a381-4b370815f325" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: powershell;">
# Perform fetch on all git repositories immediately beneath F:\git-deploy-repos
F:
cd F:\git-deploy-repos
dir | %{
    if (test-path &quot;$_\.git&quot;)
    {
        echo &quot;Performing fetch on : $_&quot;
        cd $_
        git fetch
        # Writing an event
        $EventLog = New-Object System.Diagnostics.EventLog('Application')
        $EventLog.MachineName = &quot;.&quot;
        $EventLog.Source = &quot;Fetch-Updates&quot;
        if ($?)
        {
        echo &quot;Fetch on $_ completed&quot;
        $EventLog.WriteEntry(&quot;Successfully fetched updates for $_&quot;,&quot;Information&quot;, $EventID)
                echo &quot;Applying changes to dev build: $_&quot;
                git clean -f -d
                git reset --hard head
                git merge origin/master
                if ($?)
                {
                    echo &quot;Changed succesfully applied to: $_&quot;
                    $EventLog.WriteEntry(&quot;Successfully applied updates for build $_&quot;,&quot;Information&quot;, $EventID)
                }
                else
                {
                    echo &quot;Failed to apply changes to: $_&quot;
                    $EventLog.WriteEntry(&quot;Failed to apply updates for build $_&quot;,&quot;Error&quot;, $EventID)
                }
        }
        else
        {
        echo &quot;Fetch on $_ failed&quot;
        $EventLog.WriteEntry(&quot;Failed to fetch updates for $_&quot;,&quot;Error&quot;, $EventID)
        }
        cd ..
    }
}
</pre></p>
</div>
<p>Set up a windows scheduled task to run this powershell script every few minutes and you are done <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Step 8 – Take it for a spin!</h3>
<p>Now all the configuration is done deployment is as simple as clicking ‘build’ in teamcity. This will build the solution, copy in any configuration-specific overrides (web.config etc.), and add it to the local git repository. The next time the scheduled task runs on each of the web servers the changes will be pulled over the network and then applied to the live website.</p>
<p>If you need to revert to the previous build you can simply run the following command on each of the web servers.</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:da2e89ff-c9d5-48de-8425-81a9f1c47e66" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;"><pre class="brush: powershell; gutter: false;">
git reset --hard HEAD^
</pre></p>
</div>
<p>Of course you can revert to any build you like! Git Extensions really comes into its own in this scenario because it means you can easily visualise the timeline and view changes between different builds. Switching between builds a couple of clicks!</p>
<p><a href="http://thecodedecanter.files.wordpress.com/2010/04/git-extensions.png"><img class="alignnone size-full wp-image-9" title="Viewing changes between deploys" src="http://thecodedecanter.files.wordpress.com/2010/04/git-extensions.png?w=480" alt="Git Extensions diff screen showing changes between deploys"   /></a></p>
<h3>See also</h3>
<p>Rob Conery has also proposed a git-based solution for website deployments which is worth a read: <a title="http://blog.wekeroad.com/2009/11/23/deploying-a-web-application-with-git-and-ftp" href="http://blog.wekeroad.com/2009/11/23/deploying-a-web-application-with-git-and-ftp">http://blog.wekeroad.com/2009/11/23/deploying-a-web-application-with-git-and-ftp</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/thecodedecanter.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/thecodedecanter.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/thecodedecanter.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thecodedecanter.wordpress.com&amp;blog=13405980&amp;post=3&amp;subd=thecodedecanter&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://thecodedecanter.wordpress.com/2010/03/25/one-click-website-deployment-using-teamcity-nant-git-and-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/51a043c53ce525e2105b9c4fc48c44a3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thecodedecanter</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/git-deploy.png" medium="image">
			<media:title type="html">Deployment process</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/teamcity-config.png" medium="image">
			<media:title type="html">Teamcity configuration</media:title>
		</media:content>

		<media:content url="http://thecodedecanter.files.wordpress.com/2010/04/git-extensions.png" medium="image">
			<media:title type="html">Viewing changes between deploys</media:title>
		</media:content>
	</item>
	</channel>
</rss>
