<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5459393636366885547</atom:id><lastBuildDate>Tue, 04 Nov 2025 08:20:00 +0000</lastBuildDate><category>c#</category><category>code</category><category>extension methods</category><category>meta</category><category>framework tip</category><category>snippet</category><category>string extensions</category><category>exception signatures</category><category>humor</category><category>readability</category><title>freakcode</title><description>Special price, just for you</description><link>http://blog.freakcode.com/</link><managingEditor>noreply@blogger.com (Markus Olsson)</managingEditor><generator>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-1980335166293523766</guid><pubDate>Mon, 06 Dec 2010 18:37:00 +0000</pubDate><atom:updated>2010-12-07T18:07:11.735+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">extension methods</category><title>Exception data evolved</title><description>&lt;p&gt;As detailed in my earlier post about &lt;a href=&quot;http://blog.freakcode.com/2009/07/introducing-exception-signatures.html&quot;&gt;exception signatures&lt;/a&gt; I and my colleagues take exceptions from our production servers seriously. In addition to grouping them by signatures (which helps a lot and makes triage much more pleasant) and logging them in our internal bug tracking software we also try to add relevant debug information whenever we throw an exception.&lt;/p&gt;  &lt;p&gt;The BCL team in their infinite wisdom added the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.exception.data.aspx&quot;&gt;Exception.Data property&lt;/a&gt;. This property is simply an &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.collections.idictionary.aspx&quot;&gt;IDictionary&lt;/a&gt; which allows storing key and value pairs of any type. By default this is an empty collection which means you don’t have to worry about it being null.&lt;/p&gt;  &lt;h4&gt;Typical usage&lt;/h4&gt;  &lt;pre class=&quot;brush: csharp&quot;&gt;public void LogonUser(string username, string password, string domain)
{
    try
    {
        DataStore.LogOnUser(username, password, domain);
    }
    catch (Exception exc)
    {
        var ae = new ApplicationException(&amp;quot;Underlying logon failed, see InnerException&amp;quot;, exc);
                
        ae.Data[&amp;quot;username&amp;quot;] = username;
        ae.Data[&amp;quot;domain&amp;quot;] = domain;

        throw ae;
    }
}&lt;/pre&gt;

&lt;p&gt;When the exception reaches our internal &lt;a href=&quot;http://trac.edgewall.org/&quot;&gt;trac site&lt;/a&gt; it might look something like the image below (in our case the data dictionary will actually be added as a comment but you get the point).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS9VwjBKZtRi-OUVhfLKDcDhe8rte36XXTVMUVspB7q7UOJi7aT1U1lkAIv2jM2u7FJ7MWWVhWgXpGeduOjs4p2Pcfl_w2vPF-KooGen2DFfNppVOjSqU8fVjT456yNBs8uXgysQYRfoiN/s1600-h/example-data%5B2%5D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;example-data&quot; border=&quot;0&quot; alt=&quot;example-data&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2bmUTVl0h-uSQSB7Z4nZXYvdVJDyaadCS-Tosp3MZavf8gZTkthdrj4460ZKMC-rnI-x69lmbgVs5di0M8T2dYAWGC0k_RqvuyvBRuRooRF9M_c4cAuFraHSVC2RiUCT15EKpfccz7iqx/?imgmax=800&quot; width=&quot;244&quot; height=&quot;172&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This has proven to be is incredibly useful for debugging purposes but it is a bit tedious to actually write the code. Storing the exception in a variable just to get access to the data property just didn’t feel right to me and writing the same boilerplate .Data[“xyz”] = xyz was just boring.&lt;/p&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h4&gt;Step 1 – The AddData extension method.&lt;/h4&gt;

&lt;p&gt;I started off by creating an extension method for System.Exception called AddData. AddData looks a bit like this (very simplified, see the end of the post for the real deal)&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;public static Exception AddData(this Exception exception, string key, object value)
{
    exception.Data.Add(key, value);&lt;br /&gt;    // whohoo, chaining!
    return exception;
}&lt;/pre&gt;

&lt;p&gt;This allowed me to save a few keystrokes over the first method and I would end up with something like this instead&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;catch(...) {
    throw new ApplicationException(&amp;quot;Underlying logon failed, see InnerException&amp;quot;, exc)
        .AddData(&amp;quot;username&amp;quot;, username)
        .AddData(&amp;quot;domain&amp;quot;, domain);
}&lt;/pre&gt;

&lt;p&gt;It might not look like much but it sure helps when you want to add debug data to an already existing exception, it saves you from having to store the reference and so on but it still doesn’t solve the problem with having to write the argument names twice. This isn’t only a nuisance when writing the code; it’s very easy for the key and value to get out of sync if you’re doing refactoring since refactoring tools will only change the variable name, not the key.&lt;/p&gt;

&lt;p&gt;My ideal solution would be something like this&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;catch(...) {
    throw new ApplicationException(&amp;quot;Underlying logon failed, see InnerException&amp;quot;, exc)
        .AddData(username)
        .AddData(domain);
}&lt;/pre&gt;

&lt;p&gt;And have the AddData method automatically infer the proper key name but since that’s not possible I had to find another way.&lt;/p&gt;

&lt;h4&gt;Step 2 – Taking a cue from ASP.NET MVC&lt;/h4&gt;

&lt;p&gt;We continued using the AddData extension method above for a couple of weeks before it dawned on me that I could use &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/bb397696.aspx&quot;&gt;anonymous types&lt;/a&gt; to skip the parameter name duplication. Anonymous types have the great ability of being able to “infer” property names when initialized.&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;var x = new { username = username, password = password }
// Is the same as
var x = new { username, password }&lt;/pre&gt;

&lt;p&gt;With this in mind I wrote an AddData extension method which accepts a single object and then uses reflection to iterate over all properties and adds their property names and values into the exception data dictionary.&amp;#160; This allowed me to rewrite my code yet again.&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;catch(...) {
    throw new ApplicationException(&amp;quot;Underlying data store logon failed, see InnerException&amp;quot;, exc)
        .AddData(new { username, password });
}&lt;/pre&gt;

&lt;p&gt;Neat, isn’t it? This is the exact same technique that ASP.NET MVC uses for route-declarations, attributes in html helpers and more.&lt;/p&gt;

&lt;h4&gt;&lt;/h4&gt;

&lt;h5&gt;Reflection? Isn’t that horribly slow&lt;/h5&gt;

&lt;p&gt;Not like in the olden days. It comes with a cost but you shouldn’t be too worried since you’re probably not throwing exception often enough for it to matter anyway (and if you are, then you have bigger problems).&lt;/p&gt;

&lt;h4&gt;Teh codez&lt;/h4&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;using System;
using System.ComponentModel;
using System.Diagnostics;

namespace freakcode.Extensions
{
    /// &lt;summary&gt;
    /// Extension methods related to instances of &lt;c&gt;System.Exception&lt;/c&gt; and inherited objects.
    /// &lt;/summary&gt;
    public static class ExceptionExtensions
    {
        /// &lt;summary&gt;
        /// Adds the supplied debug data to the exceptions data dictionary and returns
        /// the exception allowing chaining.
        /// &lt;/summary&gt;
        /// &lt;typeparam name=&quot;T&quot;&gt;The exception type, you should not need to specify this explicitly&lt;/typeparam&gt;
        /// &lt;param name=&quot;exception&quot; /&gt;The exception.&lt;/param&gt;
        /// &lt;param name=&quot;key&quot; /&gt;The key of the debug value to be inserted into the exceptions data dictionary.&lt;/param&gt;
        /// &lt;param name=&quot;value&quot; /&gt;The value to be inserted into the exceptions data dictionary.&lt;/param&gt;
        /// &lt;exception cref=&quot;System.ArgumentNullException&quot;&gt;key is null&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.ArgumentException&quot;&gt;An element with the same key already exists in the Data dictionary&lt;/exception&gt;
        public static T AddData&amp;lt;T&amp;gt;(this T exception, string key, object value) where T : Exception
        {
            if (exception == null)
                throw new ArgumentNullException(&amp;quot;exception&amp;quot;);

            if (key == null)
                throw new ArgumentNullException(&amp;quot;key&amp;quot;);

            /* Key or value is not serializable (or key is null). The default internal structure which
             * implements the IDictionary is going to throw an exception in Add() so instead of 
             * throwing another exception while preparing to throw the first one we silently ignore the
             * error. Unless we&#39;re building in debug mode that is, then we&#39;ll fail. */
            if (value != null &amp;amp;&amp;amp; !value.GetType().IsSerializable)
            {
                Debug.Fail(&amp;quot;Attempt to add non-serializable value to exception data&amp;quot;);
            }
            else
            {
                exception.Data.Add(key, value);
            }

            return exception;
        }

        /// &lt;summary&gt;
        /// Adds the each property name and value from the supplied object to the exceptions data dictionary and returns
        /// the exception allowing chaining.
        /// &lt;/summary&gt;
        /// &lt;typeparam name=&quot;T&quot;&gt;The exception type, you should not need to specify this explicitly&lt;/typeparam&gt;
        /// &lt;param name=&quot;exception&quot; /&gt;The exception.&lt;/param&gt;
        /// &lt;param name=&quot;values&quot; /&gt;An object from where properties will be read and added to the exception debug data collection.&lt;/param&gt;
        /// &lt;exception cref=&quot;System.ArgumentNullException&quot;&gt;key is null&lt;/exception&gt;
        /// &lt;exception cref=&quot;System.ArgumentException&quot;&gt;An element with the same key already exists in the Data dictionary&lt;/exception&gt;
        public static T AddData&amp;lt;T&amp;gt;(this T exception, object values) where T : Exception
        {
            if (values == null)
            {
                // Some really nasty things can happen if you start throwing exceptions in the middle
                // of throwing exceptions so unless we&#39;re in debug more we&#39;ll just silently ignore it.
                Debug.Fail(&amp;quot;Argument &#39;values&#39; was null!&amp;quot;);
            }
            else
            {
                foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(values))
                    exception.AddData(descriptor.Name, descriptor.GetValue(values));
            }
            
            return exception;
        }
    }
}
&lt;/pre&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2010%2f12%2fexception-data-evolved.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2010%2f12%2fexception-data-evolved.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.freakcode.com/2010/12/exception-data-evolved.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2bmUTVl0h-uSQSB7Z4nZXYvdVJDyaadCS-Tosp3MZavf8gZTkthdrj4460ZKMC-rnI-x69lmbgVs5di0M8T2dYAWGC0k_RqvuyvBRuRooRF9M_c4cAuFraHSVC2RiUCT15EKpfccz7iqx/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-9022688380819679858</guid><pubDate>Sun, 05 Dec 2010 22:16:00 +0000</pubDate><atom:updated>2012-11-26T11:07:52.592+01:00</atom:updated><title>Calculating week numbers in Google Spreadsheets Revisited</title><description>&lt;p&gt;In my previous entry &lt;a href=&quot;http://blog.freakcode.com/2009/12/calculating-week-numbers-in-google.html&quot;&gt;Calculating week numbers in Google Spreadsheets&lt;/a&gt; I explored and presented a way of  retrieving the week number of a given date. A couple of weeks ago a guy named &lt;a href=&quot;http://fredd-e.narfum.org/&quot;&gt;Frederik Claes&lt;/a&gt; send me the best bug report from a non-programmer that I&#39;ve ever received. He pointed out an error in an edge-case date that wasn&#39;t included in the &lt;a href=&quot;https://spreadsheets.google.com/ccc?key=0AueEb10tSoSUdHBMTFlMbnJwTlAwX0JRTEhSd2hxQ3c&amp;hl=en&quot;&gt;test suite&lt;/a&gt;. After having looked at the problem and read up on the problem I found two errors. &lt;/p&gt;&lt;h2&gt;First: the algorithm&lt;/h2&gt;&lt;p&gt;The algorithm I used didn&#39;t comply with the specifications and for some dates it would return an invalid week number. While it had the advantage of being easy to read and verbose it was obvious that it would have to be replaced. An improved algorithm is currently being discussed on the &lt;a href=&quot;http://en.wikipedia.org/wiki/Talk:ISO_week_date#Algorithms&quot;&gt;talk-page of the wikipedia article&lt;/a&gt; and after a couple of verifications I ended up reimplementing my script using it instead. &lt;/p&gt;&lt;h2&gt;Second: Time zone conversion&lt;/h2&gt;&lt;p&gt;This is a classic example of a Works On My Machine problem. It turns out (and for good reasons to) that Google Apps Scripts run in a (potentially) different timezone from the actual spreadsheet. This is a major problem when dealing with dates since what looks like 2009-01-01 in the spreadsheet could very well have been converted to 2008-12-31 when it reaches the script. While I haven&#39;t had the time to fully investigate the possible workarounds I think I&#39;ve found an acceptable way of transforming the date within the script to it&#39;s proper timezone. &lt;/p&gt;&lt;h2&gt;The script&lt;/h2&gt;&lt;p&gt;I&#39;ve sent the script to Google for review so hopefully it&#39;ll be available through the Apps Script gallery within a couple of days. Until then you can copy the script from this blog and insert it to your sheets. &lt;/p&gt;&lt;pre class=&quot;brush: js&quot;&gt;// by Markus Olsson (http://www.freakcode.com). 
// See http://www.freakcode.com/projects/google-spreadsheet-week-numbers
// The script is licensed under the MIT License. Basically you&#39;re free to do whatever you want with it. Attribution not necessary but appreciated.

// Update 2011-05-02:
//   Now returns current week when no arguments are given.
//   Adding attempt to automatically convert non-date objects, see code
//   Using 2 space indentation since that seems to be the proper indentation level for apps scripts
//
// Update 2010-12-05: 
//   Using the algorithm suggested by DR J R Stockton on http://en.wikipedia.org/wiki/Talk:ISO_week_date#Algorithms and
//   some of the JS implementation provided by DR Stockton on http://www.merlyn.demon.co.uk/weekcalc.htm#JS.
//
//   This fixes the erroneous week numbers reported by Frederik Claes.
//
//   Also fixed proper conversion between spreadsheet and script time zones since scripts now have explicit 
//   time zones (they didn&#39;t when I first started this script).
//
// This method is provided as an easy to use extension to the function namespace of Google Spreadsheet. 
// Since it was written a couple of people have reported that it is possible to get the week number from a
// date cell without resorting to scripts formula:
//    =VALUE(MID(TEXT( A1; &quot;yyw&quot;) ; 3 ;5)) 
// Use whichever method you prefer, I think =WeekNumber(A1) is more readable but that could be because of the
// work I&#39;ve put in into this script ;)
//
function WeekNumber(date, inIsoStringFormat)
{
  // Allows this method to be called without arguments to return the
  // current week. Shorter version of =WEEKNUMBER(TODAY())
  if(arguments.length &lt; 1)
    date = new Date();

  // For a short while when I first started writing this script date cells 
  // wasn&#39;t given as pure js date objects so you had to convert them first. This 
  // hasn&#39;t been an issue for me for ages but some comments on my blog suggests 
  // that explicitly convertering into a Date instance has helped them. Maybe they&#39;re
  // using old spreadsheets, maybe not. But I can&#39;t foresee that adding this extra 
  // safeguard should cause any major problems (famous last words).
  if(Object.prototype.toString.call(date) !== &#39;[object Date]&#39;)
    date = new Date(date);

  var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var spreadsheetTimeZone = activeSpreadsheet.getSpreadsheetTimeZone();  

  // Google apps will automatically convert the spreadsheet date into the timezone
  // under which the script is running, this will revert it to the spreadsheet date and
  // at the same time truncate hours, minutes and seconds.
  date = new Date( Utilities.formatDate(date, spreadsheetTimeZone, &quot;MMM d, yyyy&quot;) );
    
  // Get the week day where 1 = Monday and 7 = Sunday
  var dayOfWeek = ((date.getDay() + 6) % 7) + 1;

  // Locate the nearest thursday
  date.setDate(date.getDate() + (4 - dayOfWeek));
  
  var jan1 = new Date(date.getFullYear(), 0, 1);

  // Calculate the number of days in between the nearest thursday and januari first of 
  // the same year as the nearest thursday.
  var deltaDays = Math.floor( (date.getTime() - jan1.getTime()) / (86400 * 1000) )

  var weekNumber = 1 + Math.floor(deltaDays / 7);
  
  if(inIsoStringFormat)
    return jan1.getFullYear() + &quot;-W&quot; + (weekNumber &lt; 10 ? &quot;0&quot; + weekNumber : weekNumber);
        
  return weekNumber;
}
&lt;/pre&gt;
&lt;div class=&quot;license&quot;&gt;&lt;a href=&quot;http://blog.freakcode.com/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/div&gt;</description><link>http://blog.freakcode.com/2010/12/calculating-week-numbers-in-google.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-6176224198362984799</guid><pubDate>Wed, 20 Jan 2010 10:11:00 +0000</pubDate><atom:updated>2010-12-05T23:33:14.257+01:00</atom:updated><title>Calculating week numbers in Google Spreadsheets</title><description>&lt;p style=&quot;color: red&quot;&gt;&lt;strong&gt;I&#39;ve fixed a couple of bugs and made some changes to the script. The code on this page is obsolete and only preserved for historical purposes. Please see my &lt;a href=&quot;http://blog.freakcode.com/2010/12/calculating-week-numbers-in-google.html&quot;&gt;updated blog post&lt;/a&gt; for the updated code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I use an excellent little app called &lt;a href=&quot;http://www.mobileapps.de/timetracker/&quot;&gt;TimeTracker&lt;/a&gt; to keep track of how much time I spend at work. When I&#39;ve collected too much overtime I try to compensate by taking a day off (unfortunately for me I haven’t exactly been great at balancing this in the past).&lt;/p&gt;  &lt;p&gt;TimeTracker has an export feature that mails me a CSV file with all the data I need to produce a report suitable for showing to my boss should he ever complain about me not working enough. &lt;/p&gt;  &lt;p&gt;I use the Google Spreadsheets to input and calculate how much I&#39;ve been working. The problem is that I wanted to sum up how much I work in any given week but I couldn&#39;t find a function that, given a date, returns the &lt;a href=&quot;http://en.wikipedia.org/wiki/ISO_week_date&quot;&gt;ISO 8601 week number&lt;/a&gt;.&lt;/p&gt;  &lt;h4&gt;Writing it myself: The bad way&lt;/h4&gt;  &lt;p&gt;My first attempt at writing it myself was both messy and naive &lt;/p&gt;  &lt;pre&gt;=ROUNDDOWN((INT(B2-DATE(YEAR(B2);1;1))+(WEEKDAY(DATE(YEAR(B2);1;1);3)))/7)+1)&lt;/pre&gt;

&lt;p&gt;While this function has worked for me during the few months that I&#39;ve been using it it won&#39;t work properly across new years eve, it doesn&#39;t take leap years into account and I&#39;m sure there&#39;s a bunch of other things that&#39;s wrong with it. &lt;/p&gt;

&lt;p&gt;But that was before I found out that it is possible to &lt;strong&gt;write Google spreadsheet functions in JavaScript!&lt;/strong&gt; It&#39;s called &lt;a href=&quot;http://www.google.com/google-d-s/scripts/articles.html&quot;&gt;Google Apps Script&lt;/a&gt; and it&#39;s JavaScript which you can write that gets executed server-side in the Google cloud. &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div style=&quot;text-decoration: line-through&quot;&gt;&lt;em&gt;Please note that unfortunately this only seems to be available to &lt;/em&gt;&lt;a href=&quot;http://www.google.com/apps/intl/en/business/features.html&quot;&gt;&lt;em&gt;Google Apps users&lt;/em&gt;&lt;/a&gt;&lt;em&gt; (i.e. not for standard Google accounts) at the moment. There seems to be some kind of &lt;/em&gt;&lt;a href=&quot;http://www.google.com/support/forum/p/Google+Docs/thread?tid=4041a308dc2c2c3f&amp;amp;hl=en&quot;&gt;&lt;em&gt;a petition for opening up the scripts feature to the public&lt;/em&gt;&lt;/a&gt;&lt;em&gt; that you might want to check out.&lt;/em&gt;&lt;/div&gt;
- As of 2010-03-11 Apps script is available to all docs users! 

&lt;p&gt;&lt;/p&gt;

&lt;h4&gt;Writing it myself: The right way&lt;/h4&gt;

&lt;p&gt;The intertubes are littered with lots and lots of examples of how to calculate week numbers in JavaScript but very few of the nifty ones (the one-liners) seem to properly handle the 2010 transition correctly (2010-01-03 is week 53 and 2010-01-04 is week 1) so I decided to more or less translate the pseudo code at &lt;a href=&quot;http://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date&quot;&gt;Wikipedia&lt;/a&gt; to JavaScript and ultimately Google Apps Script. &lt;/p&gt;

&lt;p&gt;The solution is quite verbose and there&#39;s a couple of tricks that I haven&#39;t bothered implementing. But it works.&lt;/p&gt;

&lt;p style=&quot;color: red&quot;&gt;&lt;strong&gt;This code is obsolete and will fail for certain dates. It is only preserved for historical purposes. Please see my &lt;a href=&quot;http://blog.freakcode.com/2010/12/calculating-week-numbers-in-google.html&quot;&gt;updated blog post&lt;/a&gt; for the updated code&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;brush: js&quot;&gt;// Built from pseudo code at:
// http://en.wikipedia.org/wiki/ISO_week_date#Calculating_the_week_number_of_a_given_date
// by Markus Olsson (http://www.freakcode.com). See http://blog.freakcode.com/2009/12/calculating-week-numbers-in-google.html.
function WeekNumber(inDate)
{
    function IsLeapYear(year)
    {
        return (year % 4 == 0) &amp;amp;&amp;amp; ((year % 100 != 0) || (year % 400 == 0))
    }

    function OrdinalDays(inDate)
    {
        var ordinalDatesPerMonth = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
        var ordinalDatesPerMonthInLeapYear = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];

        var ordinals = ordinalDatesPerMonth;

        if(IsLeapYear(inDate.getFullYear()))
            ordinals = ordinalDatesPerMonthInLeapYear;
  
        return ordinals[inDate.getMonth()] + inDate.getDate();
    }
      
    // Get the week day where 1 = Monday and 7 = Sunday
    var weekDay = ((inDate.getDay() + 6) % 7) + 1;
    var ordinal = OrdinalDays(inDate);

    var weekNum = Math.floor(((ordinal - weekDay) + 10) / 7);

    // If the week number equals 0, it means that the 
    // given date belongs to the preceding (week-based) year.
    if(weekNum == 0)
        return 53;

    // If 53 is obtained, we must check that the date is not actually 
    // in week 1 of the following year.
    if(weekNum == 53 &amp;amp;&amp;amp; weekDay &amp;lt; 4)
        return 1;

    return weekNum;
}&lt;/pre&gt;

&lt;p&gt;I&#39;ve made a small &lt;a href=&quot;https://spreadsheets.google.com/ccc?key=0AueEb10tSoSUdHBMTFlMbnJwTlAwX0JRTEhSd2hxQ3c&amp;amp;hl=en&quot;&gt;test suite available as a spreadsheet&lt;/a&gt;. &lt;/p&gt;

&lt;h4&gt;Trick&lt;/h4&gt;

&lt;p&gt;If you&#39;ve got lots and lots of cells performing week number calculations you can select the cells, hit CTRL+C (or copy through the menu) then only paste the value (Edit menu -&amp;gt; Paste values only). There&#39;s really no need to calculate it over and over again since the likelihood of a major change to the ISO spec is pretty low ;) &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 2010-01-20 (2010-W3):&lt;/strong&gt; Google made some &lt;a href=&quot;http://googleappsscript.blogspot.com/2010/01/new-apps-script-release.html&quot;&gt;changes to Google Apps Scripts&lt;/a&gt; that broke the script. The sample above and the test suite has been updated. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 2010-03-11 (2010-W10):&lt;/strong&gt; Google released the &lt;a href=&quot;http://googledocs.blogspot.com/2010/03/apps-script-gallery-for-google.html&quot;&gt;Google Apps Scripts gallery&lt;/a&gt; today and simultaneously enabled apps script for regular docs users. The apps gallery makes it possible to &lt;a href=&quot;http://googleappsdeveloper.blogspot.com/2010/03/publish-your-scripts-to-apps-script.html&quot;&gt;publish apps script&lt;/a&gt;! Great work by the Apps script team! I&#39;ve submitted the week number script to the gallery and I&#39;m currently waiting for them to approve it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update 2010-03-16 (2010-W11):&lt;/strong&gt; Got an approval mail from Google, the script is now available in the script gallery!&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisE6gXaIUicsYE3WTyK7m6bLTLTuVEUPDU_nlFJ1d0_WmdiC1Kk117wFiHsJLuOGaPVlVJA7JI-gYvaGSbu-BuycTpp8kkUDW124_tgXc4mII4eCRkq-psV12xBLG_9FJDFJuz5v0WEYJ3/s1600-h/weeknumbers-in-google-apps-script-gallery%5B2%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;weeknumbers-in-google-apps-script-gallery&quot; border=&quot;0&quot; alt=&quot;weeknumbers-in-google-apps-script-gallery&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3LPJRDSSZPt4yk2PigZ7b93OyR_-g7tXfkmzxJ0Q5cHqMVDbtc3C7yQLnEoFXdmYc83YFiD6OM7AoHSnAprhyf7YHupWdeOT_5DU5Gm9gFQt_nh59EKUFKSdRLAwjtKGWIw630h0j5sFm/?imgmax=800&quot; width=&quot;244&quot; height=&quot;213&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.freakcode.com/2009/12/calculating-week-numbers-in-google.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg3LPJRDSSZPt4yk2PigZ7b93OyR_-g7tXfkmzxJ0Q5cHqMVDbtc3C7yQLnEoFXdmYc83YFiD6OM7AoHSnAprhyf7YHupWdeOT_5DU5Gm9gFQt_nh59EKUFKSdRLAwjtKGWIw630h0j5sFm/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-266469713060250586</guid><pubDate>Fri, 08 Jan 2010 15:18:00 +0000</pubDate><atom:updated>2010-01-08T16:19:19.798+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><title>Pretty automatically updating lighttpd server status or “mod_status on steroids”</title><description>&lt;p&gt;At work we use the excellent &lt;a href=&quot;http://www.lighttpd.net/&quot;&gt;lighttpd&lt;/a&gt; (or lighty) web server as a frontend reverse proxy that performs &lt;a href=&quot;http://www.f5.com/glossary/ssl-offloading.html&quot;&gt;SSL offloading&lt;/a&gt;, and&amp;#160; some other neat tricks before our visitors reach our backend servers. It’s been working like a charm.&lt;/p&gt;  &lt;p&gt;We’ve been using &lt;a href=&quot;http://redmine.lighttpd.net/wiki/1/Docs:ModStatus&quot;&gt;mod_status&lt;/a&gt; to keep track of how much traffic goes through our frontend server. mod_status is one of those little apps that gets the job done but not so much more.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivxO7B2qCSrPkCBvZIk0EAHMjy53Ajj2bvZAYJM1mnatp3erXqS5iP5f07mQT0h9laxfCEF1uJbpRVvMz_Qx7mbUw1LTdnCJPofDs_3LlmA-OlW6uR2hh3VsTWqNzbI4-XgxKCtZUWZlP-/s1600-h/server-status%5B2%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;server-status&quot; border=&quot;0&quot; alt=&quot;server-status&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoH3iroyaTGknK_IOsrmAATMM1tiJr1VEV8qrlaG_7QvNQvH6qhZ4wviShuabIIUFGk80tYcif8zbwYYsY066txRasMdHO9errtYZB7KgyH1S9gNOJgaetOm0sNVDFd7RUDn8CJGw6Rgx4/?imgmax=800&quot; width=&quot;200&quot; height=&quot;244&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It contains all the relevant information but I wanted to display this data on a separate monitor to as a way to keep track of how much traffic we where getting in real time. &lt;/p&gt;  &lt;p&gt;Since it’s a static html page there wasn’t much interactivity there. So I whipped out my vim-editor and wrote a little helper page that dynamically polls data from the server-status page and displays it in a little more full-screen friendly way. You can see the result below (click on it to enlarge). It will automatically refresh the data once every 5 seconds.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis0vieuhrdycsqOHxalvb2Ky7n51VfqcJUfVwEh5gj1i4_TlFUdzNYO6v0S2vOgSSEKWJLZ-5XvI062laX8DRaiOvBwmE2xpOBlUaQIU_5-fT3cumP3tc6Vckx7KnpfSn6-ifF2WVW0ery/s1600-h/server-status-pretty%5B2%5D.png&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;server-status-pretty&quot; border=&quot;0&quot; alt=&quot;server-status-pretty&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqTmZK7ay73604-bmdOvWkPQDK2nTexF7Ss1rz7JnS-7iJtZ8_QZpw6HlU-YB2z8w1X6PQ__iSFNwiSnr_Ws9l4KgLVERKkREs3BzhTCKQiJx6BruPEx_ogl36eMkmxyQAuwGrG_pwewuD/?imgmax=800&quot; width=&quot;244&quot; height=&quot;172&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Go ahead and &lt;a href=&quot;http://www.freakcode.com/projects/pretty-lighty-status-page/pretty-status.htm?attredirects=0&amp;amp;d=1&quot;&gt;download the source&lt;/a&gt;. It’s a single html file and all you have to do is to configure your lighty server so that the server status is enabled for a directory to which you’ve got write access to. Ours looks like this:&lt;/p&gt;  &lt;pre class=&quot;brush:plain; gutter: false&quot;&gt;$SERVER[&amp;quot;socket&amp;quot;] == &amp;quot;192.168.30.1:80&amp;quot; {
    status.status-url = &amp;quot;/server-status&amp;quot;
    server.document-root = &amp;quot;/var/www/status&amp;quot;
    mimetype.assign = ( &amp;quot;.html&amp;quot; =&amp;gt; &amp;quot;text/html&amp;quot; )
    index-file.names = ( &amp;quot;pretty-status.html&amp;quot; )
}&lt;/pre&gt;

&lt;p&gt;Then you simply put the file in that page and it should just magically work. &lt;strong&gt;Note that the file loads the Google hosted jQuery library &lt;/strong&gt;so if you don’t have access to the internet (on the machine your viewing from) you’ll have to download the jQuery script and place it along side the page.&lt;/p&gt;

&lt;p&gt;Things on the todo list include pretty error messages when the data can’t be fetched and perhaps a nice little demo-mode.&lt;/p&gt;

&lt;p&gt;[&lt;a href=&quot;http://www.freakcode.com/projects/pretty-lighty-status-page/pretty-status.htm?attredirects=0&amp;amp;d=1&quot;&gt;Download the source&lt;/a&gt;], [“&lt;a href=&quot;http://www.freakcode.com/projects/pretty-lighty-status-page&quot;&gt;Project page at freakcode.com&lt;/a&gt;”]&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;  </description><link>http://blog.freakcode.com/2010/01/pretty-automatically-updating-lighttpd.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoH3iroyaTGknK_IOsrmAATMM1tiJr1VEV8qrlaG_7QvNQvH6qhZ4wviShuabIIUFGk80tYcif8zbwYYsY066txRasMdHO9errtYZB7KgyH1S9gNOJgaetOm0sNVDFd7RUDn8CJGw6Rgx4/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-5266756720906962652</guid><pubDate>Mon, 23 Nov 2009 15:46:00 +0000</pubDate><atom:updated>2009-11-24T11:02:06.951+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><title>Google Maps version 3 intellisense</title><description>&lt;p&gt;Intellisense is one of those killer-features of Visual Studio. I love that I can just drop in an assembly in VS and start poking around in an editor to get a feel of the API. If the API i properly documented and layed out in a .netty way I can immediately start working with it. &lt;/p&gt;&lt;p&gt;The flipside of intellisense is that once you get used to it you feel severely limited when you encounter a project without intellisense. That&#39;s what happened to me today. &lt;/p&gt;&lt;p&gt;I was integrating the excellent Google Maps library into one of our websites and decided that I should use the latest and greatest release - &lt;a href=&quot;http://code.google.com/intl/en-US/apis/maps/documentation/v3/&quot;&gt;Google Maps v3&lt;/a&gt;. I fired up VS and started hacking away in a .js file until i got flashbacks from back in the days when I developed PHP. I was toggling between writing code in my IDE and reading the api documentation in my browser. It was horrifying! &lt;/p&gt;&lt;h4&gt;-vsdoc to the rescue&lt;/h4&gt;&lt;p&gt;At some point I realized that since I can get &lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2008/11/21/jquery-intellisense-in-vs-2008.aspx&quot;&gt;intellisense for jQuery&lt;/a&gt; I should be able to get it for Google Maps as well so I started googling and found &lt;a href=&quot;http://gmapjs.codeplex.com/&quot;&gt;this single commit project&lt;/a&gt; at codeplex that did offer an intellisense file for Google Maps v2 but not for v3. &lt;/p&gt;&lt;p&gt;That&#39;s when I started looking at writing my own intellisense file. I tried to validate the &lt;a href=&quot;http://code.google.com/apis/maps/documentation/v3/reference.html&quot;&gt;Google API reference&lt;/a&gt; in the &lt;a href=&quot;http://validator.w3.org/&quot;&gt;W3 Validator&lt;/a&gt; only to find out that the king of all web doesn&#39;t always produce the best markup. &lt;/p&gt;&lt;p&gt;Not to fear; I&#39;ve written a couple of screen scraping utilities before and I know that there&#39;s one project that makes dealing with badly formatted html a breeze: &lt;a href=&quot;http://www.codeplex.com/htmlagilitypack&quot;&gt;Html Agility Pack&lt;/a&gt;. The agility pack parses almost any amount of bad markup and gives you a nice little XPath interface for poking around inside the DOM. &lt;/p&gt;&lt;h4&gt;The result&lt;/h4&gt;&lt;p&gt;After some hackish (screen scrapers are always messy) code I was able to produce a basic intellisense file that covers most of the Google Maps API. &lt;/p&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxoXY_2y7r_2pH5PDyMlKACawy7QFU7EE3LHzYoo0mjTtszt-RfzC4HntrIbp6dOQ8yiFe3OnPT-63uJDIV8K7ncMbQ2UOZTwCJJPTgUZud6wvj3eiOu2n-H7spS95m0nfvkFb2vub-5fb/s1600/google-maps-intellisense.png&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;width: 400px; height: 84px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxoXY_2y7r_2pH5PDyMlKACawy7QFU7EE3LHzYoo0mjTtszt-RfzC4HntrIbp6dOQ8yiFe3OnPT-63uJDIV8K7ncMbQ2UOZTwCJJPTgUZud6wvj3eiOu2n-H7spS95m0nfvkFb2vub-5fb/s400/google-maps-intellisense.png&quot; border=&quot;0&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5407332298613697442&quot; /&gt;&lt;/a&gt;  &lt;h4&gt;The files&lt;/h4&gt;&lt;p&gt;The js intellisense file and usage instructions can be found over at &lt;a href=&quot;http://www.freakcode.com/projects/google-maps-v3-vsdoc&quot;&gt;http://www.freakcode.com/projects/google-maps-v3-vsdoc&lt;/a&gt;. &lt;/p&gt;&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2009%2f11%2fgoogle-maps-version-3-intellisense.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2009%2f11%2fgoogle-maps-version-3-intellisense.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;  &lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;http://www.blogger.com/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.freakcode.com/2009/11/google-maps-version-3-intellisense.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxoXY_2y7r_2pH5PDyMlKACawy7QFU7EE3LHzYoo0mjTtszt-RfzC4HntrIbp6dOQ8yiFe3OnPT-63uJDIV8K7ncMbQ2UOZTwCJJPTgUZud6wvj3eiOu2n-H7spS95m0nfvkFb2vub-5fb/s72-c/google-maps-intellisense.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-5726101226844694747</guid><pubDate>Sat, 25 Jul 2009 17:33:00 +0000</pubDate><atom:updated>2009-07-27T11:54:13.409+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">exception signatures</category><title>Introducing exception signatures</title><description>&lt;p&gt;At work we develop, maintain and host a web solution which consists of a fair amount of assemblies and spans across several websites. Although we might like to think that we develop perfect code that certainly isn&#39;t always the case. And as with all non-&lt;a href=&quot;http://en.wikipedia.org/wiki/Daniel_J._Bernstein&quot;&gt;djb&lt;/a&gt; applications ours sometimes generates a few exceptions. &lt;/p&gt;  &lt;p&gt;&lt;i&gt;&lt;span style=&quot;font-size: x-small&quot; class=&quot;Apple-style-span&quot;&gt;Now please don&#39;t think of us as bad people, exceptions are an unfortunate part of nature and not all exceptions are the result of our bad programming, quite often we get exceptions from external libraries, from asp.net (viewstate exceptions, forbidden input exceptions and so on).&lt;/span&gt;&lt;/i&gt; &lt;/p&gt;  &lt;h4&gt;Keeping track of exceptions&lt;/h4&gt;  &lt;p&gt;Quite early on in our development process we decided that we needed a way of reacting to these exceptions as they happened. Our solution was to implement global exception handlers which sent an email to us whenever an unhandled exception occurred. &lt;/p&gt;  &lt;p&gt;This worked great and in our early days it was more than enough. We could immediately react to an exception and we could often deploy a fix rapidly. &lt;/p&gt;  &lt;p&gt;&lt;span style=&quot;font-size: x-small&quot; class=&quot;Apple-style-span&quot;&gt;&lt;i&gt;If you don&#39;t keep track of your exception at all you&#39;re probably in trouble. See &lt;/i&gt;&lt;/span&gt;&lt;a href=&quot;http://www.codinghorror.com/blog/archives/001239.html&quot;&gt;&lt;span style=&quot;font-size: x-small&quot; class=&quot;Apple-style-span&quot;&gt;&lt;i&gt;this post&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;font-size: x-small&quot; class=&quot;Apple-style-span&quot;&gt;&lt;i&gt; by Jeff Atwood for a better explanation of why than I could ever come up with.&lt;/i&gt;&lt;/span&gt; &lt;/p&gt;  &lt;h4&gt;Keeping track of large amounts of exceptions&lt;/h4&gt;  &lt;p&gt;When our sites had been live for a while and started to get some serious use we noticed that it was getting really hard to keep track of all incoming exception mails. From looking at the stack trace we had no idea if an exception had been resolved, if someone was working on it, it&#39;s priority and so on. Troubled by the need to keep a bunch of stack traces in (my) memory I started thinking about ways of solving the problem. &lt;/p&gt;  &lt;p&gt;My idea was to convert the exceptions into issue tickets. We use &lt;a href=&quot;http://trac.edgewall.org/&quot;&gt;Trac&lt;/a&gt; at work so I started looking at simply redirecting all of our exception email there. Getting the exception mails converted to tickets wasn&#39;t really a problem but it didn&#39;t help at all with organization since every exception spawned a new ticket and we still had to manually merge the duplicates. &lt;/p&gt;  &lt;h4&gt;Enter Exception Signatures&lt;/h4&gt;  &lt;p&gt;In order to enable organization I started looking at generating a fingerprint for every exception. Some sort of string generated by looking at the stack traces of the exception, its inner exceptions and meta information of each exception. I wanted a solution which could be intelligent enough to differentiate between two exceptions thrown from the same place but for different reasons (i.e., the algorithm should look at the entire exception chain instead of only the base exception target site). &lt;/p&gt;  &lt;h4&gt;Handling dynamic data in exception messages&lt;/h4&gt;  &lt;p&gt;I also wanted it to be able to detect and disregard dynamic data in exception messages. Ever heard of &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.exception.data.aspx&quot;&gt;Exception.Data&lt;/a&gt;? That&#39;s where we store extra information that we want to tack along for debugging purposes. Exception.Data is great but sometimes it&#39;s to much work and you just want to throw in some debugging data in the Exception.Message string like this: &lt;/p&gt;  &lt;pre class=&quot;brush: csharp&quot;&gt;public void RefundPurchase() {
    if(PurchaseState != &amp;quot;completed&amp;quot;)
        throw new InvalidOperationException(
            &amp;quot;Invalid state for refund: &amp;quot; + PurchaseState
        );
}&lt;/pre&gt;

&lt;p&gt;In order to handle these cases I made the algorithm aware of three &amp;quot;pretty standard&amp;quot; ways of including dynamic data in exception messages. &lt;/p&gt;

&lt;div&gt;
  &lt;ol&gt;
    &lt;li&gt;Text after a colon &#39;:&#39;. &lt;i&gt;Invalid state for refund: inprogress&lt;/i&gt; &lt;/li&gt;

    &lt;li&gt;Text within single and double quotes. &lt;i&gt;Invalid state for refund &amp;quot;inprogress&amp;quot;&lt;/i&gt; &lt;/li&gt;

    &lt;li&gt;Text within balanced parenthesis, brackets and braces. &lt;i&gt;Invalid state for refund (state was inprogress)&lt;/i&gt; &lt;/li&gt;
  &lt;/ol&gt;
&lt;/div&gt;

&lt;h4&gt;Handling localized exceptions&lt;/h4&gt;

&lt;p&gt;I also wanted localized exceptions to produce the same signature when possible. We have a windows app used by some of our customers and we wanted exceptions from them to produce the same signature regardless of their OS language. To accommodate this I added some custom code for exceptions which contain an ErrorCode (SocketException and Win32Exception) and use that instead of the message. &lt;/p&gt;

&lt;h4&gt;Human semi-friendly signatures&lt;/h4&gt;

&lt;p&gt;My last requirement was that the signatures generated would be short so that we could display them to our users when they encounter one of our error-pages. This enables our customer service to provide status updates to calling customers by simply looking up the signature in trac and looking at its status. &lt;/p&gt;

&lt;p&gt;As such the signatures are no-crazy-signs 8 character hex strings, like &amp;quot;617c1de5&amp;quot; and &amp;quot;1570d6d7&amp;quot; &lt;/p&gt;

&lt;h4&gt;Conclusion and possible solution&lt;/h4&gt;

&lt;p&gt;I think I&#39;ve covered all my requirements and I must say that it has worked great for us. All of our exceptions end up in trac where we can prioritize, assign and catalogue them. We even have a great way of knowing when exceptions that we think we&#39;ve squashed re-appear because then the ticket just get re-opened. &lt;/p&gt;

&lt;p&gt;Jeff Atwood wrote about &lt;a href=&quot;http://www.codinghorror.com/blog/archives/001239.html&quot;&gt;using exception logs as a de-facto to do list&lt;/a&gt; a while ago and that&#39;s exactly what we have accomplished using this technique. We even did it long before he published his post but no one will ever believe that =) &lt;/p&gt;

&lt;h4&gt;What about ELMAH?&lt;/h4&gt;

&lt;p&gt;I have not used &lt;a href=&quot;http://code.google.com/p/elmah/&quot;&gt;ELMAH&lt;/a&gt; personally but I&#39;ve certainly &lt;a href=&quot;http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx&quot;&gt;heard&lt;/a&gt; &lt;a href=&quot;http://www.codinghorror.com/blog/archives/001239.html&quot;&gt;many&lt;/a&gt; &lt;a href=&quot;http://www.hanselman.com/blog/ELMAHAndExceptionDrivenDevelopmentFTW.aspx&quot;&gt;great&lt;/a&gt; &lt;a href=&quot;http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx&quot;&gt;things&lt;/a&gt; &lt;a href=&quot;http://scottonwriting.net/sowblog/posts/13882.aspx&quot;&gt;about it&lt;/a&gt;. From what I&#39;ve read about ELMAH it seems that they have some great features for filtering unwanted exceptions but I haven&#39;t seen anything about grouping exceptions. The ideal thing would of course be if existing frameworks like ELMAH used this implementation to provide simple grouping. &lt;/p&gt;

&lt;h4&gt;Our end result&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCmjqkmLOpBCvG3Q-vZwiZv-iaX9IsBaey3B_JYzFI1xDbKHcflw6PlSf50X1lIKlcoLaTKRmFogxBtMUW89DGRpi-Cz9qk-Sorg29W8tN4iVyROYxQmsCcupzAPxxw2pwGjQVxcU3SANZ/s1600-h/trac-tickets%5B5%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;trac-tickets&quot; border=&quot;0&quot; alt=&quot;trac-tickets&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie3rGAoOD_8pQdBdBanf5JaXlktjy0-jHbD0WxGyVRTkgEOu7CdVObL6y3lQ_A7PDSXKTsXCBHx5ONFEM7_1UyvRCs6RO8PnK10j1GxKPCbt02shsQ30XuJQP5LWXj7RK9g2I_okLN3ba5/?imgmax=800&quot; width=&quot;576&quot; height=&quot;112&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8oIL_mu6lh6gyd6hl7fD-ujDsxneEpAGlbouucxgA99CnrK2H8PsmnJpXWl05k6qjwX5LacJjlt6i5OLft1Ooew5M8FlgPRP0A5j4MStcMc-AgWnL1o8f9Md_Prw26kfqH7DtGpnXr69h/s1600-h/image%5B5%5D.png&quot;&gt;&lt;img style=&quot;border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQbjgCMKu5lya94SlBnYDw6vD3wbc0JCHSVXNfjKBgqxRhnFFdFsaTRBAJEyMZ9LHVS0yKcTfXzlhhN_VMBtEK_NSkIEJF5VgWT_JFarwtujHJBK7AnWcgioRXN_89XhVSSo0MN7GjUvg-/?imgmax=800&quot; width=&quot;244&quot; height=&quot;119&quot; /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This is an example of how it looks when we encounter an exception in our system. Note that although the exception was thrown twice there’s only one ticket.&lt;/p&gt;

&lt;h1&gt;&lt;/h1&gt;

&lt;h4&gt;Get the code and abuse it&lt;/h4&gt;

&lt;p&gt;This is the part which makes my stomach ache... The code, complete with a couple of unit tests and an example program plus more information is available at &lt;a href=&quot;http://www.freakcode.com/projects/exception-signatures&quot;&gt;http://www.freakcode.com/projects/exception-signatures&lt;/a&gt;. &lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;http://blog.freakcode.com/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt; &lt;/p&gt;
&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2009%2f07%2fintroducing-exception-signatures.html&quot;&gt;&lt;img border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2009%2f07%2fintroducing-exception-signatures.html&amp;amp;bgcolor=000000&amp;amp;cbgcolor=FFFFFF&quot; /&gt;&lt;/a&gt;  </description><link>http://blog.freakcode.com/2009/07/introducing-exception-signatures.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie3rGAoOD_8pQdBdBanf5JaXlktjy0-jHbD0WxGyVRTkgEOu7CdVObL6y3lQ_A7PDSXKTsXCBHx5ONFEM7_1UyvRCs6RO8PnK10j1GxKPCbt02shsQ30XuJQP5LWXj7RK9g2I_okLN3ba5/s72-c?imgmax=800" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-4117720061071571826</guid><pubDate>Tue, 10 Feb 2009 16:48:00 +0000</pubDate><atom:updated>2009-07-27T00:43:02.106+02:00</atom:updated><title>IIS7 Certificate binding issue</title><description>&lt;p&gt;
I recently tried installing a certificate into IIS7 on an new Windows 2008 server at work. The import whent well but when I tried to bind a site to use the new certificate I got a dialog box with the following message 
&lt;/p&gt;

&lt;pre class=&quot;brush: plain; gutter: false&quot;&gt;---------------------------
Add Site Binding
---------------------------
There was an error while performing this operation.

Details: 

A specified logon session does not exist. It may already have been terminated. (Exception from HRESULT: 0x80070520)
---------------------------
OK   
---------------------------&lt;/pre&gt;

&lt;p&gt;
(Note: The above text was produced by simply focusing the dialog window and pressing CTRL+C; really neat trick!)
&lt;/p&gt;

&lt;p&gt;
After a lot of debugging/googling I managed to find a solution; you have to check the &quot;Allow this certificate to be exported&quot; box when you import the cert. Really strange and really not good practice but until I find another solution that&#39;s the way it has to be. If you&#39;ve got another solution please comment!
&lt;/p&gt;

&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIbs4fl_TLOnWcRNFuaZKmwsTV98kJPk4HTRNPLKGRyDZ1GZaCinYEiGYCPrN3hN49JjYVYvmuChks09z4209s0qJK6y8Z8dF3HdvXa0uyWl27zKyMKQ-3etKRTyJUse5x_ru9I3Uyow_b/s1600-h/importcert.png&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;width: 313px; height: 225px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIbs4fl_TLOnWcRNFuaZKmwsTV98kJPk4HTRNPLKGRyDZ1GZaCinYEiGYCPrN3hN49JjYVYvmuChks09z4209s0qJK6y8Z8dF3HdvXa0uyWl27zKyMKQ-3etKRTyJUse5x_ru9I3Uyow_b/s400/importcert.png&quot; border=&quot;0&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5301212273952118818&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2009/02/iis7-certificate-binding-issue.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIbs4fl_TLOnWcRNFuaZKmwsTV98kJPk4HTRNPLKGRyDZ1GZaCinYEiGYCPrN3hN49JjYVYvmuChks09z4209s0qJK6y8Z8dF3HdvXa0uyWl27zKyMKQ-3etKRTyJUse5x_ru9I3Uyow_b/s72-c/importcert.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-7190273846422243373</guid><pubDate>Thu, 18 Sep 2008 09:11:00 +0000</pubDate><atom:updated>2008-09-18T11:13:24.431+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">humor</category><title>Little bobby tables</title><description>&lt;p&gt;
Hilarious!
&lt;/p&gt;

&lt;img src=&quot;http://imgs.xkcd.com/comics/exploits_of_a_mom.png&quot; alt=&quot;Little bobby tables&quot; /&gt;

&lt;p&gt;
From &lt;a href=&quot;http://xkcd.com/327/&quot;&gt;http://xkcd.com/327/&lt;/a&gt;
&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/09/little-bobby-tables.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-6229256039282708422</guid><pubDate>Fri, 12 Sep 2008 20:45:00 +0000</pubDate><atom:updated>2009-07-27T00:39:41.393+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">extension methods</category><category domain="http://www.blogger.com/atom/ns#">framework tip</category><category domain="http://www.blogger.com/atom/ns#">string extensions</category><title>ToTitleCase</title><description>&lt;p&gt;
Not to long ago I had to write a method to convert lowercase names to proper case for display on a website I was working on. I started rolling my own but then I thought that such a feature would be nice to have in the framework. So I hit google with a query and sure enough the framework authors had thought of it. The method was well hidden though ;)
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;CultureInfo.InvariantCulture.TextInfo.ToTitleCase(&quot;hELLo wORLd&quot;);
// Will return &quot;Hello World&quot;
&lt;/pre&gt;

&lt;p&gt;
This fits quite well in as an extension method
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
/// &amp;lt;summary&amp;gt;
/// Creates a new string with Title Case (ie &amp;quot;hEllO wORLd&amp;quot; becomes  &amp;quot;Hello World&amp;quot;) using the Invariant Culture
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;s&amp;quot;&amp;gt;The string to convert&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;The string in title case&amp;lt;/returns&amp;gt;
public static string ToTitleCaseInvariant(this string s)
{
    return ToTitleCase(s, CultureInfo.InvariantCulture);
}

/// &amp;lt;summary&amp;gt;
/// Creates a new string with Title Case (ie &amp;quot;hEllO wORLd&amp;quot; becomes  &amp;quot;Hello World&amp;quot;)
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;s&amp;quot;&amp;gt;The string to convert&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;The string in title case&amp;lt;/returns&amp;gt;
public static string ToTitleCase(this string s)
{
    return ToTitleCase(s, CultureInfo.CurrentCulture);
}

/// &amp;lt;summary&amp;gt;
/// Creates a new string with Title Case (ie &amp;quot;hEllO wORLd&amp;quot; becomes  &amp;quot;Hello World&amp;quot;)
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;s&amp;quot;&amp;gt;The string to convert&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;ci&amp;quot;&amp;gt;The culture to use when creating title case&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;The string in title case&amp;lt;/returns&amp;gt;
public static string ToTitleCase(this string s, CultureInfo ci)
{
    if (s == null)
        throw new ArgumentNullException(&amp;quot;s&amp;quot;);

    return ci.TextInfo.ToTitleCase(s);
}
&lt;/pre&gt;

&lt;p&gt;
Now you can just call the ToTitleCase on your string objects like this:
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;var s = &quot;george washington&quot;;
s.ToTitleCase();&lt;/pre&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2ftotitlecase.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2ftotitlecase.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/08/totitlecase.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-866592162384818114</guid><pubDate>Sat, 06 Sep 2008 16:25:00 +0000</pubDate><atom:updated>2009-07-27T00:43:38.540+02:00</atom:updated><title>Single instance Calculator.NET</title><description>&lt;p&gt;
Everyone has their set of utility programs that they need to be productive. I&#39;ve got lots of them. Whenever I change computers or reinstall windows I&#39;ve got a list of about 10-15 essential apps that needs to be installed before I do anything else. One of these programs is &lt;a href=&quot;http://weblogs.asp.net/pwelter34/archive/2007/05/05/calculator-net-calculator-that-evaluates-math-expressions.aspx&quot;&gt;Calculator.NET&lt;/a&gt; by Paul Welter
&lt;/p&gt;

&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD4urlPWQXb5BQiF65xj4tgbS21hLwoTpVJZ48DcZW12AfREJi3g-R7ME6yCpNIWgtM-BTuJT6aV6zj94QRHPhyfBGaxw46zmvKUizoh5QoAuqgCLpWvd1er0ySCwE9trV8NcBPtF3CsFV/s320/Calculator.NET.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5242947578380851506&quot; border=&quot;0&quot; /&gt;

&lt;p&gt;
It&#39;s one of those small apps that does exactly what you expect of it and nothing more. It&#39;s got a clean nice history and some built in conversion utilities but other that that it&#39;s just a calculator. It has a built in option (menu item toggle) for setting it to be the default calculator for windows. Simple, and without any hassle.
&lt;/p&gt;

&lt;p&gt;
There&#39;s one tiny thing that bothers me though. At work I&#39;ve got a &lt;a href=&quot;http://www.microsoft.com/hardware/mouseandkeyboard/productdetails.aspx?pid=089&quot;&gt;MS Wireless Desktop 7000&lt;/a&gt; keyboard with one of those neat calculator shortcut buttons right above the numpad and whenever I press it a new instance of Calculator.NET starts up. Ideally though I&#39;d like for my existing Calculator.NET instance (if any) to be focused and restored (if minimized).
&lt;/p&gt;

&lt;h2&gt;Open source to the rescue&lt;/h2&gt;
&lt;p&gt;
Paul was kind enough to provide the &lt;a href=&quot;http://www.loresoft.com/Applications/Calculator/Download/default.aspx&quot;&gt;source to Calculator.NET&lt;/a&gt; and being a curious developer I loaded it up to see if I perhaps could add my little feature myself instead of bugging Paul with a feature request. About half an hour later I was done.
&lt;/p&gt;

&lt;h2&gt;Enter Calculator.NET single instance patch&lt;/h2&gt;

&lt;img src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0d9mJjIVpk5R-p0NFiwzB44nGCLxpll_uLu9pxk8hKtCeit2xCmSSOroP-N_lXrlbiIvlkccF9zZuCJPqPnvB7k-2v8ByaEvlh8lBU1d40QKLHS1TTCgxpKJg0Fa9SUwcuJbCJMQQ71Og/s400/calculator.net-with-singleinstance-patch.jpg&quot; alt=&quot;Calculator.NET with single instance patch&quot; id=&quot;BLOGGER_PHOTO_ID_5242950215130962322&quot; border=&quot;0&quot; /&gt;

&lt;p&gt;
It ensures that only one instance of the calculator is active at any one time but you can override that behavior by passing -force as the first argument or by pressing CTRL+N or by just clicking on the new window icon in the toolbar/menu.
&lt;/p&gt;

&lt;h2&gt;And here is the code&lt;/h2&gt;
&lt;p&gt;
It uses a named mutex to ensure that only one instance can run at any given moment.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
static void Main(string[] args)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    string optStr = string.Empty;

    if(args.Length &amp;gt; 0)
        optStr = args[0].Trim().ToLower();

    if (optStr != &amp;quot;-force&amp;quot; &amp;amp;&amp;amp; Settings.Default[&amp;quot;SingleInstanceMode&amp;quot;] != null &amp;amp;&amp;amp;  Settings.Default.SingleInstanceMode)
    {
        using (Mutex m = new Mutex(false, &amp;quot;Calulator.NET single instance&amp;quot;))
        {
            if (!m.WaitOne(0, false))
            {
                // There is already an instance of Calculator.NET running.
                // Attempt to locate the window and bring it to front
                IntPtr hWnd = FindWindow(null, &amp;quot;Calculator.NET&amp;quot;);

                if (hWnd.ToInt32() != 0)
                {
                    ShowWindow(hWnd, SW_RESTORE);
                    SetForegroundWindow(hWnd);
                }
            }
            else
            {
                RunApp();
            }
        }
    }
    else
    {
        RunApp();
    }
}

private static void RunApp()
{
    Application.Run(new CalculatorForm());
}

const int SW_RESTORE = 9;

[DllImport(&amp;quot;user32.dll&amp;quot;, SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport(&amp;quot;user32.dll&amp;quot;)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport(&amp;quot;user32.dll&amp;quot;)]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
&lt;/pre&gt;

&lt;p&gt;
If you want to apply it to your build begin by downloading the &lt;a href=&quot;http://www.loresoft.com/Applications/Calculator/Download/default.aspx&quot;&gt;source to Calculator.NET&lt;/a&gt; and then go get my patch &lt;a href=&quot;http://www.mediafire.com/file/dsikitlwi1s/Calculator.NET-singleinstance-patch.zip&quot;&gt;Calculator.NET-singleinstance-patch.zip&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Just unpack the Calculator.NET zip file and then copy the contents of my zip into that directory and you&#39;re good to go. I&#39;ll drop a comment over at &lt;a href=&quot;http://weblogs.asp.net/pwelter34/default.aspx&quot;&gt;Paul&#39;s weblog&lt;/a&gt; and then we&#39;ll see if it&#39;s something he&#39;d consider adding to the official version.
&lt;/p&gt;

&lt;p&gt;
If you don&#39;t want the build hassle you can simply download the binary &lt;a href=&quot;http://www.mediafire.com/file/slqjkzamlgq/Calculator.NET-singleinstance.exe&quot;&gt;Calculator.NET-singleinstance.exe&lt;/a&gt;
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;http://blog.freakcode.com/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f09%2fsingle-instance-calculatornet.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f09%2fsingle-instance-calculatornet.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2008/09/single-instance-calculatornet.html</link><author>noreply@blogger.com (Markus Olsson)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD4urlPWQXb5BQiF65xj4tgbS21hLwoTpVJZ48DcZW12AfREJi3g-R7ME6yCpNIWgtM-BTuJT6aV6zj94QRHPhyfBGaxw46zmvKUizoh5QoAuqgCLpWvd1er0ySCwE9trV8NcBPtF3CsFV/s72-c/Calculator.NET.png" height="72" width="72"/></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-7571214671497166500</guid><pubDate>Thu, 04 Sep 2008 11:07:00 +0000</pubDate><atom:updated>2009-07-27T00:44:10.533+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">framework tip</category><category domain="http://www.blogger.com/atom/ns#">snippet</category><title>High precision performance measurement</title><description>&lt;p&gt;
Sometimes you need to get a feel for how performant a specific method is. I&#39;ve seen lots of developers use DateTime.Now for this. Like this:
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
DateTime start = DateTime.Now;
PerformWork();
TimeSpan ts = DateTime.Now - start
Console.WriteLine(&quot;Time taken: {0}ms&quot;, ts.TotalMilliseconds);
&lt;/pre&gt;

&lt;p&gt;
Now, there&#39;s a couple of problems with this. First off, DateTime.Now performs way worse than DateTime.UtcNow since it has to get the UTC time and the calculate timezone and DST offsets.
&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;p&gt;
The second and more concerning problem is that DateTime has a resolution of about 15ms, it can&#39;t be more precise than that. Now, in development code you could of course get around this by running your code a couple of thousand time to compensate for the low precision but what if you&#39;re code can&#39;t easily be run more than one time (perhaps it performs expensive and hard-to-recover database work).
&lt;/p&gt;

&lt;h4&gt;Stopwatch to the rescue&lt;/h4&gt;
&lt;p&gt;
The &lt;a href=&quot;http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx&quot;&gt;System.Diagnostics.Stopwatch&lt;/a&gt; class provides high-precision measurement of elapsed time. Using hardware frequency counters it achieves nanosecond precision and it&#39;s really easy to use.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
Stopwatch sw = Stopwatch.StartNew();
PerformWork();
sw.Stop();

Console.WriteLine(&quot;Time taken: {0}ms&quot;, sw.Elapsed.TotalMilliseconds);
&lt;/pre&gt;

&lt;p&gt;
The stopwatch falls back on DateTime.UtcNow if your hardware doesn&#39;t support a high frequency counter. You can check to see if Stopwatch utilizes hardware to achieve high precision by looking at the static field &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.ishighresolution.aspx&quot;&gt;Stopwatch.IsHighResolution&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
This post is essentially a ripoff of my answer to a question regarding time measurement on the kickass Q/A site &lt;a href=&quot;http://stackoverflow.com&quot;&gt;stackoverflow.com&lt;/a&gt; (not open to public yet).
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f09%2fhigh-precision-performance-measurement.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f09%2fhigh-precision-performance-measurement.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2008/09/high-precision-performance-measurement.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-6274226821958953298</guid><pubDate>Tue, 02 Sep 2008 07:03:00 +0000</pubDate><atom:updated>2009-07-27T00:44:29.702+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">extension methods</category><title>The hazards of extension methods</title><description>&lt;p&gt;
I love extension methods! I really do, to the point that I have to constrain myself so that this blog won&#39;t turn into a shrine where followers of extension methods hang around all day praising &lt;a href=&quot;http://msdn.microsoft.com/en-us/vcsharp/aa336719.aspx&quot;&gt;the founders&lt;/a&gt; for giving us this precious gift.
&lt;/p&gt;

&lt;p&gt;
That being said though I have one major issue with extension methods. Since exception methods is essentially &lt;a href=&quot;http://blogs.msdn.com/jaredpar/archive/2007/11/30/calling-extension-methods-on-null-objects.aspx&quot;&gt;glorified static methods&lt;/a&gt; they will accept you calling them even if the object reference is null.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
string s = null;
s.ToString(); // This will throw a NullReferenceException
s.HtmlEncode(); // This will not
&lt;/pre&gt;

&lt;p&gt;
Now, did you see the difference? Since it&#39;s the string object we&#39;re talking about we all know that the HtmlEncode method doesn&#39;t belong there and thus we can deduce that it&#39;s an extension method but what if it where some lesser known object and the method name wasn&#39;t so obvious? It works since the s.HtmlEncode call will be compiled into something like this: StringExtensions.HtmlEncode(s)
&lt;/p&gt;

&lt;p&gt;
Well, I thought about it for a while and I decided that &lt;span style=&quot;font-weight:bold;&quot;&gt;I don&#39;t like it!&lt;/span&gt; I don&#39;t like it one bit actually and while I do respect the decision to make it this way I feel that it will essentially undermine the respect that C# developers have for null references. Whenever I look at some code calling an instance method there is something, embedded deep in my cerebral cortex, that tells me that I should watch out for nullity but when I see extension methods that allow (or actually depends on) the reference to be null my fear of NullReferenceException gradually goes away.
&lt;/p&gt;

&lt;p&gt;
So what&#39;s my recommended solution? Well, with great power comes great responsibility and of course it&#39;s up to you whether or not you&#39;re going to include these methods in your code. I will not! Whenever I write an extension method I explicitly check for nullity and raise the ArgumentNullException.
&lt;/p&gt;

&lt;p&gt;
The worst use of this this that I&#39;ve seen so far is without a doubt the &lt;a href=&quot;http://www.extensionmethod.net/Details.aspx?ID=111&quot;&gt;IsNull extension method&lt;/a&gt; which essentially lets you do this:
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
string s = null;

if(!s.IsNull())
    PerformWork(s)

if(s != null)
    PerformWork(s)
&lt;/pre&gt;

&lt;p&gt;
Now do you see the problem here? It&#39;s actually more code, less obvious, (IMO)  less readable than the &quot;original&quot; null comparison and it breaks a very important rule; you can&#39;t call instance methods on null references. Now, I have no problem with the &lt;a href=&quot;http://www.extensionmethod.net/Details.aspx?ID=97&quot;&gt;IsEmpty&lt;/a&gt; extension method since that doesn&#39;t break any null rules.
&lt;/p&gt;

&lt;p&gt;
PS. This whole post is actually a reaction to the &lt;a href=&quot;http://blog.freakcode.com/2008/08/collectionisnullorempty.html#c3456495680449753290&quot;&gt;anonymous comment&lt;/a&gt; suggesting that I convert my &lt;a href=&quot;http://blog.freakcode.com/2008/08/collectionisnullorempty.html&quot;&gt;Collection.IsNullOrEmpty&lt;/a&gt; method into an extension method. DS.
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2008/09/hazards-of-extension-methods.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-2464351863676470585</guid><pubDate>Mon, 01 Sep 2008 16:06:00 +0000</pubDate><atom:updated>2008-09-01T18:19:49.513+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">meta</category><title>Kick me please!</title><description>&lt;p&gt;
Yup, you heard me. I want you to kick me. Not physically though, I hope I didn&#39;t dissapoint you there.
&lt;/p&gt;

&lt;p&gt;
Under every .net related blog post I make you&#39;ll see a little image that looks like this:&lt;/p&gt; 

&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2fstartswithanyof-extension-method.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; alt=&quot;Kick me!&quot;&gt;


&lt;p&gt;
That&#39;s a shortcut for kicking (or voting for) my blog post at &lt;a href=&quot;http://dotnetkicks.com/&quot;&gt;dotnetkicks.com&lt;/a&gt;, a digg-like community driven site for interesting .net articles. So if you see a post that you like, please please please vote for it. I&#39;d so like to get one of my articles onto the front page of that site. Signup is easy and I haven&#39;t had any problems with spam or unwanted email (actually, I haven&#39;t received a single email other than the confirmation mail).
&lt;/p&gt;

&lt;p&gt;
Now, I&#39;m not saying that you should vote for it if you think it stinks but if you felt that it was a well written or insightful article that someone else could appreciate I&#39;d appreciate it if you vote for it.
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/09/kick-me-please.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-3429997878398758711</guid><pubDate>Sun, 31 Aug 2008 20:00:00 +0000</pubDate><atom:updated>2009-07-27T00:45:13.206+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">extension methods</category><category domain="http://www.blogger.com/atom/ns#">readability</category><category domain="http://www.blogger.com/atom/ns#">string extensions</category><title>StartsWithAnyOf extension method</title><description>&lt;p&gt;
Here comes another great string extension for improved readability. You all know how to check if a string starts with another string (yep, it&#39;s the StartsWith method I&#39;m talking about).
&lt;/p&gt;

&lt;p&gt;
But what if you wan&#39;t to check if a string starts with any of a series of strings? Well, you&#39;d have to do something like this.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
string name = &quot;Mr. Markus Olsson&quot;
var l = new List&amp;lt;string&amp;gt; { &quot;Dr&quot;, &quot;Mr&quot;, &quot;Ms&quot; };
bool found;
foreach(string s in l) {
    if(name.StartsWith(l)) {
        found = true;
        break;
    }
}
&lt;/pre&gt;

&lt;p&gt;
Or, you could use lambdas for a much more elegant solution
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
string name = &quot;Mr. Markus Olsson&quot;
var l = new List&amp;lt;string&amp;gt; { &quot;Dr&quot;, &quot;Mr&quot;, &quot;Ms&quot; };
bool found = l.Exists(prefix =&gt; name.StartsWith(prefix));
&lt;/pre&gt;

&lt;p&gt;
That&#39;s pretty cool, right? The .Exists method on the list object takes a Predicate&lt;string&gt; as a parameter and executes that predicate with each element as it&#39;s first argument until it finds a match. Coolio indeed but we can do better readability wise.
&lt;/p&gt;

&lt;h4&gt;Enter StartsWithAnyOf extension methods&lt;/h4&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
/// &amp;lt;summary&amp;gt;
/// Checks to see if the string starts with any of the supplied strings
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;s&amp;quot;&amp;gt;The string to check for a start value&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;strings&amp;quot;&amp;gt;One or more strings&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;True the strings starts with any of the supplied strings, false otherwise&amp;lt;/returns&amp;gt;
public static bool StartsWithAnyOf(this string s, params string[] strings)
{
    if (s == null)
        throw new ArgumentNullException(&amp;quot;s&amp;quot;);

    if (strings == null)
        throw new ArgumentNullException(&amp;quot;strings&amp;quot;);

    if (strings.Length == 0)
        throw new ArgumentOutOfRangeException(&amp;quot;strings&amp;quot;, &amp;quot;You must supply one or more strings&amp;quot;);

    return Array.Exists(strings, (prefix =&gt; s.StartsWith(prefix)); 
}

/// &amp;lt;summary&amp;gt;
/// Checks to see if the string starts with any of the supplied strings
/// &amp;lt;/summary&amp;gt;
/// &amp;lt;param name=&amp;quot;s&amp;quot;&amp;gt;The string to check for a start value&amp;lt;/param&amp;gt;
/// &amp;lt;param name=&amp;quot;strings&amp;quot;&amp;gt;One or more strings&amp;lt;/param&amp;gt;
/// &amp;lt;returns&amp;gt;True the strings starts with any of the supplied strings, false otherwise&amp;lt;/returns&amp;gt;
public static bool StartsWithAnyOf(this string s, List&amp;lt;string&amp;gt; strings)
{
    if (s == null)
        throw new ArgumentNullException(&amp;quot;s&amp;quot;);

    if (strings == null)
        throw new ArgumentNullException(&amp;quot;strings&amp;quot;);

    if (strings.Count == 0)
        throw new ArgumentOutOfRangeException(&amp;quot;strings&amp;quot;, &amp;quot;You must supply one or more strings&amp;quot;);

    return strings.Exists(x =&amp;gt; s.StartsWith(x));
}
&lt;/pre&gt;

&lt;p&gt;
This allows us to rewrite our code to
&lt;/p&gt;

&lt;pre class=&quot;prettyprint&quot;&gt;
string name = &quot;Mr. Markus Olsson&quot;
bool found = name.StartsWithAnyOf(&quot;Dr.&quot;, &quot;Mr.&quot;, &quot;Ms.&quot;);
&lt;/pre&gt;

&lt;p&gt;
Readability in a nutshell. Variations of these extension methods includes an override that takes a StringComparison in order to allow for case insensitive lookup. The EndsWithAnyOf method is of course also a must.
&lt;/p&gt;

&lt;p&gt;

&lt;div style=&quot;text-decoration: line-through&quot;&gt;
&lt;span style=&quot;font-weight:bold;&quot;&gt;Update:&lt;/span&gt; as &lt;a href=&quot;#c5607516206550508301&quot;&gt;mattias&lt;/a&gt; pointed out there&#39;s a bit of code duplication here but that&#39;s intentional, &lt;a href=&quot;#c6473780186728652317&quot;&gt;read why&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-decoration: line-through&quot;&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Update 2:&lt;/span&gt; I changed my mind again after discussing it with mattias and for the sake of readability and code-duplication I&#39;ve decided to wrap the first method into a call of the second.&lt;/div&gt;
&lt;div&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;Update 3:&lt;/span&gt; &lt;a href=&quot;/2008/08/startswithanyof-extension-method.html#c5143598628428393762&quot;&gt;James Curran&lt;/a&gt; pointed out that the Array class have an Exist method and that&#39;s of course what you want for the string array. Thanks James!&lt;/div&gt;
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2fstartswithanyof-extension-method.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2fstartswithanyof-extension-method.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2008/08/startswithanyof-extension-method.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-6663975100780832846</guid><pubDate>Sat, 30 Aug 2008 18:18:00 +0000</pubDate><atom:updated>2009-07-27T00:48:26.811+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">snippet</category><title>Collection.IsNullOrEmpty</title><description>&lt;p&gt;
Ah, &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.string.isnullorempty.aspx&quot;&gt;string.IsNullOrEmpty&lt;/a&gt;. It was love at first sight when I found that simple yet extremely useful method. It&#39;s quite often you want check if a string is null or empty. Instead of checking if the string is null and then checking if it is of zero length (or god forbid checking if it equals string.Empty) you can call this this method and it does it for you. Not only does it save you from unnecessary keystrokes, it also increases readability.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
string s = null;
if(!string.IsNullOrEmpty(s))
    PerformWork(s);
&lt;/pre&gt;

instead of 


&lt;pre class=&quot;brush: csharp&quot;&gt;
string s = null;
if(s != null &amp;&amp; s.Length &gt; 0)
    PerformWork(s);
&lt;/pre&gt;

&lt;p&gt;
Well, you probably get my point, it&#39;s awesome. But I found that I still write if-statements checking for nullity and length of lists, hashsets and other collections. I can&#39;t quite figure out why the BCL team didn&#39;t include a corresponding method for collections (or perhaps they did? Enlighten me plix!). Don&#39;t despair though, uncle Markus is here to help.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
using System.Collections;

namespace freakcode.Utils
{
   public static class Collection
   {
       /// &amp;lt;summary&amp;gt;
       /// Checks if the supplied collection is null or empty
       /// &amp;lt;/summary&amp;gt;
       /// &amp;lt;param name=&quot;il&quot;&amp;gt;The collection&amp;lt;/param&amp;gt;
       /// &amp;lt;returns&amp;gt;True if the collection is null or empty, false otherwise&amp;lt;/returns&amp;gt;
       public static bool IsNullOrEmpty(ICollection ic)
       {
           return (ic == null || ic.Count == 0);
       }

   }
}
&lt;/pre&gt;

&lt;p&gt;
It&#39;s so simple it&#39;s almost embarrassing to post but it sure increases readability and it&#39;s a really great method to integrate and enforce in you own repository of utility methods.
&lt;/p&gt;

&lt;pre class=&quot;brush: csharp&quot;&gt;
var employees = new List&amp;lt;string&amp;gt;() {&quot;Bob&quot;, &quot;Alice&quot;, &quot;Tom&quot; };
if(Collection.IsNullOrEmpty(employees))
    FireTheirAsses(employees);
&lt;/pre&gt;

&lt;p&gt;
You could rename/copy this to List.IsNullOrEmpty if you think that produces cleaner and more readable code.
&lt;/p&gt;

&lt;p class=&quot;license&quot;&gt;&lt;a href=&quot;/2008/08/license.html&quot;&gt;Licensing information&lt;/a&gt;&lt;/p&gt;

&lt;a href=&quot;http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2fcollectionisnullorempty.html&quot;&gt;&lt;img src=&quot;http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fblog.freakcode.com%2f2008%2f08%2fcollectionisnullorempty.html&amp;bgcolor=000000&amp;cbgcolor=FFFFFF&quot; border=&quot;0&quot; alt=&quot;kick it on DotNetKicks.com&quot; /&gt;&lt;/a&gt;</description><link>http://blog.freakcode.com/2008/08/collectionisnullorempty.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-6527880530782906985</guid><pubDate>Sat, 30 Aug 2008 12:00:00 +0000</pubDate><atom:updated>2009-07-25T22:30:57.176+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">meta</category><title>Code license information</title><description>&lt;p&gt;
Yup, we all have our &lt;a href=&quot;http://www.codinghorror.com/blog/archives/000833.html&quot;&gt;problems with licenses&lt;/a&gt;. But I&#39;m planning on throwing some code out to the reader(s) of this blog (hi mom!) and I thought that I&#39;d make sense to make it clear from the beginning.
&lt;/p&gt;

&lt;p&gt;
I have limited understanding of copyright law, especially US law but I suspect that most of the smaller code samples won&#39;t pass &lt;a href=&quot;http://en.wikipedia.org/wiki/Threshold_of_originality&quot;&gt;threshold of originality&lt;/a&gt; and thus isn&#39;t even copyrightable.
&lt;/p&gt;

&lt;p&gt;
The code snippets that do pass the treshold is (unless otherwise noted) written by me and I will place them under the &lt;span style=&quot;font-weight:bold;&quot;&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/MIT_License&quot;&gt;MIT-license&lt;/a&gt;&lt;/span&gt; and they can be used for whatever purpose you want, commercial or otherwise. Please give credit where credit is due though. Common sense applies. If you want to discuss specifics feel free to &lt;a href=&quot;http://www.freakcode.com/contact&quot;&gt;contact me&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
In the case of blog posts concerning contributions to other projects where the project prohibits the use of MIT-license for contributions the supplied code will of course comply with the license of said project. Should I for example contribute to a project that&#39;s licensed under GPL my code will be licensed the same way.
&lt;/p&gt;

&lt;p&gt;
If you like a particular snippet or code sample that I&#39;ve posted, please link to it from your blog, your code where you integrated it or wherever. Help me gather some pagerank karma!
&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/08/license.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-8660048925778121165</guid><pubDate>Sat, 30 Aug 2008 08:05:00 +0000</pubDate><atom:updated>2008-08-30T10:05:01.082+02:00</atom:updated><title>Inpossible word verification</title><description>&lt;p&gt;
&lt;a href=&quot;http://membot.blogspot.com/&quot;&gt;That Chosen One&lt;/a&gt; pointed out how irritating it is to have to have to pass CAPTCHA every time you want to comment. I totally agree. I even had a hard time setting up this blog since the CAPTCHA was so hard to read. Therefore I&#39;ve changed the settings so that word verification is no longer required for posting comments. Unfortunately this also means that you wont be able to post comments without having an OpenID or Google account.
&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/08/inpossible-word-verification.html</link><author>noreply@blogger.com (Markus Olsson)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5459393636366885547.post-1367726898369542829</guid><pubDate>Fri, 29 Aug 2008 20:01:00 +0000</pubDate><atom:updated>2009-07-25T21:10:12.029+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">meta</category><title>Hello world</title><description>&lt;p style=&quot;font-size: x-small&quot;&gt;This intro is brought to you by the imaginary interviewer. For your viewing pleasure!&lt;/p&gt;

&lt;h4&gt;Oh, great, another developer, who are you?&lt;/h4&gt;
&lt;p&gt;
I&#39;m a developer from Sweden and currently I spend most of my time with .NET web and applications development. Exclusively C# for the .NET stuff. I&#39;m employed by a small company (~12 employees) with big ambitions where I work on a product for which I was one of the founders. I&#39;ll share more on my work later on.
&lt;/p&gt;

&lt;p&gt;
I&#39;ve been an active developer for more years than I can remember and I have a broad background. I started with QBasic at age eleven or twelve continuing onto pascal and then back to VB. After that I jumped ship and became an avid linux supporter/developer/evangelist which resulted in quite a lot of bash scripting at first continuing onto C but that was not my cup of tea. I think PHP came next and I started a small consulting business along with some friends called Softdays development to do some web development (hey, everybody was doing it).
&lt;/p&gt;

&lt;p&gt;
After building webshops for a while I found my first programming language love: python and I developed quite a lot of stuff in python before my work situation forced my into a radically new direction.
&lt;/p&gt;

&lt;p&gt;
In the initial stages of planning for our new killer product at work I was introduced to my new colleague who was a real, all-the-way-to-the-bone Microsoft dude. Needless to say we fought like cats and dogs for about a year and there where a lot of hard discussions about how we where going to go about building this system of ours. We eventually settled (against my strongest recommendataion) on ASP.NET 2.0 (which was in early beta at the time), C# and SQL Server. I&#39;m really glad we did because C# and .NET (especially with all the new cool features of .net 3.5) really rocks!
&lt;/p&gt;

&lt;h4&gt;ENOUGH! We don&#39;t care! Why would we want another developer blog?&lt;/h4&gt;

&lt;p&gt;
I don&#39;t think the world can get enough of developer blogs ;) Seriously though, I plan to blog for two reasons:
&lt;ol&gt;
  &lt;li&gt;To share the cool/time saving/bug killing code that I produce or find&lt;/li&gt;
  &lt;li&gt;To keep myself up to date and to, hopefully, get some input from the community on what I&#39;m thinking&lt;/li&gt;
&lt;/ol&gt;

That being said I don&#39;t have any special insight on how to avoid blogdeath. I&#39;ve tried blogging before with, shall we say, limited success. But I think that&#39;s because I tried blogging about my general life and that&#39;s not interesting enough to write &lt;i&gt;or&lt;/i&gt; read ;)
&lt;/p&gt;

&lt;h4&gt;Okay, so what can we expect to read then?&lt;/h4&gt;

&lt;p&gt;
I don&#39;t quite know yet. My general idea is that I&#39;ll be posting some cool code snippets to begin with and I&#39;ll definitely share my view on currently relevant questions and topics in the .net/c#/asp.net community.
&lt;/p&gt;

&lt;p&gt;
I&#39;ve lined up a couple of posts already that I&#39;ll be posting over the next couple of days (yup, they&#39;re already written) but other than that I think we&#39;ll just have to wait and see
&lt;/p&gt;

&lt;h4&gt;Uh oh, I know where this is going, you wan&#39;t our help don&#39;t you?&lt;/h4&gt;

&lt;p&gt;
Er, um... hmm. Well... I&#39;d really like to try to get this blog going and to do that I&#39;d really appreciate if you could spread the link to your developer friends and colleagues. I also gladly accept questions that you think would be interesting to blog about. Some pagerank karma wouldn&#39;t hurt either (link me plix!). If you&#39;d like to write a guest-post that&#39;d also be great.
&lt;/p&gt;

&lt;h4&gt;Hey, wait a minute, aren&#39;t you swedish?&lt;/h4&gt;

&lt;p&gt;
Thats correct, but &lt;a href=&quot;http://membot.blogspot.com/2007/09/this-is-internet.html&quot;&gt;this is not Sweden, this is the Internet&lt;/a&gt; and it only speaks english ;)
&lt;/p&gt;

&lt;h4&gt;Yeah alright... how do I contact you then?&lt;/h4&gt;
&lt;p&gt;
Oh, a new friend, yeay! Well, commenting is one way of course. Email is another, you&#39;ll find my email at &lt;a href=&quot;http://www.freakcode.com/contact/&quot;&gt;www.freakcode.com/contact/&lt;/a&gt;
&lt;/p&gt;</description><link>http://blog.freakcode.com/2008/08/about-me.html</link><author>noreply@blogger.com (Markus Olsson)</author></item></channel></rss>