<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Veggerby : IBlog</title>
	
	<link>http://blog.veggerby.dk</link>
	<description>Low decoupling, highly incoherent</description>
	<lastBuildDate>Fri, 28 May 2010 19:46:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/veggerby" /><feedburner:info uri="veggerby" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>SQL Script to Get Row Count of All Tables in Database</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/PjReJztdQEU/</link>
		<comments>http://blog.veggerby.dk/2010/05/sql-script-to-get-row-count-of-all-tables-in-database/#comments</comments>
		<pubDate>Fri, 28 May 2010 19:46:20 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2010/05/28/sql-script-to-get-row-count-of-all-tables-in-database/</guid>
		<description><![CDATA[There is an undocumented built-in stored procedure than iterates over all tables in a database and executes a SQL script &#34;sp_msforeachtable&#34; which makes the job pretty straightforward: sp_msforeachtable &#34;SELECT '?', COUNT(*) FROM ?&#34; Another nifty little sproc to use is the sp_spaceused which will besides row count return reserved size, data size, index size and [...]]]></description>
			<content:encoded><![CDATA[<p>There is an undocumented built-in stored procedure than iterates over all tables in a database and executes a SQL script &quot;sp_msforeachtable&quot; which makes the job pretty straightforward:
<pre>sp_msforeachtable &quot;SELECT '?', COUNT(*) FROM ?&quot;</pre>
<p>
  <br />Another nifty little sproc to use is the <a href="http://msdn.microsoft.com/en-us/library/ms188776.aspx">sp_spaceused</a> which will besides row count return reserved size, data size, index size and unused size of a given table. Combine the two and you get a pretty nice list: </p>
<pre>CREATE TABLE #TempTable
(
    tableName varchar(100),
    numberofRows varchar(100),
    reservedSize varchar(50),
    dataSize varchar(50),
    indexSize varchar(50),
    unusedSize varchar(50)
)
GO

EXEC sp_msforeachtable &quot;INSERT #TempTable EXEC sp_spaceused '?'&quot;
GO

SELECT * FROM #TempTable

DROP TABLE #TempTable
GO</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/wTKu-d6phrJW9-SV8XMgJ-UpavE/0/da"><img src="http://feedads.g.doubleclick.net/~a/wTKu-d6phrJW9-SV8XMgJ-UpavE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/wTKu-d6phrJW9-SV8XMgJ-UpavE/1/da"><img src="http://feedads.g.doubleclick.net/~a/wTKu-d6phrJW9-SV8XMgJ-UpavE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/PjReJztdQEU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2010/05/sql-script-to-get-row-count-of-all-tables-in-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2010/05/sql-script-to-get-row-count-of-all-tables-in-database/</feedburner:origLink></item>
		<item>
		<title>OAuth for Dummies</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/qNI_2JgJVvc/</link>
		<comments>http://blog.veggerby.dk/2009/10/oauth-for-dummies/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:40:00 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OAuth]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/29/oauth-for-dummies/</guid>
		<description><![CDATA[Having developed a little feature where I had to publish a Tweet to uh… Twitter, I did a checkup on how OAuth actually works. If you have the time you can go through Beginner’s Guide to OAuth, which is really excellent and was my source or introduction to OAuth. I’ll just condense it a little [...]]]></description>
			<content:encoded><![CDATA[<p>Having developed a little feature where I had to publish a Tweet to uh… <a href="http://twitter.com/">Twitter</a>, I did a checkup on how <a href="http://oauth.net/">OAuth</a> actually works. If you have the time you can go through <a href="http://hueniverse.com/oauth/">Beginner’s Guide to OAuth</a>, which is really excellent and was my source or introduction to OAuth. I’ll just condense it a little further, mostly because it is a good way to actually “get it”.</p>
<h2>What is OAuth?</h2>
<p><strong>OAUth makes it possible for providers to communicate in a secure and authenticated manor, without needing to share user secrets (username/password).</strong> For example it can allow the users of my web application to post Tweets to their Twitter account without needing to specify their username and password (except if the need to login to the Twitter site).</p>
<h2>Who is involved?</h2>
<p>Just to set the scene and get into the terms used, the actors involved are:</p>
<p>We want to get access to the <strong>Service Provider</strong>, e.g. Twitter.</p>
<p>The <strong>Consumer </strong>would like to access a resource on the Service Provider, e.g. my application.</p>
<p>The <strong>User</strong> want to access a resource on the Service Provider via the Consumer, e.g. post a Tweet using my application.</p>
<h2>How does it work?</h2>
<p>Seen from a larger perspective the idea is that the 3 actors (the Service Provider, the Consumer and the User) communicate with each other in such a way that all agree on who is who.</p>
<p>In more technical terms, all 3 actors generates and present various tokens (share secrets) to each other, which when combined establishes a trusted relationship between the Consumer and the Service Provider on behalf of the User.</p>
<h3>Step-by-Step</h3>
<p>A User want to perform an action on the Consumer which requires access to the/a protected resource on the Service Provider, e.g. create a Tweet.</p>
<ol>
<li>The Consumer contacts the Service Provider, requesting a <strong>Request Token</strong> and a <strong>Request Secret</strong>. </li>
<li>The User (e.g. his/her browser) is then redirected to the Service Provider presenting the <strong>Request Token</strong>. </li>
<li>The Service Provider validates the user and request approval from the User that the Consumer (found via the <strong>Request Token</strong>) can access the User’s protected resource. </li>
<li>The Service Provider generates an <strong>Access Token</strong> and an <strong>Access Secret</strong>. </li>
<li>The User (e.g. his/her browser) is then redirected to the Consumer, presenting the <strong>Access Token</strong> (the <strong>Access Secret</strong> is kept um… secret). </li>
<li>The Consumer now takes the <strong>Access Token</strong> and the <strong>Request Secret</strong> and asks the Service Provider for the <strong>Access Secret</strong>. </li>
<li>Once the Consumer has the <strong>Access Token</strong> and the <strong>Access Secret</strong>, it can access the protected resource. </li>
</ol>
<p>The point of presenting the <strong>Request Secret</strong> to the Service Provider in step 6 is so that replays cannot be performed using the <strong>Access Token</strong> alone.</p>
<p>The <strong>Tokens</strong> are used to communicate between the Consumer and the Service Provider <u>via</u> the User (his/her browser). The <strong>Secrets</strong> are kept between the Consumer and the Service Provider.</p>
<h2>Now what?</h2>
<p>Once the relationship is in place, the “real” communication can take place. This is where it gets hairy and where we’ll stop for this dummy introduction. </p>
<p>However during my implementation I found a little problem with the way .NET <a href="http://msdn.microsoft.com/en-us/library/zttxte6w.aspx">UrlEncode</a> works – it is simply not compatible with OAuth. I found an <a href="http://stackoverflow.com/questions/846487/how-to-get-uri-escapedatastring-to-comply-with-rfc-3986">implementation</a> by <a href="http://blog.nerdbank.net/">Andrew Arnott</a>, who is OAuth/OpenID aficionado and author of <a href="https://www.ohloh.net/p/dotnetopenauth/">DotNetOpenAuth</a> that does this and is <a href="http://www.faqs.org/rfcs/rfc3986.html">RFC 3986</a> compliant (it basically used the UrlEncode from .NET and then fixes what is broken):</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;summary&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// The set of characters that are unreserved in RFC 2396 but are NOT unreserved in RFC 3986.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;/summary&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">private</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">readonly</span> <span style="color: #0000ff">string</span>[] UriRfc3986CharsToEscape = <span style="color: #0000ff">new</span>[] { &quot;<span style="color: #8b0000">!</span>&quot;, &quot;<span style="color: #8b0000">*</span>&quot;, &quot;<span style="color: #8b0000">'</span>&quot;, &quot;<span style="color: #8b0000">(</span>&quot;, &quot;<span style="color: #8b0000">)</span>&quot; };
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;summary&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// Escapes a string according to the URI data string rules given in RFC 3986.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;/summary&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;param name=&quot;value&quot;&gt;The value to escape.&lt;/param&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;returns&gt;The escaped value.&lt;/returns&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;remarks&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// The &lt;see cref=&quot;Uri.EscapeDataString&quot;/&gt; method is &lt;i&gt;supposed&lt;/i&gt; to take on</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// RFC 3986 behavior if certain elements are present in a .config file.  Even if this</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// actually worked (which in my experiments it &lt;i&gt;doesn't&lt;/i&gt;), we can't rely on every</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// host actually having this configuration element present.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #808080">/// &lt;/remarks&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> UrlEncodeRfc3986(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// Start with RFC 2396 escaping by calling the .NET method to do the work.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// This MAY sometimes exhibit RFC 3986 behavior (according to the documentation).</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// If it does, the escaping we do that follows it will be a no-op since the</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// characters we search for to replace can't possibly exist in the string.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    var escaped = <span style="color: #0000ff">new</span> StringBuilder(Uri.EscapeDataString(<span style="color: #0000ff">value</span>));
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// Upgrade the escaping to RFC 3986, if necessary.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; UriRfc3986CharsToEscape.Length; i++)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        escaped.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0]));
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// Return the fully-RFC3986-escaped string.</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> escaped.ToString();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/IHyR2LpSZi1LDqcEiwY0XLxydq8/0/da"><img src="http://feedads.g.doubleclick.net/~a/IHyR2LpSZi1LDqcEiwY0XLxydq8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/IHyR2LpSZi1LDqcEiwY0XLxydq8/1/da"><img src="http://feedads.g.doubleclick.net/~a/IHyR2LpSZi1LDqcEiwY0XLxydq8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/qNI_2JgJVvc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/10/oauth-for-dummies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/10/oauth-for-dummies/</feedburner:origLink></item>
		<item>
		<title>ISO 8601/RFC 3339 Compatible Dates</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/_SWaNXRT0jw/</link>
		<comments>http://blog.veggerby.dk/2009/10/iso-8601rfc-3339-compatible-dates/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 15:09:00 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Dates]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[ISO]]></category>
		<category><![CDATA[RFC]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/10/04/iso-8601rfc-3339-compatible-dates/</guid>
		<description><![CDATA[There are not standard format specifiers for date that takes a date and converts it to an ISO 8601 or RFC 3339 compatible date. Here are two extension methods that does just that. public static string ToISO8601(this DateTime date) { return date.ToString(&#34;yyyy-MM-dd&#34;); } public static string ToRFC3339(this DateTime date) { return date.ToUniversalTime().ToString(&#34;yyyy-MM-ddThh:mm:ssZ&#34;); }]]></description>
			<content:encoded><![CDATA[<p>There are not standard format specifiers for date that takes a date and converts it to an <a href="http://en.wikipedia.org/wiki/ISO_8601#Dates">ISO 8601</a> or <a href="http://www.faqs.org/rfcs/rfc3339.html">RFC 3339</a> compatible date. Here are two extension methods that does just that.</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToISO8601(<span style="color: #0000ff">this</span> DateTime date)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> date.ToString(&quot;<span style="color: #8b0000">yyyy-MM-dd</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRFC3339(<span style="color: #0000ff">this</span> DateTime date)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> date.ToUniversalTime().ToString(&quot;<span style="color: #8b0000">yyyy-MM-ddThh:mm:ssZ</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/T1c4e75MVhB2GxAK-0t_gHkTQIk/0/da"><img src="http://feedads.g.doubleclick.net/~a/T1c4e75MVhB2GxAK-0t_gHkTQIk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/T1c4e75MVhB2GxAK-0t_gHkTQIk/1/da"><img src="http://feedads.g.doubleclick.net/~a/T1c4e75MVhB2GxAK-0t_gHkTQIk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/_SWaNXRT0jw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/10/iso-8601rfc-3339-compatible-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/10/iso-8601rfc-3339-compatible-dates/</feedburner:origLink></item>
		<item>
		<title>Generating a Slug From a String</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/Cskz5oKOHk4/</link>
		<comments>http://blog.veggerby.dk/2009/10/generating-a-slug-from-a-string/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 18:41:00 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Slug]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/10/02/generating-a-slug-from-a-string/</guid>
		<description><![CDATA[I can’t (and won’t) take full credit for this extension method. The hardcore Unicode stuff is from Michael Kaplan’s blog (jeez, he is hardcore). There is a little danish “stuff” included, for special characters æ, ø and å, which can also be written “ae”, “oe” an “aa”. public static string ToSlug(this string message) { // [...]]]></description>
			<content:encoded><![CDATA[<p>I can’t (and won’t) take full credit for this extension method. The hardcore Unicode stuff is from <a href="http://blogs.msdn.com/michkap/archive/2007/05/14/2629747.aspx">Michael Kaplan’s blog</a> (jeez, he is hardcore). There is a little danish “stuff” included, for special characters æ, ø and å, which can also be written “ae”, “oe” an “aa”.</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToSlug(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> message)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// replace space with -</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = Regex.Replace(message, @&quot;<span style="color: #8b0000">[\s/\\\.,+|_]+</span>&quot;, &quot;<span style="color: #8b0000">-</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// normalize the message </span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = message.Normalize(NormalizationForm.FormD);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    message = message.Replace(&quot;<span style="color: #8b0000">ø</span>&quot;, &quot;<span style="color: #8b0000">oe</span>&quot;).Replace(&quot;<span style="color: #8b0000">Ø</span>&quot;, &quot;<span style="color: #8b0000">Oe</span>&quot;).Replace(&quot;<span style="color: #8b0000">æ</span>&quot;, &quot;<span style="color: #8b0000">ae</span>&quot;).Replace(&quot;<span style="color: #8b0000">Æ</span>&quot;, &quot;<span style="color: #8b0000">Ae</span>&quot;).Replace(&quot;<span style="color: #8b0000">å</span>&quot;, &quot;<span style="color: #8b0000">aa</span>&quot;).Replace(&quot;<span style="color: #8b0000">Å</span>&quot;, &quot;<span style="color: #8b0000">Aa</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    StringBuilder result = <span style="color: #0000ff">new</span> StringBuilder();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; message.Length; i++)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(message[i]);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">if</span> (uc != UnicodeCategory.NonSpacingMark)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">            result.Append(message[i]);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> Regex.Replace(result.ToString().Normalize(NormalizationForm.FormC), @&quot;<span style="color: #8b0000">[^a-zA-Z0-9\-]</span>&quot;, &quot;<span style="color: #8b0000"></span>&quot;).ToLower();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/TfOz0GjhQQoc2tQepZ48IOLYao4/0/da"><img src="http://feedads.g.doubleclick.net/~a/TfOz0GjhQQoc2tQepZ48IOLYao4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/TfOz0GjhQQoc2tQepZ48IOLYao4/1/da"><img src="http://feedads.g.doubleclick.net/~a/TfOz0GjhQQoc2tQepZ48IOLYao4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/Cskz5oKOHk4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/10/generating-a-slug-from-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/10/generating-a-slug-from-a-string/</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC Gravatar HtmlHelper</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/e8cbSyC-mO0/</link>
		<comments>http://blog.veggerby.dk/2009/09/asp-net-mvc-gravatar-htmlhelper/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 19:08:00 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Gravatar]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/30/asp-net-mvc-gravatar-htmlhelper/</guid>
		<description><![CDATA[Here is a quick little URL Helper extension method to add Gravatar images/photos/avatars to your page: public static string GravatarUrl(this UrlHelper url, string email, int size) { string imageUrl = ConfigurationManager.AppSettings[&#34;DefaultGravatar&#34;]; if (imageUrl.StartsWith(&#34;~/&#34;)) { imageUrl = url.Absolute(imageUrl); } if (string.IsNullOrEmpty(email)) { return imageUrl; } string md5 = email.ToLowerInvariant().MD5(); return string.Format( &#34;http://www.gravatar.com/avatar/{0}.jpg?d={1}&#38;s={2}&#38;r=g&#34;, md5.ToLowerInvariant(), url.Encode(imageUrl), size); } [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick little <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx">URL Helper</a> extension method to add <a href="http://gravatar.com/">Gravatar</a> images/photos/avatars to your page:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GravatarUrl(<span style="color: #0000ff">this</span> UrlHelper url, <span style="color: #0000ff">string</span> email, <span style="color: #0000ff">int</span> size)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> imageUrl = ConfigurationManager.AppSettings[&quot;<span style="color: #8b0000">DefaultGravatar</span>&quot;];
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (imageUrl.StartsWith(&quot;<span style="color: #8b0000">~/</span>&quot;))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        imageUrl = url.Absolute(imageUrl);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (<span style="color: #0000ff">string</span>.IsNullOrEmpty(email))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> imageUrl;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> md5 = email.ToLowerInvariant().MD5();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        &quot;<span style="color: #8b0000">http://www.gravatar.com/avatar/{0}.jpg?d={1}&amp;s={2}&amp;r=g</span>&quot;,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        md5.ToLowerInvariant(),
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        url.Encode(imageUrl),
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        size);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GravatarUrl(<span style="color: #0000ff">this</span> UrlHelper url, <span style="color: #0000ff">string</span> email)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> url.GravatarUrl(email, 32);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>It uses another custom URL Helper extension method Absolute to generate an absolute URL to a default image (based on an application relative url).</p>
<p>The Absolute extension method is similar to the ActionAbsolute method <a href="http://blog.veggerby.dk/2009/01/13/getting-an-absolute-url-from-aspnet-mvc/">I posted earlier</a>:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 475px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> Absolute(<span style="color: #0000ff">this</span> UrlHelper url, <span style="color: #0000ff">string</span> contentUrl)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> Uri(GetBaseUrl(url), url.Content(contentUrl))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        .AbsoluteUri;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>And it also used the MD5 extension method <a href="http://blog.veggerby.dk/2009/09/29/md5-extension-method/">from yesterdays post</a>.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/BEyECB1L9D2IKwFcFaEqAN71BRQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/BEyECB1L9D2IKwFcFaEqAN71BRQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/BEyECB1L9D2IKwFcFaEqAN71BRQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/BEyECB1L9D2IKwFcFaEqAN71BRQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/e8cbSyC-mO0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/09/asp-net-mvc-gravatar-htmlhelper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/09/asp-net-mvc-gravatar-htmlhelper/</feedburner:origLink></item>
		<item>
		<title>MD5 Extension Method</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/cBMhQWs7xeY/</link>
		<comments>http://blog.veggerby.dk/2009/09/md5-extension-method/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 12:38:00 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[Secure Hash]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/29/md5-extension-method/</guid>
		<description><![CDATA[A nifty little extension method that generated the MD5/SHA-1 hash of a string. These methods are a continuation of my previous post: public static string MD5(this string value) { System.Security.Cryptography.MD5 algorithm = System.Security.Cryptography.MD5.Create(); byte[] data = Encoding.ASCII.GetBytes(value); data = algorithm.ComputeHash(data); string md5 = &#34;&#34;; for (int i = 0; i &#60; data.Length; i++) { md5 [...]]]></description>
			<content:encoded><![CDATA[<p>A nifty little extension method that generated the MD5/SHA-1 hash of a string. These methods are a continuation of <a href="http://blog.veggerby.dk/2008/07/27/formsauthenticationhashpasswordforstoringinconfigfile-continued/">my previous post</a>:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> MD5(<span style="color: #0000ff">this</span> <span style="color: #0000ff">string</span> <span style="color: #0000ff">value</span>)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    System.Security.Cryptography.MD5 algorithm =
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        System.Security.Cryptography.MD5.Create();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">byte</span>[] data = Encoding.ASCII.GetBytes(<span style="color: #0000ff">value</span>);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    data = algorithm.ComputeHash(data);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> md5 = &quot;<span style="color: #8b0000"></span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">for</span> (<span style="color: #0000ff">int</span> i = 0; i &lt; data.Length; i++)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        md5 += data[i].ToString(&quot;<span style="color: #8b0000">x2</span>&quot;).ToLower();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> md5;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>Just substitute <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.md5.aspx">MD5</a> for <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx">SHA1</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha256.aspx">SHA256</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha384.aspx">SHA384</a>, <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.sha512.aspx">SHA512</a> or <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.ripemd160.aspx">RIPEMD160</a> which ever hash algorithm fits your needs.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/O1ML2cluqlZcn5iZA5zEkYt2pOk/0/da"><img src="http://feedads.g.doubleclick.net/~a/O1ML2cluqlZcn5iZA5zEkYt2pOk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/O1ML2cluqlZcn5iZA5zEkYt2pOk/1/da"><img src="http://feedads.g.doubleclick.net/~a/O1ML2cluqlZcn5iZA5zEkYt2pOk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/cBMhQWs7xeY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/09/md5-extension-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/09/md5-extension-method/</feedburner:origLink></item>
		<item>
		<title>Relative Time Description</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/gG8f6bBiXzk/</link>
		<comments>http://blog.veggerby.dk/2009/09/relative-time-description/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 19:46:48 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Dates]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/09/28/relative-time-description/</guid>
		<description><![CDATA[Showing an absolute date on a webpage, e.g. January 22, 2009 13:01, is of course a very normal way to do it, apart from various different date formats, it is easily read and consumed. However if the date is shown in a context where the absolute date is of little importance, but it is more [...]]]></description>
			<content:encoded><![CDATA[<p>Showing an absolute date on a webpage, e.g. January 22, 2009 13:01, is of course a very normal way to do it, apart from various different date formats, it is easily read and consumed. However if the date is shown in a context where the absolute date is of little importance, but it is more important to know if it was a long time ago, just now or maybe just in a couple of minutes, a relative and more descriptive method is better. </p>
<p>For example the date mentioned above might be described as “8 months ago”. Just by giving it a quick glance you get an idea about when this event occurred.</p>
<p>For this here are a couple of extension methods that generate this descriptive text based on a given time:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 100%; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    DateTime now = DateTime.Now;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(now);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, <span style="color: #0000ff">bool</span> usePreAndSuffix)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    DateTime now = DateTime.Now;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(now, usePreAndSuffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, DateTime to)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> from.ToRelativeTime(to, <span style="color: #0000ff">true</span>);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ToRelativeTime(<span style="color: #0000ff">this</span> DateTime from, DateTime to, <span style="color: #0000ff">bool</span> usePreAndSuffix)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> prefix = usePreAndSuffix &amp;&amp; (from &gt; to) ? &quot;<span style="color: #8b0000">in </span>&quot; : <span style="color: #0000ff">string</span>.Empty;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">string</span> suffix = !usePreAndSuffix || (from &gt; to) ? <span style="color: #0000ff">string</span>.Empty : &quot;<span style="color: #8b0000"> ago</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// is more than 1 year?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (from &gt; to)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        DateTime d = from;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        from = to;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        to = d;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">int</span> years = to.Year - from.Year;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> ((to.Month &lt; from.Month) || ((to.Month == from.Month) &amp;&amp; (to.Day &lt; from.Day)))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        years--;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (years &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} years{2}</span>&quot;, prefix, years, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (years == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 year{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 year, is more than 1 month?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">int</span> months = to.Month - from.Month;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (months &lt; 0)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        months += 12;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> ((to.Day &lt; from.Day) || ((to.Day == from.Day) &amp;&amp; (to.TimeOfDay &lt; from.TimeOfDay)))
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        months--;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (months &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} months{2}</span>&quot;, prefix, months, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (months == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 month{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 month, is more than 1 day/week?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    TimeSpan diff = to - from;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Days &gt; 7)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} weeks{2}</span>&quot;, prefix, diff.Days / 7, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Days &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} days{2}</span>&quot;, prefix, diff.Days, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Days == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 day{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 day, is more than 1 hour?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Hours &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} hours{2}</span>&quot;, prefix, diff.Hours, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Hours == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 hour{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 hour, is more than 1 minute?</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Minutes &gt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} minutes{2}</span>&quot;, prefix, diff.Minutes, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Minutes == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 minute{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #008000">// less than 1 minute</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">if</span> (diff.Seconds == 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}1 second{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">else</span> <span style="color: #0000ff">if</span> (diff.Seconds &lt; 1)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    {
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">        <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}less than 1 second{1}</span>&quot;, prefix, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    }
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">    <span style="color: #0000ff">return</span> <span style="color: #0000ff">string</span>.Format(&quot;<span style="color: #8b0000">{0}{1} seconds{2}</span>&quot;, prefix, diff.Seconds, suffix);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}</pre>
</pre>
<p>This can of course be optimized for localization etc.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/3hvytlJjVTVRFtiLkMXQJmoyuVY/0/da"><img src="http://feedads.g.doubleclick.net/~a/3hvytlJjVTVRFtiLkMXQJmoyuVY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/3hvytlJjVTVRFtiLkMXQJmoyuVY/1/da"><img src="http://feedads.g.doubleclick.net/~a/3hvytlJjVTVRFtiLkMXQJmoyuVY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/gG8f6bBiXzk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/09/relative-time-description/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/09/relative-time-description/</feedburner:origLink></item>
		<item>
		<title>EF bloating</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/hMix5XrzfUo/</link>
		<comments>http://blog.veggerby.dk/2009/06/ef-bloating/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 18:43:36 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[WCF]]></category>
		<category><![CDATA[entity framework]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/06/25/ef-bloating/</guid>
		<description><![CDATA[I just read a post from Cibrax aka Pablo M. Cibraro and remembered my old post on the “LINQ to SQL is dead” news. Especially the quote: They made a good work teaching us about how evil Datasets were for interoperability with other platforms, and now they came up with a solution like this, no [...]]]></description>
			<content:encoded><![CDATA[<p>I just read a post from <a href="http://weblogs.asp.net/cibrax/archive/2009/06/25/a-bad-idea-ef-entities-over-wcf.aspx">Cibrax aka Pablo M. Cibraro</a> and remembered <a href="http://blog.veggerby.dk/2008/11/01/adonet-entitity-framework-vs-linq-to-sql/">my old post</a> on the <a href="http://blogs.msdn.com/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx">“LINQ to SQL is dead” news</a>.</p>
<p>Especially the quote:</p>
<blockquote><p>They made a good work teaching us about how evil Datasets were for interoperability with other platforms, and now they came up with a solution like this, no way.</p>
</blockquote>
<p>Priceless…</p>
<p>On the topic from Cibrax’ post, I could not agree more, I am a strong believer in the explicitness of service design and the WCF “opt-in” approach. How else would you know what is on the wire!? Similar to how you would choose ASP.NET MVC over classic ASP.NET WebForms if you want complete control of your HTML. Similar even to WCF vs. ASMX (on a high level).</p>

<p><a href="http://feedads.g.doubleclick.net/~a/SqmSkV1od2glG0fvfWAC0D6jrnU/0/da"><img src="http://feedads.g.doubleclick.net/~a/SqmSkV1od2glG0fvfWAC0D6jrnU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/SqmSkV1od2glG0fvfWAC0D6jrnU/1/da"><img src="http://feedads.g.doubleclick.net/~a/SqmSkV1od2glG0fvfWAC0D6jrnU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/hMix5XrzfUo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/06/ef-bloating/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/06/ef-bloating/</feedburner:origLink></item>
		<item>
		<title>Getting an absolute URL from ASP.NET Webforms</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/VMuItGYD9Y8/</link>
		<comments>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-webforms/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 18:33:50 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/01/15/getting-an-absolute-url-from-aspnet-webforms/</guid>
		<description><![CDATA[Related to the post Getting an absolute URL from ASP.NET MVC here is the corresponding ASP.NET Webforms version (not as extension methods): public static Uri GetBaseUrl(HttpRequest request) { &#160;&#160;&#160; Uri contextUri = new Uri(request.Url, request.RawUrl); &#160;&#160;&#160; UriBuilder realmUri = new UriBuilder(contextUri) { Path = request.ApplicationPath, Query = null, Fragment = null }; &#160;&#160;&#160; return realmUri.Uri; [...]]]></description>
			<content:encoded><![CDATA[<p>Related to the post <a href="http://blog.veggerby.dk/2009/01/13/getting-an-absolute-url-from-aspnet-mvc/">Getting an absolute URL from ASP.NET MVC</a> here is the corresponding ASP.NET Webforms version (not as extension methods):</p>
<div class="vscode"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #2b91af">Uri</span> GetBaseUrl(<span style="color: #2b91af">HttpRequest</span> request)    <br />{    <br />&#160;&#160;&#160; <span style="color: #2b91af">Uri</span> contextUri = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(request.Url, request.RawUrl);    <br />&#160;&#160;&#160; <span style="color: #2b91af">UriBuilder</span> realmUri = <span style="color: #0000ff">new</span> <span style="color: #2b91af">UriBuilder</span>(contextUri) { Path = request.ApplicationPath, Query = <span style="color: #0000ff">null</span>, Fragment = <span style="color: #0000ff">null</span> };    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> realmUri.Uri;    <br />}    </p>
<p><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> GetAbsoluteUrl(<span style="color: #2b91af">HttpRequest</span> request, <span style="color: #0000ff">string</span> relativeUrl)    <br />{    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(GetBaseUrl(request), <span style="color: #2b91af">VirtualPathUtility</span>.ToAbsolute(relativeUrl)).AbsoluteUri;    <br />}</div>

<p><a href="http://feedads.g.doubleclick.net/~a/YyblwoZIRsLiTJH2JBc02vMh8io/0/da"><img src="http://feedads.g.doubleclick.net/~a/YyblwoZIRsLiTJH2JBc02vMh8io/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/YyblwoZIRsLiTJH2JBc02vMh8io/1/da"><img src="http://feedads.g.doubleclick.net/~a/YyblwoZIRsLiTJH2JBc02vMh8io/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/VMuItGYD9Y8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-webforms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-webforms/</feedburner:origLink></item>
		<item>
		<title>Getting an absolute URL from ASP.NET MVC</title>
		<link>http://feedproxy.google.com/~r/veggerby/~3/xG8kLXQVm-w/</link>
		<comments>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-mvc/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 22:40:15 +0000</pubDate>
		<dc:creator>veggerby</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[url]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2009/01/13/getting-an-absolute-url-from-aspnet-mvc/</guid>
		<description><![CDATA[I have been in situations where I need to generate an absolute URL to a specific action in an ASP.NET MVC application. The main problem mostly lies in getting the “domain” part of the URL. The only way to do this is to examine the request URL. I came across a very nice method of [...]]]></description>
			<content:encoded><![CDATA[<p>I have been in situations where I need to generate an <u>absolute</u> URL to a specific action in an <a href="http://asp.net/mvc">ASP.NET MVC</a> application. The main problem mostly lies in getting the “domain” part of the URL. The only way to do this is to examine the request URL. I came across a very nice method of doing this during an encounter with the <a href="http://code.google.com/p/dotnetopenid/">dotnetopenid</a>.&#160; </p>
<div class="vscode"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #2b91af">Uri</span> GetBaseUrl(<span style="color: #0000ff">this</span> <span style="color: #2b91af">UrlHelper</span> url)    <br />{    <br />&#160;&#160;&#160; <span style="color: #2b91af">Uri</span> contextUri = <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(url.RequestContext.HttpContext.Request.Url, url.RequestContext.HttpContext.Request.RawUrl);    <br />&#160;&#160;&#160; <span style="color: #2b91af">UriBuilder</span> realmUri = <span style="color: #0000ff">new</span> <span style="color: #2b91af">UriBuilder</span>(contextUri) { Path = url.RequestContext.HttpContext.Request.ApplicationPath, Query = <span style="color: #0000ff">null</span>, Fragment = <span style="color: #0000ff">null</span> };    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> realmUri.Uri;    <br />}    </p>
<p><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">string</span> ActionAbsolute(<span style="color: #0000ff">this</span> <span style="color: #2b91af">UrlHelper</span> url, <span style="color: #0000ff">string</span> actionName, <span style="color: #0000ff">string</span> controllerName)    <br />{    <br />&#160;&#160;&#160; <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> <span style="color: #2b91af">Uri</span>(GetBaseUrl(url), url.Action(actionName, controllerName)).AbsoluteUri;    <br />}</div>

<p><a href="http://feedads.g.doubleclick.net/~a/p8STZa4_fn43UBwU-9iw2pVxXTI/0/da"><img src="http://feedads.g.doubleclick.net/~a/p8STZa4_fn43UBwU-9iw2pVxXTI/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/p8STZa4_fn43UBwU-9iw2pVxXTI/1/da"><img src="http://feedads.g.doubleclick.net/~a/p8STZa4_fn43UBwU-9iw2pVxXTI/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/veggerby/~4/xG8kLXQVm-w" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://blog.veggerby.dk/2009/01/getting-an-absolute-url-from-aspnet-mvc/</feedburner:origLink></item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: blog.veggerby.dk @ 2010-08-25 09:14:12 -->
