<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bugfree.dk - Ronnie Holm&#039;s blog &#187; Tool</title>
	<atom:link href="http://www.bugfree.dk/blog/tag/tool/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bugfree.dk/blog</link>
	<description>Not anti-anything, just pro-quality</description>
	<lastBuildDate>Wed, 08 Sep 2010 13:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Unit testing LINQ to SQL using TypeMock</title>
		<link>http://www.bugfree.dk/blog/2010/05/04/unit-testing-linq-to-sql-using-typemock/</link>
		<comments>http://www.bugfree.dk/blog/2010/05/04/unit-testing-linq-to-sql-using-typemock/#comments</comments>
		<pubDate>Tue, 04 May 2010 19:23:00 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/?p=1050</guid>
		<description><![CDATA[Recent months have brought about a proliferation of mocking frameworks that mocks what more traditional framework like Rhino Mocks cannot. Instead of creating and loading a mock implementation at runtime, the new breed of mocking frameworks hooks into the CLR to intercept and redirect calls. This opens up virtually every aspect of a class to [...]]]></description>
			<content:encoded><![CDATA[<p>Recent months have brought about a proliferation of mocking frameworks that mocks what more traditional framework like <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino Mocks</a> cannot. Instead of creating and loading a mock implementation at runtime, the new breed of mocking frameworks hooks into the CLR to <a href="http://www.bugfree.dk/blog/2009/02/11/an-example-of-unit-testing-using-typemock">intercept and redirect calls</a>. This opens up virtually every aspect of a class to mocking, which is useful for testing code not written with explicit testability in mind. Until recently, <a href="http://site.typemock.com/typemock-isolator-product">TypeMock</a> was the only mocking framework around that took the latter approach, but it’s now being challenged by <a href="http://research.microsoft.com/en-us/projects/moles">Moles</a> from Microsoft Research and <a href="http://www.telerik.com/products/mocking.aspx">JustMock</a> from Telerik.</p>
<h4>Why traditional dependency-breaking techniques come short</h4>
<p>After watching a screencast on how to <a href="http://www.dimecasts.net/Casts/CastDetails/170">use Moles to unit test LINQ to SQL</a> without hitting the database, I thought it would be interesting to do the same with TypeMock. But first, let’s make sure we understand why traditional dependency-breaking techniques come short in testing LINQ to SQL. Assuming we want to put a repository under test, our goal is to mock how it accesses the database. Here’s a simple implementation of a repository that queries the Employee table of the <a href="http://sqlserversamples.codeplex.com">AdventureWorks</a> database:</p>
<pre class="prettyprint lang-cs">    public class EmployeeRepository {
        public List&lt;Employee&gt; GetEmployeesByHireDate(DateTime start, DateTime end) {
            using (var ctx = new AdventureWorksDataContext())
                return (from e in ctx.Employees
                        where e.HireDate &gt;= start &amp;&amp; e.HireDate &lt;= end
                        select e).ToList();
        }
    }
</pre>
<p>All calls to the database are routed through the AdventureWorksDataContext generated by Visual Studio. To mock access to the database, we therefore have to mock part of the data context. Easier said than done, though, for the context doesn’t expose an interface that a fake can implement. In addition, the tables are accessed through properties on the context that return a type of <a href="http://msdn.microsoft.com/en-us/library/bb358844">Table&lt;TEntity&gt;</a>. Unfortunately, the constructor of Table&lt;TEntity&gt; is internal and the class itself is sealed, eliminating the hope of instantiating or subclassing the type by traditional means:</p>
<pre class="prettyprint lang-cs">    public sealed class Table&lt;TEntity&gt; : IQueryProvider,
            ITable, IListSource, ITable&lt;TEntity&gt;, IQueryable&lt;TEntity&gt;,
            IEnumerable&lt;TEntity&gt;, IQueryable, IEnumerable
            where TEntity : class {
        internal Table(DataContext context, MetaTable metaTable) {
            ...
        }
    }</pre>
<p>For an example of how the data context itself creates an instance of Table&lt;TEntity&gt;, take a look at the Employees property on the AdventureWorksDataContext. It relies on the GetTable&lt;Employee&gt; method on the DataContext class to create an instance of Table&lt;Employee&gt;. Despite its constructors being internal, the GetTable&lt;TEntity&gt; method has no trouble constructing an instance of the Table&lt;TEntity&gt; type, as they both reside in the System.Data.Linq assembly:</p>
<pre class="prettyprint lang-cs">    public partial class AdventureWorksDataContext : DataContext {
        public Table&lt;Employee&gt; Employees {
            get {
                return GetTable&lt;Employee&gt;();
            }
        }
    }</pre>
<h4>How to break the unbreakable</h4>
<p>The design of LINQ to SQL leaves us short of a traditional testing seam, as <a href="http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052">Michael Feathers</a> would phrase it; a place at which we can alter the behavior of a program without editing in that place. This explains why, with LINQ to SQL, traditionally we’ve had to test against a real database with all its constraints, making our tests brittle, slow, and painful to write and maintain. With the new breed of mocking frameworks the issues of not being able to subclass or not being able to call an internal constructor go away (and new issues take their place). Regardless, here’s how to write a unit test for the CustomerRepository that doesn’t hit the database:</p>
<pre class="prettyprint lang-cs">    [TestClass]
    public class CustomerRepositoryTest {
        private EmployeeRepository _repository;

        [TestInitialize]
        public void Initialize() {
            _repository = new EmployeeRepository();

            var fakeEmployees = new List&lt;Employee&gt; {
                new Employee {EmployeeID = 1, HireDate = new DateTime(2004, 12, 1)},
                new Employee {EmployeeID = 2, HireDate = new DateTime(2006, 7, 1)},
                new Employee {EmployeeID = 3, HireDate = new DateTime(2009, 3, 1)}
            }.AsQueryable();

            var fakeDataContext = Isolate.Fake.Instance&lt;AdventureWorksDataContext&gt;();
            Isolate.Swap.NextInstance&lt;AdventureWorksDataContext&gt;().With(fakeDataContext);

            // var fakeEmployeeTable = Isolate.Fake.Instance&lt;Table&lt;Employee&gt;&gt;();
            // Isolate.WhenCalled(() =&gt; fakeDataContext.Employees).WillReturn(fakeEmployeeTable);
            // Isolate.WhenCalled(() =&gt; fakeEmployeeTable).WillReturnCollectionValuesOf(fakeEmployees);
            // or by transitivity
            Isolate.WhenCalled(() =&gt; fakeDataContext.Employees).WillReturnCollectionValuesOf(fakeEmployees);
        }

        [TestMethod]
        public void GetEmployeesByHireDate_should_return_hires_from_2008_until_present() {
            var employees = _repository.GetEmployeesByHireDate(new DateTime(2008, 1, 1), DateTime.Now);
            Assert.AreEqual(1, employees.Count());
            Assert.AreEqual(3, employees[0].EmployeeID);
        }
    }
</pre>
<p>The test method itself looks exactly as if we’d been testing against a real database. The difference lies in the Initialize method, where we setup the fake data context and database contents. We instruct TypeMock to return the fake context in place of the real one inside EmployeeRepository. And whenever someone calls the Employees property on the fake context, we have TypeMock intercept the call and return a fake collection of type <a href="http://msdn.microsoft.com/en-us/library/bb351562.aspx">IQueryable&lt;Employee&gt;</a>. We could’ve returned an instance of Table&lt;Employee&gt;, which implements IQueryable&lt;Employee&gt;, but in this case returning the collection is simpler and sufficient. Had we had more methods on our repository, we likely would’ve added additional rows to the Employee table and populated more of its columns.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2010/05/04/unit-testing-linq-to-sql-using-typemock/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting organized with Emacs Org-mode</title>
		<link>http://www.bugfree.dk/blog/2009/11/05/getting-organized-with-emacs-org-mode/</link>
		<comments>http://www.bugfree.dk/blog/2009/11/05/getting-organized-with-emacs-org-mode/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 21:42:02 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Emacs]]></category>
		<category><![CDATA[Logging]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/?p=694</guid>
		<description><![CDATA[It&#8217;s been four months and 350 clocked work-hours since I started using Org-mode for Emacs. I use Org-mode, mixed with some of the Pomodoro principles, to maintain my task lists at work and home. In a nutshell Org-mode is a plug-in for Emacs that makes taking notes, maintaining lists, clocking time, and many other tasks [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been four months and 350 clocked work-hours since I started using <a href="http://orgmode.org">Org-mode</a> for <a href="http://www.gnu.org/software/emacs/">Emacs</a>. I use Org-mode, mixed with some of the <a href="http://www.pomodorotechnique.com">Pomodoro principles</a>, to maintain my task lists at work and home.</p>
<p>In a nutshell Org-mode is a plug-in for Emacs that makes taking notes, maintaining lists, clocking time, and many other tasks more straightforward. The mode works by adding features on top of Emacs for editing plain text files. Features that enrich the interaction with the underlying text buffer by parsing and adding (meta-)information to it.</p>
<p>With Org-mode you group items into a hierarchical structure. A path to the item to work on is then formed by unfolding items in a way analogous to how you navigate the file system with Explorer.</p>
<p><img alt="" src="http://www.bugfree.dk/blog/wp-content/uploads/2009/11/Org-mode-example1.png" /></p>
<p>To efficiently work with items, Org-mode supports moving items around the hierarchy. Items may also be tagged (buy, work, phone, etc.) or associated with a state (done, waiting, started, etc.). Additional meta-information may include a deadline, an estimate, or time spent working on a task. The clocking of time is accomplished by Org-mode adding a timestamp to the item. On completion, another timestamp and the elapsed time is calculated and added.</p>
<p>Below is an example of an expanded and a collapsed item containing clocked times and estimates.</p>
<p><img alt="" src="http://www.bugfree.dk/blog/wp-content/uploads/2009/11/Org-mode-example2.png" /></p>
<p>With a few keystrokes, Org-mode is able to correlate estimates with time spent on an item-by-item basis. This truly short-circuits the estimation feedback cycle. Imagine doing this on a file containing a large hierarchy of items and the transparency it brings.</p>
<p><img alt="" src="http://www.bugfree.dk/blog/wp-content/uploads/2009/11/Org-mode-example3.png" /></p>
<p>If you want to keep track of billable hours, it may make sense to clock all your time using Org-mode and generate timesheets from the clocking information. Especially since the billing context is automatically provided by the item storing the timestamp, and since you&#8217;re free to organize the file in any way you see fit. Few other tools manage to compete with the flexibility of a plain text buffer.</p>
<p>This post only scratches the surface of Org-mode. To get a sense of the possibilities, the <a href="http://orgmode.org/org.pdf">manual</a> amounts to 184 pages. However, for a quick introduction I encourage you to watch the <a href="http://orgmode.org/GoogleTech.html">Google Tech Talk on Org-mode</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2009/11/05/getting-organized-with-emacs-org-mode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Becoming aware of and minimizing distractions</title>
		<link>http://www.bugfree.dk/blog/2009/07/27/becoming-aware-of-and-minimizing-distractions/</link>
		<comments>http://www.bugfree.dk/blog/2009/07/27/becoming-aware-of-and-minimizing-distractions/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 20:14:31 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/?p=295</guid>
		<description><![CDATA[Spending a great deal of time in front of my computer, I often get carried away by instant messaging, mail, RSS, Twitter, Facebook, etc. For the most part, these activities aren&#8217;t the reason I turned on the computer. Nevertheless they end up being where a lot of time is spent. Like with any habit, every [...]]]></description>
			<content:encoded><![CDATA[<p>Spending a great deal of time in front of my computer, I often get carried away by instant messaging, mail, RSS, Twitter, Facebook, etc. For the most part, these activities aren&#8217;t the reason I turned on the computer. Nevertheless they end up being where a lot of time is spent.
</p>
<p>Like with any habit, every so often you should take the time to review it. I find <a href="http://timesnapper.com/">TimeSnapper</a> (the free edition) to be an invaluable tool for reviewing computer habits. It captures an image of the desktop every few seconds and is able to create a movie from the images. That way, a partial <a href="http://en.wikipedia.org/wiki/Lifelog">life log</a> (mine is currently 393 days) is automatically created to help you remember what you did yesterday and the day before.
</p>
<p>There&#8217;s nothing like reviewing a few of weeks of captured images to make habits stand out. I found that I&#8217;ve a tendency to re-visit the same maybe ten sites all too often. I also have difficulty single-tasking. Listening to a podcast or watching a movie, I&#8217;m often browsing the web instead of paying attention to the podcast or skipping it altogether. I may even have several media players launched at once, although only one playing.
</p>
<p>Most of my distractions can be attributed to me always being online. I need Internet access for work, so turning it off altogether isn&#8217;t an alternative. So, not unlike <a href="http://www.paulgraham.com">Paul Graham</a>, on several occasions, I&#8217;ve made myself adhere to a set of rules for using the Internet. And every time they&#8217;ve worked &#8212; for a short while.
</p>
<p>In <a href="http://www.paulgraham.com/distraction.html">Disconnecting Distraction</a>, Paul takes these rules one step further and argues that using two computers may be a better solution: one computer with Internet access and one without for doing real work. Ideally, the computers should be placed some distance apart to make you psychically get up to go on the Internet.
</p>
<p>For a week I&#8217;ve given the two-computer approach a try. It was hard initially, but I&#8217;ve come to appreciate it. Forming permanent habits takes time. Thus, I&#8217;ll continue the experiment for a couple of weeks. Perhaps in time I&#8217;ll even learn to turn off instant messaging and only do mail once or twice a day. Or I may end up spending most of the time in front of the connected computer.
</p>
<p>Then again, there&#8217;s more to life than work.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2009/07/27/becoming-aware-of-and-minimizing-distractions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototyping LINQ using LINQPad</title>
		<link>http://www.bugfree.dk/blog/2008/06/29/prototyping-linq-using-linqpad/</link>
		<comments>http://www.bugfree.dk/blog/2008/06/29/prototyping-linq-using-linqpad/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 12:44:00 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2008/06/29/prototyping-linq-using-linqpad/</guid>
		<description><![CDATA[I&#8217;ve been doing some LINQ development lately. What I typically do is write a LINQ query within the production code and then attach a debugger to see what the query returns and perhaps what the underlying SQL statement looks like. For simple queries this technique is sufficient, but for more complex ones, several, cumbersome round-trips [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some LINQ development lately. What I typically do is write a LINQ query within the production code and then attach a debugger to see what the query returns and perhaps what the underlying SQL statement looks like. For simple queries this technique is sufficient, but for more complex ones, several, cumbersome round-trips through the debugger are often necessary to get the query right.
</p>
<p>Researching the issue I came across <a href="http://www.linqpad.net">LINQPad</a> (<a href="http://www.dimecasts.net/Casts/CastFeedDetails/22">see</a> LINQPad <a href="http://www.dimecasts.net/Casts/CastDetails/6">in</a> <a href="http://oreilly.com/pub/e/909">action</a>). The tool is a generic testbed for molding expressions or statements (LINQ being one such class) before embedding them into code. Also, because LINQPad is written by one of the authors of <a href="http://www.amazon.com/gp/product/0596527578?ie=UTF8&amp;tag=cinanu-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596527578">C# in a Nutshell</a>, the tool comes with a lot of samples from the book.
</p>
<p><a href="http://www.bugfree.dk/blog/wp-content/uploads/2008/06/LINQPadExample.png" target="_blank"><img src="http://www.bugfree.dk/blog/wp-content/uploads/2008/06/LINQPadExample.png" alt=""/></a>
</p>
<p>On the implementation side, LINQPad works by emitting MSIL behind the scenes, conceptually similar to the DataContext classes generated by Visual Studio when using the database design surface.</p>
<p>As an interesting side note, LINQPad can also show the query after it has been transformed into lambdas, anonymous types, and the like:
</p>
<pre class="prettyprint lang-cs">
   Users
      .Join (
         Macs,
         u => u.UserId,
         m => m.UserId,
         (u, m) =>
            new
            {
               u = u,
               m = m
            }
      )
      .Where (temp0 => (temp0.u.Created < DateTime.Now.AddHours (-24)))
      .Select (
         temp0 =>
            new
            {
               UserId = temp0.u.UserId,
               UserCreated = temp0.u.Created,
               Mac = temp0.m.Mac,
               Active = temp0.m.Active
            }
      )
      .Take (15)
</pre>
<p>Keep in mind how the .Net 3.5 framework and the .Net 3.5 compiler play together to ultimately transform the LINQ query into MSIL. What the framework does is transform the LINQ query into the above expression by applying a transform to the abstract syntax tree of the LINQ query. The .Net 3.5 compiler then transforms the lambdas, the anonymous types, and the like into .Net 2.0 MSIL (there&#8217;s no such thing as a .Net 3.5 CLR. For an overview of how the various versions of the framework, the compiler, and the CLR relate to each other, see Scott Hanselman&#8217;s <a href="http://www.hanselman.com/blog/HowToSetAnIISApplicationOrAppPoolToUseASPNET35RatherThan20.aspx">blog entry</a>).</p>
<p>But back to LINQPad. The only downside that I&#8217;ve encountered is that there&#8217;s no IntelliSense support in the current 1.24 release. However, even without IntelliSense support LINQPad is still a very valuable tool.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2008/06/29/prototyping-linq-using-linqpad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Purging inactive users from e107</title>
		<link>http://www.bugfree.dk/blog/2007/10/29/purging-inactive-users-from-e107/</link>
		<comments>http://www.bugfree.dk/blog/2007/10/29/purging-inactive-users-from-e107/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 21:35:02 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2007/10/29/purging-inactive-users-from-e107/</guid>
		<description><![CDATA[Download E107InactiveUserPurger-1.0.zip. As part of my use of the e107 open source contents management system, I want to purge the user accounts that’ve not logged in recently. This is something not supported out of the box, but by going through MySQL and accessing the e107_user table directly, the date of last login is accessible to [...]]]></description>
			<content:encoded><![CDATA[<p>Download <a href="/software/E107InactiveUserPurger-1.0.zip">E107InactiveUserPurger-1.0.zip</a>.</p>
<p>As part of my use of the <a href="http://e107.org/news.php">e107</a> open source contents management system, I want to purge the user accounts that’ve not logged in recently. This is something not supported out of the box, but by going through MySQL and accessing the e107_user table directly, the date of last login is accessible to anyone.</p>
<p>I’ve therefore written a small command-line tool in C# that makes use of the e107_user information to sent inactive users a warning email that their accounts are about to be purged (or whatever you want to happen).</p>
<p>The tool may be run in one of two modes, determined by a command-line switch.<br />
</p>
<ul>
<li>GenerateWarningMails: emails users that have not logged in during the last WarningPeriod days.</li>
<li>GeneratePurgeMailForAdministrator: emails site administrator a list of users that have not logged in during the last PurgePeriod days.</li>
</ul>
<p>Before running E107InactiveUserPurger, make sure to go to the Debug directory and adjust the settings in E107InactiveUserPurger.exe.xml to match your environment. You might also want to adjust the WarningMailTemplate.txt, which serves as a template for generating the body of warning emails. </p>
<p>Note that within the WarningMailTemplate.txt file, you&#8217;re free to add placeholders for fields within the e107_user table. Thus, if you want to include the login name of a user within the warning email, you’d write $user_loginname$.</p>
<p>Now you might run E107InactiveUserPurger as a scheduled task. Keep in mind, though, that the tool doesn’t actually purge the user accounts. Therefore, running it too often with the GenerateWarningMails switch may result in users receiving more than one warning email.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2007/10/29/purging-inactive-users-from-e107/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Alerts</title>
		<link>http://www.bugfree.dk/blog/2007/05/25/google-alerts/</link>
		<comments>http://www.bugfree.dk/blog/2007/05/25/google-alerts/#comments</comments>
		<pubDate>Fri, 25 May 2007 09:09:27 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2007/05/25/google-alerts/</guid>
		<description><![CDATA[I just learned about Google Alerts. It&#8217;s a simple service where you enter keywords for Google to search. Then Google will monitor the search results and send you an email whenever new hits appear in the search result. Time will tell if it&#8217;s truly useful to have your own personal intelligence service at your hands. [...]]]></description>
			<content:encoded><![CDATA[<p>I just learned about <a href="http://www.google.com/alerts">Google Alerts</a>.</p>
<p>It&#8217;s a simple service where you enter keywords for Google to search. Then Google will monitor the search results and send you an email whenever new hits appear in the search result.</p>
<p>Time will tell if it&#8217;s truly useful to have your own personal intelligence service at your hands. So far I receive alerts about the company I work for, the region where I live, myself, and so on.</p>
<p><b>Update, May 29</b>: In my experience there are too many ads at the top of each email I receive. Also, Google sends me a daily email for each alert even though there are no new search results. </p>
<p>Thus,  bulking alerts would be a nice option. Or perhaps you could write something better by coding against the <a href="http://code.google.com/">Google APIs</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2007/05/25/google-alerts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The su of Windows</title>
		<link>http://www.bugfree.dk/blog/2007/02/25/the-su-of-windows/</link>
		<comments>http://www.bugfree.dk/blog/2007/02/25/the-su-of-windows/#comments</comments>
		<pubDate>Sun, 25 Feb 2007 09:58:11 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2007/02/25/the-su-of-windows/</guid>
		<description><![CDATA[On Linux based system, it&#8217;s a common idiom to impersonate the root user whenever you have to perform a privileged operation. This is typically accomplished using the su command, which, although used less frequently, has a Windows equivalent, called runat.exe. runat.exe turned out to be quite useful when I had to do some work with [...]]]></description>
			<content:encoded><![CDATA[<p>On Linux based system, it&#8217;s a common idiom to impersonate the root user whenever you have to perform a privileged operation. This is typically accomplished using the <code>su</code> command, which, although used less frequently, has a Windows equivalent, called <code>runat.exe</code>. </p>
<p><code>runat.exe</code> turned out to be quite useful when I had to do some work with MS SQL 2005 Server, Analysis Service. The thing with Analysis Service is that it&#8217;s <a href="http://msdn2.microsoft.com/en-us/library/ms144288.aspx">Windows authentication only</a>, whereas MS SQL 2005 Server supports <a href="http://msdn2.microsoft.com/en-us/library/ms144284.aspx">mixed mode authentication</a>.</p>
<p>My only option for getting in touch with Analysis Service was using SQL Server Management Studio by impersonating an existing Windows user, who is allowed access to Analysis Service (I didn&#8217;t have the option of creating a new account on the machine running Analysis Service and the machine wasn&#8217;t allowed to trust the domain my desktop computer was on (it&#8217;s a tough world out there)).</p>
<p>So, using <code>runat.exe</code>, I ran the command below (on one line, from a shortcut), in effect causing the display of a prompt asking for the password for my_impersonated_user. Upon entering the password <code>sqlwb.exe</code> starts up as if it was run from the local my_impersonated_user account. </p>
<pre>
C:\\Windows\\System32\\runas.exe /user:my_impersonated_user
"c:\\Program Files\\Microsoft SQL Server\\90\\Tools\\
Binn\\VSShell\\Common7\\IDE\\sqlwb.exe"
</pre>
<p>For the command to succeed my_impersonated_user have to be a user on the local machine with a username and password identical to the user that is allowed access to MS SQL 2005 Server/Analysis service. </p>
<p>Now Windows lets you logon to Analysis Service even if your local machine is on a different domain than the MS SQL 2005 Server.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2007/02/25/the-su-of-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text files vs. personal wiki</title>
		<link>http://www.bugfree.dk/blog/2006/12/04/text-files-vs-personal-wiki/</link>
		<comments>http://www.bugfree.dk/blog/2006/12/04/text-files-vs-personal-wiki/#comments</comments>
		<pubDate>Sun, 03 Dec 2006 22:18:59 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/12/04/text-files-vs-personal-wiki/</guid>
		<description><![CDATA[I have quite a few small text files lying around, containing everything from to-do lists to shopping lists to code snippets to small howto&#8217;s. Now, instead of having all those text files floating around as regular files, nine months ago I decided to move them into a locally stored, for security reasons, personal wiki. Among [...]]]></description>
			<content:encoded><![CDATA[<p>I have quite a few small text files lying around, containing everything from to-do lists to shopping lists to code snippets to small howto&#8217;s. Now, instead of having all those text files floating around as regular files, nine months ago I decided to move them into a locally stored, for security reasons, personal wiki.</p>
<p>Among the good wiki engines out there (most notably <a href="http://www.mediawiki.org/wiki/MediaWiki">MediaWiki</a>, <a href="http://moinmoin.wikiwikiweb.de">MoinMoin</a>, and <a href="http://www.flexwiki.com">FlexWiki</a>), I went with FlexWiki, because it being asp.net based means that all the software required for a basic configuration ships with Windows. In addition, FlexWiki&#8217;s provider-based storage model lets you store pages in an MS SQL server, if you want to. </p>
<p>My incentive for going the wiki way was that I expected my documents to become more structured when making use of the typical wiki-like features &#8230;</p>
<ul>
<li>Documents are automatically linked together.<br />
I found my pages to be fairly independent, so hyperlinks are almost never present.</li>
<li>All modifications are recoded.<br />
Versioning isn&#8217;t really that big an issue, because I usually add contents to the end of a page rather than changing existing contents, and for pages such as a shopping list, I don&#8217;t really need versioning.</li>
<li>More sophisticating layout capabilities.<br />
Although I occasionally created a table and used colors, generally I can do with simple formatting. For those few cases where I can&#8217;t, a Word document is in place, since it’s equally well indexed by MS or Google desktop search engines.</li>
</ul>
<p>&#8230; but most of the time, I didn&#8217;t make use of the features FlexWiki provided over text files. So, if you also factor in the disadvantages &#8230;</p>
<ul>
<li>Extra infrastructure required.<br />
Web server, and possibly an SQL server, is a must-have-installed. Also, you probably need to figure out how to configure the web server so you don&#8217;t share your live with the world.</li>
<li>Browser required for page edit.<br />
After launching the browser, you must navigate to the wiki page, which may add considerable overhead for quick edits as opposed to simply double clicking a text file from within Explorer.</li>
<li>Lacking WYSIWYG support.<br />
With FlexWiki, editing a page is a two-step process. First you write content in a markup language. Then you click &#8220;Save&#8221; and the browser switches to display view, where your markup is converted to html. Now, if the result is not what you expected, you have to repeat the cycle.</li>
<li>Build-in search less powerful than desktop search engines.<br />
If you use the file system for storing wiki pages then the pages are also searchable by desktop search engines. However, if you opt for MS SQL storage, you have to rely on the build-in search capabilities of the wiki to find pages.</li>
<li>Backup is more involved.<br />
Backing up and restoring a database is more complicated than copying a directory.</li>
</ul>
<p>&#8230; I&#8217;ve decided that the wiki doesn&#8217;t cut it for me: simply because there is less overhead associated with editing text or even Word documents and because with desktop search engines I retain most of the properties I need.</p>
<p>This doesn&#8217;t mean that a wikis aren&#8217;t suited for maintaining a corpus of personal information; just that the corpus should serve a different purpose to make better use of wiki features.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/12/04/text-files-vs-personal-wiki/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CruiseControl.net and build queues</title>
		<link>http://www.bugfree.dk/blog/2006/11/19/cruisecontrolnet-and-build-queues/</link>
		<comments>http://www.bugfree.dk/blog/2006/11/19/cruisecontrolnet-and-build-queues/#comments</comments>
		<pubDate>Sun, 19 Nov 2006 09:07:10 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/11/19/build-queues-with-cruisecontrolnet/</guid>
		<description><![CDATA[(I&#8217;ve created a Download page for the tool described in this post, with a short description of prerequisites and how to install it.) For team development a way is needed to ensure that team members doesn&#8217;t inadvertently break the shared code, e.g., a developer forgets to commit all files related to a change, which is [...]]]></description>
			<content:encoded><![CDATA[<p>(I&#8217;ve created a <a href="http://www.bugfree.dk/blog/software/ccnetserializer/">Download</a> page for the tool described in this post, with a short description of prerequisites and how to install it.)</p>
<p>For team development a way is needed to ensure that team members doesn&#8217;t inadvertently break the shared code, e.g., a developer forgets to commit all files related to a change, which is something not easily fixable by other developers.</p>
<p>Also, the team might want to run post-compile tasks, such as unit tests, on a dedicated machine to avoid the works-on-my-machine syndrome.</p>
<p>Ideally, the project’s code should always go from one stable state to another so that a developer doesn’t get broken code the next time he synchronizes with source control. </p>
<p>One way to achieve this is by means of <a href="http://www.martinfowler.com/articles/continuousIntegration.html">continuous integration</a> of changes into the code. Either by rolling your own build script that monitors source control for changes to trigger a build and inform developers of the result or by leveraging an existing continuous integration solution, such as <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET">CruiseControl.net</a> (ccnet): a continuous integration server, an asp.net based front-end, and a desktop client.</p>
<p>Although CruiseControl (both the Java and .Net incarnation) appears to be a popular choice among developers, I find it somewhat immature: it violates the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">dry principle</a> in its projects configuration file and, worst of all, it doesn&#8217;t support build queues to ensure that only one of several projects are actually building at once. </p>
<p>It&#8217;s not a problem for ccnet itself to perform parallel continuous integration. However, the build chain is no stronger than the weakest link, which in my case is devenv.exe, the Visual Studio executable used by ccnet to build the application (by running devenv.exe from the command line with a couple of arguments, you can leverage the build system within Visual Studio from a script). </p>
<p>The downside to using devenv.exe, however, is that all running instances share a temporary build folder for compiler output. Thus, when ccnet does continuous integration of branches in parallel, the instances of devenv.exe spawned by ccnet compete for write access to identically named files, namely the executables generated by the compiler.</p>
<p>Not surprisingly, this results in build failures for one or more ccnet projects, although there is nothing wrong with the code. </p>
<p>In my experience from the trenches this happens too often to be ignored for any serious use of ccnet: It&#8217;s just too common for a developer to cross-commit a bugfix to several branches or for independent developers to commit to their working branches in between when ccnet checks the branch for updates. </p>
<p>Having these false negatives make the team members not trust ccnet and not take proper action whenever they see a build failure, thus rendering continuous integration useless.</p>
<p>One solution to the above file locking problem is to serialize the builds manually by building branches at predefined intervals, thus interleaving the builds so that they shouldn&#8217;t be able to overlap. As a result the developer may have to wait a fair amount of time to be sure his latest commit doesn&#8217;t breaks anything. Also, if a build has not finished when the next is scheduled to start, it may cause a cascade of broken builds to occur until the interleaving is properly realigned. </p>
<p>Another solution is to head over to <a href="http://jayflowers.com/WordPress/?p=72">Jay Flowers</a>. He has branched off the official 1.0 version of ccnet and created a ccnet that allows for a lot more constraints than just serializing builds. It happens at the expense of running the non-official, not-recent version of ccnet, though.</p>
<p>My solution to the parallel build problem was to write a front-end for ccnet that implements build queues without the knowledge of ccnet, i.e., by means of checking for changes on a configurable number of branches. If a change is detected, the branch is enqueued. Then when all branches are checked, the tool force builds each branch, monitoring the state of the ccnet server to ensure that only one branch is building at a time. </p>
<p>With this solution you integrate the nice features of ccnet, such as the nice webgui for displaying what went wrong with a build and the systray application that goes green, yellow, or red depending on the state of your builds, with rapid feedback in a way that is compatible with Visual Studio&#8217;s integrated build engine.</p>
<p>The biggest downside, however, is that you can no longer see the changes that triggered a build from the web gui as ccnet is no longer in charge of cvs operations.</p>
<p>The tool is roughly 100 lines of <a href=”http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython”>IronPython</a> code and works by spawning cvs.exe, synchronizing a number of working copies with the cvs repository, and in the process  monitors the output of cvs.exe for changes, additions, and removals of files to the working copies. </p>
<p>The state of CruiseControl is determined by screen scraping the webgui and builds are forced by simulating a click on the &#8220;build&#8221; button for the ccnet project in the webgui for which a change was detected.</p>
<p>The url of the ccnet webgui, the path to the cvs.exe, and mappings between the path on disk where each working copy resides and the corresponding name of the ccnet project are stored in the tools configuration file, which is itself Python code loaded into the tool on startup. </p>
<p>Using Python as a language for your configuration file, you don’t have to invent your own language or use verbose xml, which requires you to write code for parsing it.</p>
<p>PS: I recently stumbled across the <a href="http://ccnetplugins.sourceforge.net/">Sequential Task Plug In</a> that I want to try out sometime.</p>
<p><b>Update, April 16</b>: It has come to my attention that there is a way to minimize duplication in the configuration file. It involves &#8220;&#8230; users to set up DTD entities within the CCNet configuration&#8221; as mentionen <a href="http://dotnetjunkies.com/WebLog/exortech/archive/2007/04/15/225924.aspx">here</a>. I haven&#8217;t tried it, though.</p>
<p><b>Update, August 10</b>: CruiseControl.net 1.3 now comes with a build-in queue feature.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/11/19/cruisecontrolnet-and-build-queues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CVS merge bit me</title>
		<link>http://www.bugfree.dk/blog/2006/09/24/cvs-merge-bid-me/</link>
		<comments>http://www.bugfree.dk/blog/2006/09/24/cvs-merge-bid-me/#comments</comments>
		<pubDate>Sun, 24 Sep 2006 09:42:48 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/09/24/cvs-merge-bid-me/</guid>
		<description><![CDATA[I&#8217;m currently managing the merge operations for a CVS repository with a branch layout looking partly as follows: At some point in the past HEAD branched into B1, which subsequently branched into B1.1. Then development on B1 completed and it was merged back into HEAD so a release branch B2 could be created. B1.1, however, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently managing the merge operations for a CVS repository with a branch layout looking partly as follows:</p>
<p><img id="image15" height=140 alt=cvs_merge.GIF src="http://www.bugfree.dk/blog/wp-content/uploads/2006/09/cvs_merge.GIF" /></p>
<p>At some point in the past HEAD branched into B1, which subsequently branched into B1.1. Then development on B1 completed and it was merged back into HEAD so a release branch B2 could be created. B1.1, however, kept living its separate life for a while, because the features added aren&#8217;t to be released until with release branch B5. This also goes for the changes made to B3, so it makes sense for B1.1 to be merged into B3.</p>
<p>As a result, I just spend a few hours on tracking down a merge issue resulting from this merge, because a change made in B1 wasn&#8217;t present in B3 after B1.1 was merged into this branch. I finally figured out why: suppose a line is removed in B1 before the spin-off of B1.1. After that the very same line is added back in. Now when B1.1 is merged into B3, the line is removed again. There is no merge conflict at this point, because from CVS&#8217; point of view it&#8217;s a clean merge.</p>
<p>It seems obvious what happened when looking at the diagram, but when you&#8217;re working with a large repository with lots of modified files and you&#8217;re merging code not written by yourself, this sort of indirect change propagation may inevitably bite you as well.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/09/24/cvs-merge-bid-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powertools from SysInternals</title>
		<link>http://www.bugfree.dk/blog/2006/09/17/powertools-from-sysinternals/</link>
		<comments>http://www.bugfree.dk/blog/2006/09/17/powertools-from-sysinternals/#comments</comments>
		<pubDate>Sun, 17 Sep 2006 13:26:57 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/09/17/powertools-from-sysinternals/</guid>
		<description><![CDATA[I use the SysInternals tools (now acquired by the Empire). The ones I use most often are: PageDefrag PageDefrag uses advanced techniques to provide you what commercial defragmenters cannot: the ability for you to see how fragmented your page file and Registry hives are, and to defragment them. In addition, it defragments event log files [...]]]></description>
			<content:encoded><![CDATA[<p>I use the <a href="http://www.sysinternals.com/">SysInternals</a> tools (now acquired by the <a href="http://microsoft.com">Empire</a>). The ones I use most often are:</p>
<ul>
<li><a href="http://www.sysinternals.com/utilities/pagedefrag.html">PageDefrag</a><br />
<blockquote><p>
PageDefrag uses advanced techniques to provide you what commercial defragmenters cannot: the ability for you to see how fragmented your page file and Registry hives are, and to defragment them. In addition, it defragments event log files and Windows 2000/XP hibernation files [...].
</p></blockquote>
<p>Has the ability to run at the next or every boot (that&#8217;s how it gets exclusive access to the system files).  Running it every time I boot typically adds 10-20 seconds to my boot time, but I guess it depends on how often you boot, the amount of physical memory, and what kind of applications you run.</p>
<li><a href="http://www.sysinternals.com/utilities/contig.html">Contig</a><br />
<blockquote><p>
Contig is a single-file defragmenter that attempts to make files contiguous on disk. It’s perfect for quickly optimizing files that are continuously becoming fragmented, or that you want to ensure are in as few fragments as possible.
</p></blockquote>
<p>Also has a recursive switch, so you can specify C:\ as the starting point and it&#8217;ll defragment its way through your entire drive.</p>
<li><a href="http://www.sysinternals.com/utilities/shareenum.html">ShareEnum</a><br />
<blockquote><p>
When you run ShareEnum it uses NetBIOS enumeration to scan all the computers within the domains accessible to it, showing file and print shares and their security settings.
</p></blockquote>
<p>A worthy replacement for Network Neighborhood, although it sometimes is not able to find any shares, although I know there&#8217;s quite a few out there. </p>
<li><a href="http://www.sysinternals.com/utilities/autoruns.html">Autoruns</a><br />
<blockquote><p>
This utility, which has the most comprehensive knowledge of auto-starting locations of any startup monitor, shows you what programs are configured to run during system boot or login, and shows you the entries in the order Windows processes them. These programs include ones in your startup folder, Run, RunOnce, and other Registry keys.
</p></blockquote>
<p>On my computer, it takes longer for Windows to become responsive after log on than it takes Windows to boot and display the log on screen, because Windows loads a ton of software, fills up the systray, and starts various services I really don&#8217;t need. </p>
<p>Services such as Remote Registry for accessing the registry across the network, Windows Image Acquisition for popping up a dialog box when I scan an image on the scanner I don&#8217;t have, or Windows Zero Configuration for managing the WLAN access I never use. </p>
<p>Those services are all on by default and can be disabled using AutoRuns (or using Control panel => Administrative tools => Services).</p>
<li><a href="http://www.sysinternals.com/utilities/processexplorer.html">Process Explorer</a><br />
<blockquote><p>
The Process Explorer display consists of two sub-windows. The top window always shows a list of the currently active processes, including the names of their owning accounts, whereas the information displayed in the bottom window depends on the mode that Process Explorer is in: if it is in handle mode you&#8217;ll see the handles that the process selected in the top window has opened; if Process Explorer is in DLL mode you&#8217;ll see the DLLs and memory-mapped files that the process has loaded. Process Explorer also has a powerful search capability that will quickly show you which processes have particular handles opened or DLLs loaded.
</p></blockquote>
<p>The quote speaks for itself.
</ul>
<p>There&#8217;s a lot more tools where these came from. Among the ones I use less frequently are FileMon and Regmon for real-time monitoring of file system and registry access, respectively. Also, I use TCPView as a more user friendly replacement for the netstat command.</p>
<p>Finally, take a look at <a href="http://www.dnrtv.com/default.aspx?showID=35">dnrTV</a>, where <a href="http://www.hanselman.com/blog/">Scott Hanselman</a> recently showed off some of these tools.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/09/17/powertools-from-sysinternals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Query transform with MSSQL server</title>
		<link>http://www.bugfree.dk/blog/2006/09/15/query-transformation-with-mssql-server/</link>
		<comments>http://www.bugfree.dk/blog/2006/09/15/query-transformation-with-mssql-server/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 19:55:12 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/09/15/query-transformation-with-mssql-server/</guid>
		<description><![CDATA[Ever found yourself struggling with a big chuck of embedded SQL failing on you? Oftentimes because of a trivial, but hard to spot, syntax (or semantic) error introduced as part of your dynamic query composition process. Typically, you&#8217;d target your frustration at the debugger and insert a breakpoint around the problematic part of your code [...]]]></description>
			<content:encoded><![CDATA[<p>Ever found yourself struggling with a big chuck of embedded SQL failing on you? Oftentimes because of a trivial, but hard to spot, syntax (or semantic) error introduced as part of your dynamic query composition process.</p>
<p>Typically, you&#8217;d target your frustration at the debugger and insert a breakpoint around the problematic part of your code to extract the SQL and copy it into the Query Analyzer for investigation.</p>
<p>Unfortunately, pasting the SQL into Query Analyzer causes the statement to appear on one line entirely. You then find yourself inserting new line characters for readability and for making the error message more precise.</p>
<p>Transforming SQL this way is tedious, boring, and crying for automation. Fortunately, Enterprise Manager responds well to these cries. Just drill down to a table view of your database, right click on a table, and select &#8220;Open table&#8221; followed by &#8220;Query&#8221;.</p>
<p>Now paste your extracted SQL into the text portion of the Query by Example window and hit &#8220;Run&#8221;. Although the query might not actually execute, it&#8217;s transformed into a more readable one. </p>
<p>Obviously, you could start and stay in the QBE window. Personally, though, I dislike QBE as a working environtment beyond for layout beautification, so I usually copy the transformed query into Query Analyzer.</p>
<p>By the way, the transform also comes in handy if you want to make sure your query doesn&#8217;t contain any camouflaged expensive joins, e.g., for a query with inner joins done using where clauses, QBE transforms it into explicit inner joins.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/09/15/query-transformation-with-mssql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Vista RC1 rocks</title>
		<link>http://www.bugfree.dk/blog/2006/09/12/windows-vista-rc1-rocks/</link>
		<comments>http://www.bugfree.dk/blog/2006/09/12/windows-vista-rc1-rocks/#comments</comments>
		<pubDate>Tue, 12 Sep 2006 18:52:11 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[Tip]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/2006/09/12/windows-vista-rc1-rocks/</guid>
		<description><![CDATA[I&#8217;ve been playing around with different setups of Windows Vista RC1 the last couple of days. Just getting Vista to install was an challenge in itself as RC1 refuses to install on VMWare Workstation. It stalls at &#8220;Windows is loading files &#8230;&#8221;. Apparently the subsequent switch into graphics mode causes Vista to hang, because Vista [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with different setups of <a href="http://www.microsoft.com/Windowsvista">Windows Vista</a> RC1 the last couple of days. Just getting Vista to install was an challenge in itself as RC1 refuses to install on VMWare Workstation.</p>
<p>It stalls at &#8220;Windows is loading files &#8230;&#8221;. Apparently the subsequent switch into graphics mode causes Vista to hang, because Vista all the sudden doesn&#8217;t properly support the emulated video hardware of VMWare.</p>
<p>That&#8217;s odd, because I previously installed Beta 2 on VMWare without any sign of trouble (could it be that MS wants people to try out RC1 on their <a href="http://www.microsoft.com/Windows/virtualpc/default.mspx">free</a> Virtual PC? By the way, <a href="http://www.vmware.com/products/server/">VMWare Server</a> is free too).</p>
<p>Luckily, <a href="http://www.joelonsoftware.com/">Joel on Software</a>&nbsp;provides a <a href="http://www.joelonsoftware.com/items/2006/09/08b.html">solution</a>&nbsp;to the VMWare issue, by adding</p>
<pre class="prettyprint lang-cs">
    svga.maxWidth = "640"
    svga.maxHeight = "480"
</pre>
<p>to the configuration file for your virtual machine prior to booting the Vista DVD. It&#8217;ll force the installer to run in SVGA mode. Then when the installation is complete and you&#8217;ve installed the VMWare tools, remove the above lines and Vista shines.</p>
<p>My intention was to run Vista in VMWare on a secondary computer and connect to it via Remote Desktop. For some yet to be uncovered reason, however, I wasn&#8217;t able to connect from my WinXP machine. Perhaps the host OS&nbsp;blocked the incoming request or perhaps Vista just wasn&#8217;t properly configured. </p>
<p>Anyway, I decided to run Vista on the bare hardware instead, so I fired up PartitionMagic. Unfortunately some guy accidentally cut power while PartitionMagic was doing its shrink-existing-partition-to-create-space-for-an-additional-one magic. After that the existing OS chickened out and bluescreened on me, so out everything went and in Vista came.</p>
<p>Thus, now I utilize a two-monitor setup, running Vista on a native 2.6GHz&nbsp;processor&nbsp;with 2GB of memory on one monitor and WinXP on the other. Unfortunately, the Vista machine has a crappy video card, so no fancy, transparent UI for me (unless I find a workaround). </p>
<p>As a final note, I&#8217;m using <a href="http://synergy2.sourceforge.net/">Synergy</a>&nbsp;to seamlessly share one mouse and keyboard between the physical machines as if it was one machine with dual head video output.</p>
<p>Way cool!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/09/12/windows-vista-rc1-rocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Being a functional Pythonian</title>
		<link>http://www.bugfree.dk/blog/2006/01/04/being-a-functional-pythonian/</link>
		<comments>http://www.bugfree.dk/blog/2006/01/04/being-a-functional-pythonian/#comments</comments>
		<pubDate>Wed, 04 Jan 2006 19:43:00 +0000</pubDate>
		<dc:creator>Ronnie Holm</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Tool]]></category>

		<guid isPermaLink="false">http://www.bugfree.dk/blog/?p=6</guid>
		<description><![CDATA[In my first blog post, I&#8217;ll give an example of how functional programming (FP) in Python results in shorter, cleaner, and more concise code, compared to the equivalent in an imperative language like C#. I&#8217;ll use a real-world build tool I&#8217;ve written as the driving example. Typical tasks for such a tool would include, but [...]]]></description>
			<content:encoded><![CDATA[<p>In my first blog post, I&#8217;ll give an example of how <a href="http://gnosis.cx/publish/programming/charming_python_13.html">functional programming (FP) in Python</a> results in shorter, cleaner, and more concise code, compared to the equivalent in an imperative language like C#.</p>
<p>I&#8217;ll use a real-world build tool I&#8217;ve written as the driving example. Typical tasks for such a tool would include, but not be limited to, checking out sources from cvs, compiling the sources, and running NUnit against a number of generated targets.</p>
<p>Each such task may be defined as a function, taking any number of arguments and returning a list of the form:</p>
<pre>[status, [(command, output), (...)]]</pre>
<p>where status indicates binary success, command is the command run to complete the task and output is the output (stdout/stderr) of running the command. There may be more than one (command, output) tuple inside the sublist, if the task requires more than one command to complete.</p>
<p>In FP the <a href="http://python.org/doc/2.4.2/tut/node7.html#SECTION007100000000000000000">list</a> and <a href="http://python.org/doc/2.4.2/tut/node7.html#SECTION007300000000000000000">tuple</a> are fundamental and very powerful concepts, because they can easily be used to define complex structures for you to use when passing data around. They also facilitate easy processing using <a href="http://python.org/doc/2.4.2/tut/node7.html#SECTION007140000000000000000">list comprehension</a>, the functions build <a href="http://python.org/doc/2.4.2/tut/node7.html#SECTION007130000000000000000">into</a> the language, or functions of your own, providing elegant syntax for common operations, such as insertion, deletion, searching, slicing, etc.</p>
<p>These lists and tuples are more dynamic in nature than their array and struct counterparts in, say, C#. In fact, rather than creating user defined types, a list, or a tuple, or a combination often suffices, eliminating the need to write a lot of boilerplate code.</p>
<p>Now, to provide an example where Python&#8217;s FP support really kicks in with the build tool, is in the implementation of the code responsible for running NUnit against a number of targets:</p>
<pre>
<font color="#a020f0">def</font> <font color="#0000ff">NUnit</font>(nunitconsole, projectsOrAssemblies):
    results = [Run(<font color="#bc8f8f">"\""</font> + nunitconsole + <font color="#bc8f8f">"\" "</font> + source)
              <font color="#a020f0">for</font> source <font color="#a020f0">in</font> projectsOrAssemblies]
    commands = [command[1][0] <font color="#a020f0">for</font> command <font color="#a020f0">in</font> results]
    outputs = [output[1][1] <font color="#a020f0">for</font> output <font color="#a020f0">in</font> results]
    failures = Sigma(re.findall(<font color="#bc8f8f">"Failures: (\d+)"</font>, <font color="#a020f0">str</font>(outputs)))
    <font color="#a020f0">return</font> [<font color="#a020f0">not</font> <font color="#a020f0">bool</font>(int(failures)), <font color="#a020f0">zip</font>(commands, outputs)]
</pre>
<p>This function relies heavily on the use of lists and list comprehension, rather than imperative style loops (which, of course, is also possible in Python). List comprehension is a construct that allows you to easily create a new list as a result of some processing on the elements of another.</p>
<p>A highlevel walk-through of the function: first the NUnit executable is invoked one target at a time. The Run function itself returns a list of the form [exitcode, (command, output)]; hence with n targets to test, the commands and outputs variables end up containing n commands and their output. The Failures variable counts the total number of failures accumulated across all targets, extracted as a list of strings matching the regular expression and summarized by the Sigma function.</p>
<p>Python doesn&#8217;t allow summing over a list of strings using its build-in Sum function. However, you can easily implement a Sum function that does in something along the lines of:</p>
<pre>
<font color="#a020f0">def</font> <font color="#0000ff">Sigma</font>(list):
    <font color="#a020f0">return</font> <font color="#a020f0">reduce</font>(<font color="#a020f0">lambda</font> a, b: <font color="#a020f0">int</font>(a) + <font color="#a020f0">int</font>(b), list)
</pre>
<p>where reduce is a function present in most, if not all, FP languages, which reduces a list of values to a single value by applying a user-defined operation to pairwise values of the list.</p>
<p>Finally, the zip function is a build-in function, merging the elements of two lists into one.</p>
<p>Another important construct in FP is the lambda notation. It enables you to create an anonymous function, a function without an explicitly name, leading us to another key characteristic of FP: functions are treated as first-class citizens, in the sense that they may be passed around as just another variable, e.g., you can create a list of functions with parameters and then do the actual invocation at a later stage.</p>
<p>Using deferred invocation, the build tool manages the overall build process; in a config file, similar to a makefile, a list of lambdas are defined, each defining a function that executes a task. This provides us with a generic way of annotating a task and for each task to be run by a central runner, which takes care of logging description, command, and outcome to a html report. The prefs used as parameters to each task is an associated array of associated arrays of &#8230; well as many levels as you require.</p>
<p>In effect the config file defines a domain specific language, using regular Python syntax, which can easily be loaded into what corresponds to the make utility by an import statement:</p>
<pre>
prefs = {
          <font color="#bc8f8f">"cvs"</font> :
          {
            <font color="#bc8f8f">"cvs"</font> : <font color="#bc8f8f">"C:\\Program Files\\cvsnt\\cvs.exe"</font>,
            <font color="#bc8f8f">"workingDirectory"</font> : <font color="#bc8f8f">"C:\\Inetpub\\wwwroot"</font>,
            <font color="#bc8f8f">"root"</font> : <font color="#bc8f8f">":pserver:foo:bar@1.2.3.4:/foobar"</font>,
            <font color="#bc8f8f">"module"</font> : <font color="#bc8f8f">"baz"</font>,
            <font color="#bc8f8f">"revision"</font> : <font color="#bc8f8f">"HEAD"</font>
          },
          <font color="#bc8f8f">"nunit"</font> :
          {
            <font color="#bc8f8f">"nunitconsole"</font> : <font color="#bc8f8f">"C:\\...\\nunit-console.exe"</font>,
            <font color="#bc8f8f">"projectsOrAssemblies"</font> : [C:\\Inetpub\\...\\foobar.nunit<font color="#bc8f8f">" ]
          },
          ...
        }

tasks = [ ("</font>Checkout Foobar <font color="#a020f0">from</font> cvs<font color="#bc8f8f">",
           lambda: Task.CvsCheckout(prefs["</font>cvs<font color="#bc8f8f">"]["</font>cvs<font color="#bc8f8f">"],
                                    prefs["</font>cvs<font color="#bc8f8f">"]["</font>workingDirectory<font color="#bc8f8f">"],
                                    prefs["</font>cvs<font color="#bc8f8f">"]["</font>root<font color="#bc8f8f">"],
                                    prefs["</font>cvs<font color="#bc8f8f">"]["</font>module<font color="#bc8f8f">"],
                                    prefs["</font>cvs<font color="#bc8f8f">"]["</font>revision<font color="#bc8f8f">"])),
          ...,
          ("</font>Running NUnit<font color="#bc8f8f">",
           lambda: Task.NUnit(prefs["</font>nunit<font color="#bc8f8f">"]["</font>nunitconsole<font color="#bc8f8f">"],
                              prefs["</font>nunit<font color="#bc8f8f">"]["</font>projectsOrAssemblies<font color="#bc8f8f">"]))
        ]</font>
</pre>
<p>This example, using the basic concepts of FP such as lists, list comprehension, tuples, build-in functions, and nice syntax, hopefully provided you with a glimpse of how a lot can be achieved in relatively few lines of Python code. Also, if you really want to explore FP from a Python perspective, I suggest you take a look at the <a href="http://sourceforge.net/projects/xoltar-toolkit">Xoltar Toolkit</a> (unfortunately, though, it isn&#8217;t under active development), described in David Mertz&#8217;s columns <a href="http://gnosis.cx/publish/programming/charming_python_16.html">More Functional Programming in Python</a> and <a href="http://gnosis.cx/publish/programming/charming_python_19.html">Even More Functional Programming in Python</a></p>
<p>Bottom line is that the use of FP style in your programs, although it takes time getting use to, leads to fewer lines of code, which leads to fewer places where things can go wrong.</p>
<p>This is not to say that your entire program should be written using the FP style (as is the case with Haskell). However, learning the basic concepts, and how Python exposes these to the developer, you&#8217;ll know which patterns to look for in your code that may be better solved using FP constructs.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.bugfree.dk/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.bugfree.dk/blog/2006/01/04/being-a-functional-pythonian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
