<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>ps. ruby sucks</description><title>respond_to?</title><generator>Tumblr (3.0; @mwjackson)</generator><link>http://blog.mwjackson.net/</link><item><title>covariance in c#</title><description>&lt;p&gt;So I&amp;#8217;ve been messing around building a Dependency Injection container in my spare time. Mainly for my own amusement, but also to practice designing DSLs and to play with some C# 4 features like anonymous objects. &lt;/p&gt;
&lt;p&gt;One of the first problems I came across was with requesting an interface that had been registered with a more specific generic type.&lt;/p&gt;
&lt;p&gt;We have a representation of the registration of interface and its implementation via a factory method shown below:&lt;/p&gt;
&lt;pre class="prettyprint"&gt;   public class FactoryRegistration : ObjectRegistration
    {
        public FactoryRegistration&amp;lt;T&amp;gt;(Type forType, Func&amp;lt;T&amp;gt; factoryFunction) : base(forType)
        {
            FactoryFunction = factoryFunction;
        }

        public Func&amp;lt;T&amp;gt; FactoryFunction { get; private set; } 
    }
&lt;/pre&gt;
&lt;div class="line" id="LC10"&gt;&amp;#8230;and this registration is satisfied by the resolver thus:&lt;/div&gt;
&lt;pre&gt;      public T Resolve&amp;lt;T&amp;gt;()
        {
            ...snip...

            var factoryRegistration = registration as FactoryRegistration&amp;lt;T&amp;gt;;
            return (T) factoryRegistration.FactoryFunction();
        }&lt;/pre&gt;
&lt;div class="line"&gt;Ok, so what&amp;#8217;s the problem?&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;Given this:&lt;/div&gt;
&lt;pre&gt;   new FactoryRegistration&amp;lt;Class&amp;gt;(typeof(IClass), () =&amp;gt; new Class());
&lt;/pre&gt;
&lt;div class="line"&gt;What happens when we try to resolve it with:&lt;/div&gt;
&lt;pre&gt;  resolver.Resolve&amp;lt;IClass&amp;gt;();
&lt;/pre&gt;
&lt;div class="line"&gt;Well, we get to these lines:&lt;/div&gt;
&lt;pre&gt;  var factoryRegistration = registration as FactoryRegistration&amp;lt;IClass&amp;gt;;
  return (T) factoryRegistration.FactoryFunction();
&lt;/pre&gt;
&lt;div class="line"&gt;and promptly get a NullRef exception when executing the factory function. Why? Because when we register the type, its a FactoryRegistration of type Class, and when we try to use it for resolution, we&amp;#8217;re asking for a FactoryRegistration of type IClass. We need an IClass, but we only have a Class. So we&amp;#8217;re kind of stuck. Now, there&amp;#8217;s a few different ways we could approach this through more &amp;#8220;conventional&amp;#8221; means, However, it occurred to me that this is exactly the type of problem that should be solvable via covariance/contravariance, new&amp;#8217;ish language features available in C#4.0. I mean, its fair to assume that the two types will always be compatible, so this seems right up its alley.&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;So what is covariance then? It basically &lt;a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)"&gt;&amp;#8220;a mechanism for providing&lt;span&gt; &lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;a href="http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)"&gt;interchangeability or equivalence of types in certain situations (such as parameters, generics, and return types)&amp;#8221;&lt;/a&gt;. In practice, this means we can&lt;/span&gt; lean on the compiler to provide more flexible signatures for functions and delegates. An example? Well (and with all relevant credit due to Eric Lippert), given types of Animal and Giraffe, and an inheritance relationship as you might expect, we could specify a method:&lt;/div&gt;
&lt;pre&gt;   public Giraffe MakeGiraffe() {
           return new Giraffe();
   }
&lt;/pre&gt;
&lt;div class="line"&gt;And assign as a function:&lt;/div&gt;
&lt;pre&gt;   Func&amp;lt;Animal&amp;gt; someFunc = MakeGiraffe();
&lt;/pre&gt;
&lt;div class="line"&gt;The function signature expects an Animal, and we&amp;#8217;re providing a method that does exactly that, so the compilers happy. The function signatures are said to be &lt;em&gt;covariant.&lt;/em&gt; What about contravariance? Well, think of the inverse when applied to function arguments (although this might be a topic for another blog post). Easy right? Well regardless, this wasn&amp;#8217;t always available in C#, and the history of which can be found in a series of excellent blog posts by &lt;a href="http://blogs.msdn.com/b/ericlippert/archive/tags/covariance%20and%20contravariance/default.aspx"&gt;Eric Lippert&lt;/a&gt;.&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;Right, back to our problem. So how do we solve our FactoryRegistration issue? Well, we simply define an interface, and take advantage of a new (and much less controversial) usage of the keyword &lt;em&gt;&lt;strong&gt;out&lt;/strong&gt;&lt;/em&gt; as thus:&lt;/div&gt;
&lt;pre&gt;    public interface IFactoryRegistration&amp;lt;out T&amp;gt;
    {
        Func&amp;lt;T&amp;gt; FactoryFunction { get; }
    }

    public class FactoryRegistration : ObjectRegistration, IFactoryRegistration&amp;lt;T&amp;gt;
    {
        public FactoryRegistration&amp;lt;T&amp;gt;(Type forType, Func factoryFunction) : base(forType)
        {
            FactoryFunction = factoryFunction;
        }

        public Func&amp;lt;T&amp;gt; FactoryFunction { get; private set; } 
    }
&lt;/pre&gt;
&lt;div class="line"&gt;We&amp;#8217;re now telling the compiler that our generic type parameter can be covariant. That is, that our more specific type (Class) can satisfy our less specific type (IClass). So our Resolve() method now looks like this:&lt;/div&gt;
&lt;pre&gt;      public T Resolve&amp;lt;T&amp;gt;()
        {
            ...snip...

            var factoryRegistration = registration as IFactoryRegistration&amp;lt;T&amp;gt;;
            return (T) factoryRegistration.FactoryFunction();
        }
&lt;/pre&gt;
&lt;div class="line"&gt;And Robert is your father&amp;#8217;s brother. We can now ask for an IClass, and be given a Class by our container. Don&amp;#8217;t worry, it still hurts my head a little too.&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;Want to know more about co/contra variance in C# (and in computer science in general)? I highly recommend this &lt;a href="http://blogs.msdn.com/b/ericlippert/archive/tags/covariance%20and%20contravariance/default.aspx"&gt;series of blog posts by the aforementioned Eric Lippert&lt;/a&gt;.&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;Enjoy. Comments welcome.&lt;/div&gt;
&lt;div class="line"&gt;&lt;/div&gt;
&lt;div class="line"&gt;PS. If you want to follow my adventures in building a DI container, look &lt;a href="https://github.com/mwjackson/ioc"&gt;here&lt;/a&gt;. Pull requests encouraged.&lt;/div&gt;</description><link>http://blog.mwjackson.net/post/21726067065</link><guid>http://blog.mwjackson.net/post/21726067065</guid><pubDate>Tue, 24 Apr 2012 19:55:00 +0100</pubDate></item><item><title>swisscom 3g dongles</title><description>&lt;p&gt;Those cheeky little devils at Swisscom have found a novel way of restricting wifi sharing of their 3G dongles, resulting in the following error message when attempting to connect to a network in Windows 7:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;#8220;Your network administrator has blocked you from connecting to this network&amp;#8221;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;With a little searching I came across &lt;a href="http://www.thomasclaudiushuber.com/blog/2009/02/10/use-the-network-services-shell-to-unblock-wlans-in-windows-vista/"&gt;this&lt;/a&gt; solution, which allows you to fix it via an Administrators Command Prompt as follows:&lt;/p&gt;
&lt;pre&gt;netsh wlan delete filter permission=denyall networktype=infrastructure 
netsh wlan delete filter permission=denyall networktype=adhoc&lt;/pre&gt;
&lt;p&gt;Enjoy&lt;/p&gt;</description><link>http://blog.mwjackson.net/post/17616865049</link><guid>http://blog.mwjackson.net/post/17616865049</guid><pubDate>Tue, 14 Feb 2012 19:56:00 +0000</pubDate></item><item><title>.net project structure and build times part 3</title><description>&lt;p&gt;(continued from &lt;a href="http://mwjackson.tumblr.com/post/14911550228/net-project-structure-and-build-time-statistics-part-2"&gt;Part 2&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Test 2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This was centred around the choice of disk drive. We&amp;#8217;re building a slightly different project from before, but similar size (about 100k LOC) and structure (about 55 projects). This main difference this time was that MsBuild was being executed with the following property:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;OutDir=c:\A\Single\Output\Directory&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So we are cutting out a LOT of I/O. Every assembly, including the lib ones, are being copied only once per run. So this negates a lot of the purported benefits of SSD and RAM drives, but IMO it ends up being much more indicative of the kind of improvements you can get from good architecture (refer to Test 1). Finally, we are also cleaning each bin &amp;amp; obj directories before each pass:&lt;/p&gt;
&lt;pre&gt;&lt;strong&gt;HDD&lt;/strong&gt; - 5 builds in 3:00 mins @ 36 seconds each&lt;/pre&gt;
&lt;pre&gt;&lt;strong&gt;SSD&lt;/strong&gt; - 5 builds in 2:37 mins @ 31 seconds each (~15% faster)&lt;/pre&gt;
&lt;pre&gt;&lt;strong&gt;RAM*&lt;/strong&gt; - 5 builds in 2:20 mins @ 28 seconds each (~23% faster)&lt;/pre&gt;
&lt;p&gt;I also ran another RAM disk run using the original project structure in Test 1&lt;/p&gt;
&lt;pre&gt;10 builds in 03:06 @ 00:18 per build (~80% faster than the original 91 seconds)&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;* The RAM Disk used can be found here: &lt;a href="http://www.ltr-data.se/opencode.html/#ImDisk"&gt;&lt;a href="http://www.ltr-data.se/opencode.html/#ImDisk"&gt;http://www.ltr-data.se/opencode.html/#ImDisk&lt;/a&gt;&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Conclusions&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;So what can we infer from these results? Well, quite a lot really - but as always they come with caveats.&lt;/p&gt;
&lt;p&gt;1. I/O is a killer. Getting rid of all those copy local references took nearly 90% off the build time.&lt;/p&gt;
&lt;p&gt;2. Csc.exe is fast. Damn fast. Spinning up all those Win32 subprocesses costs a lot of time, and when you only have to do it once, the compile times drop to near 0.&lt;/p&gt;
&lt;p&gt;3. Faster drives help. But they only Band-Aid over the symptoms, you&amp;#8217;ll get much better results by addressing the root cause.&lt;/p&gt;
&lt;p&gt;Now obviously I&amp;#8217;m not suggesting that you go and refactor your entire codebase into a single project file. There are lots of things to consider when structuring .NET solutions; the make-up of your deployable artefacts, separating test &amp;amp; production code, vertical &amp;amp; horizontal partitioning of functionality, &amp;#8220;code re-use&amp;#8221; (although the alleged benefits of this is a &lt;a href="http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/"&gt;topic for another day&lt;/a&gt;) etc etc. However, its worth keeping in mind, especially early in the project, the potential consequences of design choices. &lt;/p&gt;
&lt;p&gt;Next time, I&amp;#8217;ll be looking at the impact that CI tools can have on the speed of your build process.&lt;/p&gt;
&lt;p&gt;PS. I discovered another little gem today. Sick of all those XML IntelliSense files clogging up your output folders? Try this little nugget, and shave 40% off your artefact sizes:&lt;/p&gt;
&lt;pre&gt;MsBuild.exe YourBuild.file /p:GenerateDocumentation=false;AllowedReferenceRelatedFileExtensions=none&lt;/pre&gt;</description><link>http://blog.mwjackson.net/post/15400258015</link><guid>http://blog.mwjackson.net/post/15400258015</guid><pubDate>Fri, 06 Jan 2012 15:33:00 +0000</pubDate></item><item><title>.net project structure and build time statistics part 2</title><description>&lt;p&gt;(Continued from &lt;a href="http://mwjackson.tumblr.com/post/14636466215/net-project-structure-and-build-time-statistics-part"&gt;Part 1&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;So, nothing like some hard figures to help sharpen the mind&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Test 1&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This test was centred around project structure&amp;#8230; that is, the number of csproj&amp;#8217;s and the type of references each held to each other.&lt;/p&gt;
&lt;p&gt;Our test machine was an i7 with 8 gigs of RAM and a 7200pm HDD, each run was held after a fresh reboot, no other programs running (save a terminal session). MsBuild was executed from within a small python script, and the timing information was output to the console. The measurements which follows aren&amp;#8217;t particularly scientific, however I hope they serve as an indication of what is possible.&lt;/p&gt;
&lt;p&gt;&lt;u&gt;Original Structure (our &lt;/u&gt;&lt;u&gt;baseline)&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;This was a solution file of approximately ~80 projects &amp;amp; 125k LOC. There was quite a number of projects with only a handful of .cs files, and every project file was set to CopyLocal = true for its non-mscorlib references. This basically amounted to a collective output of thousands of assemblies, with many copies of the same third-party DLL&amp;#8217;s in each output directory (think, 100&amp;#8217;s of copies of nhibernate.dll &amp;amp; nservicebus.dll). Our build times were:&lt;/p&gt;
&lt;pre&gt;10 builds in 15:18 mins @ 1:31 mins per build&lt;/pre&gt;
&lt;p&gt;&lt;u&gt;Assembly/Weak references (CopyLocal = false)&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;That CopyLocal setting (or &amp;lt;private&amp;gt; node in the csproj XML) that I mentioned above was resulting in a huge amount of file I/O for each and every build. So, following Patrick Smacchia&amp;#8217;s advice from the article I linked to in the first part of this series, I converted every reference (via a &lt;a href="https://github.com/mwjackson/ProjectManipulator"&gt;little tool&lt;/a&gt; I wrote) to CopyLocal = false, and ran another test run. An 81% improvement&amp;#8230; not bad.&lt;/p&gt;
&lt;pre&gt;10 builds in 3:08 mins @ 0:18 mins per build&lt;/pre&gt;
&lt;p&gt;&lt;u&gt;Single Project file&lt;/u&gt;&lt;/p&gt;
&lt;p&gt;Watching all those MsBuild instances scroll up my terminal window (apart from being ridiculously hypnotic), I noticed something else. MsBuild shelling out to csc.exe takes a rather long time, maybe a second or two each and every time. However, once its running the compilation itself is very, very quick. So, with the help of ReSharper (CTRL + R + O is your friend), I merged all the code into a single project file. The results are impressive - almost 2 orders of magnitude improvement!&lt;/p&gt;
&lt;pre&gt;10 builds in 16 secs @ 1.6 secs per build&lt;/pre&gt;
&lt;p&gt;Ok, so now we are starting to see where the bottlenecks lie in our build process. Next, I&amp;#8217;ll be looking at the impact of various drives (HDD, SSD and RAMDisks) on compilation times.&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;</description><link>http://blog.mwjackson.net/post/14911550228</link><guid>http://blog.mwjackson.net/post/14911550228</guid><pubDate>Wed, 28 Dec 2011 09:22:00 +0000</pubDate></item><item><title>.net project structure and build time statistics part 1.</title><description>&lt;p&gt;So, my current role has us dealing with a build, deployment and integration test cycle of about 2 hours. Given the 50-odd developers spread across 6-7 teams, this is not a particularly nice situation. Apart from it being a PITA, a feedback loop of this length results in plenty of negative consequences, a selection of which include:&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;feature branching (esp to mitigate cross team dependencies during a release phases)&lt;/li&gt;
&lt;li&gt;developer multi-tasking (&amp;#8220;I&amp;#8217;ll just start this other thing while I&amp;#8217;m waiting for a build&amp;#8230; oh wait now I&amp;#8217;m doing 3 things at once&amp;#8221;)&lt;/li&gt;
&lt;li&gt;difficult tracking build breakages (30 min builds mean commits bunch up - which one broke the build?)&lt;/li&gt;
&lt;li&gt;large batching of code changes (&amp;#8220;if it takes 2 hours to get feedback, I&amp;#8217;m going to save integrating my work until its finished&amp;#8221;)&lt;/li&gt;
&lt;li&gt;forgetfulness (&amp;#8220;I can&amp;#8217;t remember what changes I made 2 hours ago that just broke the build&amp;#8221;)&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;We get into a situation where we are no longer &amp;#8220;continually integrating&amp;#8221; our work, but moving back to the dark old days of hourly or nightly builds (or not at all!). Instead of speeding up, the teams are slowing down, releases become less frequent and quality inevitably falls.&lt;/p&gt;
&lt;p&gt;So, considering the amount of lost development resource this was costing the company (2 hours times N developers = a lot of money and more importantly time), I was tasked with improving the situation in any way that we could. Some outcomes were possible, some not, some resulted in great improvements, others only minor gains. But it did mean that I did possibly more research into the MsBuild system, csc.exe, .NET assembly structures and Visual Studio project files than is probably healthy, in an effort to squeeze every last second of time out of the process.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll present my findings, and a bunch of interesting articles I (re)discovered along the way in the next few weeks. In the meantime, and to help set the scene somewhat, enjoy this little gem from the man himself - Patrick Smacchia (creator of NDepend)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/"&gt;&lt;a href="http://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/"&gt;http://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;</description><link>http://blog.mwjackson.net/post/14636466215</link><guid>http://blog.mwjackson.net/post/14636466215</guid><pubDate>Thu, 22 Dec 2011 22:35:36 +0000</pubDate></item><item><title>portable .net development</title><description>&lt;p&gt;I&amp;#8217;ve had to setup my dev environment on a few different machines recently. Quite a simple, but repetitive exercise, so I decided to see if I could make it completely portable. The TL;DR of it is that you can&amp;#8217;t completely - but you can to a certain extent.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s what I&amp;#8217;ve managed to do so far: &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;a) File sync&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m using SpiderOak currently. DropBox only lets you backup a single folder, and Ubuntu One&amp;#8217;s conflict resolution leaves a lot to be desired on Windows (at the moment) - appending &lt;em&gt;.u1.conflict&lt;/em&gt; to filenames all over the place. The SpiderOak client is not perfect either - but it seems to be a workable solution so far.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;b) Dotfiles&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve added some of my dotfiles to their own directory (.bashrc, .bash_history, .ssh/, .gitconfig etc), and got them syncing to the &amp;#8220;cloud&amp;#8221;. You can then use mklink to make a Windows version of a symlink, thus:&lt;/p&gt;
&lt;pre&gt;mklink /H ..\.bashrc dotfiles\.bashrc&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;c) Portable apps&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Most of the tools I use have a portable version (obviously with the exception of Visual Studio &amp;amp; Resharper), so get these sync&amp;#8217;d up as well&lt;/p&gt;
&lt;p&gt;- Git (make sure you set GITDIR in your environment)&lt;/p&gt;
&lt;p&gt;- Console2 (delete the config in your %APPDATA%)&lt;/p&gt;
&lt;p&gt;- Sublime (this is a great little text editor I&amp;#8217;ve just discovered, so long Notepad++!)&lt;/p&gt;
&lt;p&gt;- WinSplit Revolution&lt;/p&gt;
&lt;p&gt;- Unlocker&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;d) The extras&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next thing I did was to create batch files to set your symlinks and path. The symlinks work a treat, but the ENV/PATH stuff is a bit of a pain (more on this below).&lt;/p&gt;
&lt;p&gt;As a nice to have, there are some registry files to add stuff to your context menu as thus:&lt;/p&gt;
&lt;pre&gt;Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Open with Sublime\command]
@="C:\\Users\\matt.jackson\\dev\\Sublime Text 2 Build 2139\\sublime_text.exe %1"
&lt;/pre&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;d) What I haven&amp;#8217;t done yet&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Git Extensions. There is a portable version I believe, but the Explorer menu is the main reason I use it. The GitExtensions project sets these via a MSI, which is less than ideal - I&amp;#8217;m open to suggestions.&lt;/p&gt;
&lt;p&gt;p4merge. Probably the best thing to come out of Perforce, and its free! Doesn&amp;#8217;t appear to be portable though. &lt;/p&gt;
&lt;p&gt;Resharper license/settings. I know settings are stored in %AppData%, so this is on my TODO list. License information is probably in the registry but to be confirmed. Work in progress.&lt;/p&gt;
&lt;p&gt;Autorun scripts on logon. Maybe add something to my .bashrc or similar that ensures everything is set correctly. Need to think on this more.&lt;/p&gt;
&lt;p&gt;Add directories to your user PATH permanently. I could have sworn there was a way do this via SET but I still can&amp;#8217;t find it. For now, its a case of copy/pasting into a dialog box.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;d love to hear about people&amp;#8217;s experiences with this. How far have you got and have you solved anything on the TODO list above?&lt;/p&gt;</description><link>http://blog.mwjackson.net/post/13879923881</link><guid>http://blog.mwjackson.net/post/13879923881</guid><pubDate>Wed, 07 Dec 2011 18:29:49 +0000</pubDate></item><item><title>sonar for c# on windows</title><description>&lt;p&gt;&lt;a href="http://www.sonarsource.org/"&gt;Sonar&lt;/a&gt; is a shiny dashboard for code quality that provides an integration point for various quality frameworks (FxCop, StyleCop, NCover, Gallio, Gendarme etc). Unfortunately (like most awesome tools), its native to the JVM but there are actively maintained plugins for .NET.&lt;/p&gt;
&lt;p&gt;So here&amp;#8217;s a quick rundown for how I got it running on my local machine:&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Install Sonar - &lt;a href="http://docs.codehaus.org/display/SONAR/Install+Sonar"&gt;&lt;a href="http://docs.codehaus.org/display/SONAR/Install+Sonar"&gt;http://docs.codehaus.org/display/SONAR/Install+Sonar&lt;/a&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;Install requirements&lt;ol&gt;&lt;li&gt;Make sure java.exe is in your search PATH (C:\Program Files (x86)\Java\jre6\bin)&lt;/li&gt;
&lt;li&gt;Tomcat - run as exe or install as service&lt;/li&gt;
&lt;li&gt;DB not required for demo but would for proper installation (MSSQL, MySql, Postgres etc)&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Unzip (c:\sonar)&lt;/li&gt;
&lt;li&gt;Run via c:\sonar-2.11\bin\windows-x86-32\StartSonar.bat&lt;/li&gt;
&lt;li&gt;Wait a few minutes for the JVM to spin up and create a local DB (/data)&lt;/li&gt;
&lt;li&gt;You can watch this via /logs/sonar.log&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Install Sonar-runner (so we can run it without Maven) - &lt;a href="http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner"&gt;&lt;a href="http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner"&gt;http://docs.codehaus.org/display/SONAR/Analyse+with+a+simple+Java+Runner&lt;/a&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;Set your JAVA_HOME (C:\Program Files (x86)\Java\jre6)&lt;/li&gt;
&lt;li&gt;(Optional) Copy the jdbc settings from sonar.properties to sonar-runner.properties&lt;ol&gt;&lt;li&gt;
&lt;p&gt;sonar.jdbc.url: &lt;a href="http://wiki.wonga.com/jdbc:derby:/localhost:1527/sonar;create=true"&gt;jdbc:derby://localhost:1527/sonar;create=true&lt;/a&gt;&lt;br/&gt;sonar.jdbc.driverClassName: org.apache.derby.jdbc.ClientDriver&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Add C:\sonar-runner-1.1\bin to your PATH&lt;/li&gt;
&lt;li&gt;To test: sonar-runner -h&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Follow the C# plugin walkthrough here: &lt;a href="http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem"&gt;&lt;a href="http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem"&gt;http://docs.codehaus.org/display/SONAR/C-Sharp+Plugins+Ecosystem&lt;/a&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;Download &lt;a href="http://docs.codehaus.org/download/attachments/201228384/CSharpPluginsEcosystem-1.1.zip"&gt;&lt;a href="http://docs.codehaus.org/download/attachments/201228384/CSharpPluginsEcosystem-1.1.zip"&gt;http://docs.codehaus.org/download/attachments/201228384/CSharpPluginsEcosystem-1.1.zip&lt;/a&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Extract to C:\sonar-2.11\extensions\plugins&lt;/li&gt;
&lt;li&gt;(Remove gallio &amp;amp; fxcop jars unless you&amp;#8217;ve installed their binaries separately)&lt;/li&gt;
&lt;li&gt;Restart Sonar&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Create a sonar config in your .sln directory &lt;a href="http://docs.codehaus.org/display/SONAR/2.+Configure#2.Configure-CreateaSonarfileforyoursolution"&gt;&lt;a href="http://docs.codehaus.org/display/SONAR/2.+Configure#2.Configure-CreateaSonarfileforyoursolution"&gt;http://docs.codehaus.org/display/SONAR/2.+Configure#2.Configure-CreateaSonarfileforyoursolution&lt;/a&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;&lt;span&gt;Create sonar-project.properties&lt;/span&gt; &amp;amp; paste skeleton config&lt;/li&gt;
&lt;li&gt;&lt;span&gt;cd to your .sln directory&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Run sonar-runner from cmd&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;li&gt;Bask in the shiny graphs&lt;/li&gt;
&lt;/ol&gt;&lt;h6 id="SonarwithNETProjects-STILLTODO"&gt;&lt;strong&gt;Some interesting things I&amp;#8217;m still to do&amp;#8230;&lt;/strong&gt;&lt;/h6&gt;
&lt;ul&gt;&lt;li&gt;Add Gallio with (PartCover|NCover) for unit test coverage&lt;/li&gt;
&lt;li&gt;Figure how to integrate it into the CI process&lt;/li&gt;
&lt;li&gt;&amp;#8220;Stop the line&amp;#8221; on certain metrics?&lt;/li&gt;
&lt;/ul&gt;</description><link>http://blog.mwjackson.net/post/13416667370</link><guid>http://blog.mwjackson.net/post/13416667370</guid><pubDate>Sun, 27 Nov 2011 20:58:06 +0000</pubDate></item><item><title>less common git techniques</title><description>&lt;p&gt;I&amp;#8217;ve had to solve some interesting problems over the last few weeks, and although it doesn&amp;#8217;t really surprise me, git has come to the rescue in every single case.  &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Merging two git repositories&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Say you were working on a spike of some independent code in its&amp;#8217; own repo, and you&amp;#8217;ve decided you want to merge it into your main repository. Easy:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://nuclearsquid.com/writings/subtree-merging-and-you/"&gt;&lt;a href="http://nuclearsquid.com/writings/subtree-merging-and-you/"&gt;http://nuclearsquid.com/writings/subtree-merging-and-you/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Triggering TeamCity builds directly from github&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;GitHub is awesome. You should host your code there. But triggering your local build without polling them every 30 seconds? No problem:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.jaxzin.com/2011/02/teamcity-build-triggering-by-github.html"&gt;&lt;a href="http://www.jaxzin.com/2011/02/teamcity-build-triggering-by-github.html"&gt;http://www.jaxzin.com/2011/02/teamcity-build-triggering-by-github.html&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Splitting a git repository (including history)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Finally, imagine a folder that you&amp;#8217;d love to get rid of out of your repository. Hypothetically, let&amp;#8217;s say a folder full of documentation, specifications, Word files, Visio files and the like. Hundreds of megs and you don&amp;#8217;t really need that shit in a codebase do you? Well, let&amp;#8217;s split it out:&lt;/p&gt;
&lt;p&gt;&lt;a&gt;&lt;a href="http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository"&gt;http://stackoverflow.com/questions/359424/detach-subdirectory-into-separate-git-repository&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;p&gt;// copy your repo to a new directory&lt;/p&gt;&lt;p&gt;git clone --no-hardlinks ./original_repo ./new_repo&lt;/p&gt;&lt;p&gt;// now filter out the folder(s) you want to keep&lt;/p&gt;&lt;p&gt;cd new_repo/&lt;br/&gt;git status&lt;br/&gt;git filter-branch --subdirectory-filter ./the_folder_you_want_to_split/ HEAD&lt;br/&gt;git reset --hard&lt;br/&gt;rm -rf .git/refs/original/&lt;br/&gt;git reflog expire --expire=now --all&lt;br/&gt;git gc --aggressive --prune=now&lt;/p&gt;&lt;p&gt;// and head back to the original repo and delete that folder&lt;/p&gt;&lt;p&gt;cd ../original_repo/&lt;br/&gt;git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch the_folder_you_want_to_split" --prune-empty HEAD&lt;br/&gt;git reset --hard&lt;br/&gt;git gc --aggressive --prune=now&lt;/p&gt;&lt;/pre&gt;
&lt;p&gt;And one for the road, here&amp;#8217;s a cool little site that outlines what goes on under git&amp;#8217;s covers:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://think-like-a-git.net/"&gt;&lt;a href="http://think-like-a-git.net/"&gt;http://think-like-a-git.net/&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I did have a few free ebooks on the topic, I&amp;#8217;ll see if I can dig them up - they are great reads.&lt;/p&gt;</description><link>http://blog.mwjackson.net/post/13076329590</link><guid>http://blog.mwjackson.net/post/13076329590</guid><pubDate>Sun, 20 Nov 2011 20:43:00 +0000</pubDate></item><item><title>git on windows</title><description>&lt;p&gt;Some little gems from my .gitconfig&amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;p4merge with git&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;[diff]
	tool = p4merge
	guitool = p4merge
[difftool "p4merge"]
	path = C:/Program Files/Perforce/p4merge.exe
	cmd = \"C:/Program Files/Perforce/p4merge.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
	summary = true
	tool = p4merge
[mergetool "p4merge"]
	path = C:/Program Files/Perforce/p4merge.exe
	keepBackup = false
	cmd = \"c:/Program Files/Perforce/p4merge.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;pull with automatic rebase&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I have just discovered the beauty of pull with rebase (single, easy to read history on master! no more merges!). However, its a bit of a pain to continually do this:&lt;/p&gt;
&lt;pre&gt;git pull --rebase origin master&lt;/pre&gt;
&lt;p&gt;So to switch on rebase by default&amp;#8230;&lt;/p&gt;
&lt;pre&gt;git config --global branch.autosetuprebase always&lt;/pre&gt;
&lt;p&gt;Beware! This only applies to new repo&amp;#8217;s, not existing ones. To update existing repo&amp;#8217;s with this setting try this:&lt;/p&gt;
&lt;pre&gt;git config branch.branch-name.rebase true&lt;/pre&gt;
&lt;p&gt;eg.&lt;/p&gt;
&lt;pre&gt;git config branch.master.rebase true&lt;/pre&gt;
&lt;p&gt;(reference: &lt;a href="http://stevenharman.net/blog/archive/2011/06/09/git-pull-with-automatic-rebase.aspx"&gt;git with automatic rebase&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ssh-agent on windows&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ok, this one is just stolen straight from the github site &lt;a title="here" href="http://help.github.com/ssh-key-passphrases/"&gt;here&lt;/a&gt;, but it still bears mentioning anyway. Use ssh-agent to hold onto your keys instead of stupid pageant. Add this to your .bashrc and have your keys loaded the first time you launch git bash after a boot!&lt;/p&gt;
&lt;pre&gt;SSH_ENV="$HOME/.ssh/environment"

# start the ssh-agent
function start_agent {
    echo "Initializing new SSH agent..."
    # spawn ssh-agent
    ssh-agent | sed 's/^echo/#echo/' &amp;gt; "$SSH_ENV"
    echo succeeded
    chmod 600 "$SSH_ENV"
    . "$SSH_ENV" &amp;gt; /dev/null
    ssh-add
}

# test for identities
function test_identities {
    # test whether standard identities have been added to the agent already
    ssh-add -l | grep "The agent has no identities" &amp;gt; /dev/null
    if [ $? -eq 0 ]; then
        ssh-add
        # $SSH_AUTH_SOCK broken so we start a new proper agent
        if [ $? -eq 2 ];then
            start_agent
        fi
    fi
}

# check for running ssh-agent with proper $SSH_AGENT_PID
if [ -n "$SSH_AGENT_PID" ]; then
    ps -ef | grep "$SSH_AGENT_PID" | grep ssh-agent &amp;gt; /dev/null
    if [ $? -eq 0 ]; then
	test_identities
    fi
# if $SSH_AGENT_PID is not properly set, we might be able to load one from
# $SSH_ENV
else
    if [ -f "$SSH_ENV" ]; then
	. "$SSH_ENV" &amp;gt; /dev/null
    fi
    ps -ef | grep "$SSH_AGENT_PID" | grep -v grep | grep ssh-agent &amp;gt; /dev/null
    if [ $? -eq 0 ]; then
        test_identities
    else
        start_agent
    fi
fi
&lt;/pre&gt;</description><link>http://blog.mwjackson.net/post/12830976411</link><guid>http://blog.mwjackson.net/post/12830976411</guid><pubDate>Tue, 15 Nov 2011 09:35:00 +0000</pubDate></item><item><title>coming soon...</title><link>http://blog.mwjackson.net/post/12802795468</link><guid>http://blog.mwjackson.net/post/12802795468</guid><pubDate>Mon, 14 Nov 2011 21:26:09 +0000</pubDate></item></channel></rss>

