<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sergio Pereira : Tips-and-Tricks</title><link>http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx</link><description>Tags: Tips-and-Tricks</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Have you met arguments.callee?</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/09/10/have-you-met-arguments-callee.aspx</link><pubDate>Fri, 10 Sep 2010 23:36:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:62061</guid><dc:creator>sergiopereira</dc:creator><slash:comments>6</slash:comments><description>&lt;p&gt;
  Just the other day I had a need to use &lt;code&gt;arguments.callee&lt;/code&gt; and I realized that&amp;#39;s
  not something you really see every day in JavaScript. Maybe I could talk about it a bit.
 &lt;/p&gt;

 &lt;h3&gt;Anonymous functions everywhere&lt;/h3&gt;
 &lt;p&gt;
  It&amp;#39;s not news to anyone reading this blog that one of JavaScript&amp;#39;s workhorses are
  anonymous functions. Callbacks, strategies, deferred execution, event handlers, etc. 
  They just seem to be all over the place &amp;mdash; and for a good reason; they can
  be convenient and reduce the pollution of a bunch functions that are only called
  from a single spot. 
 &lt;/p&gt;
 &lt;p&gt;
  Another nice thing is that, once your eyes are trained to ignore the little bit
  of noise that they add to the code, the code is really readable and, dare I
  say it, expressive.
 &lt;/p&gt;

 &lt;h3&gt;Yet another contrived example&lt;/h3&gt;
 &lt;p&gt;
  Let&amp;#39;s say we are really into reinventing the wheel and with our understanding
  of anonymous functions we create a revolutionary &lt;code&gt;map&lt;/code&gt; function:

 &lt;/p&gt; 

 &lt;pre name="code" class="js:nogutter"&gt;function map(array, compute){
  var result = [ ];
  for(var i=0; i &amp;lt; array.length; i++){
    result.push( compute(array[i]) );
  }
  return result;
}&lt;/pre&gt;

&lt;p&gt;
	This function, as you can hopefully see, transforms each element of
	the given array into something else and returns the array of the
	transformed elements. Two simple uses are shown below.
&lt;/p&gt;

 &lt;pre name="code" class="js:nogutter"&gt;//apply discount
var prices = [1, 2, 3, 4];
var discount = 0.1; // 10% off today, w00t!
var newPrices = map(prices, function(price){ return (1-discount)*price; } );
//==&amp;gt; [0.9, 1.8, 2.7, 3.6]

//compute areas
var squareSides = [1, 2, 3, 4];
var squareAreas = map(squareSides, function(side){ return side*side; } );
//==&amp;gt; [1, 4, 9, 16]&lt;/pre&gt;

&lt;p&gt;I warned you the examples would be contrived, didn&amp;#39;t I?&lt;/p&gt;

&lt;p&gt;
	Now your product manager comes and asks for a page where the users
	can enter a list of numbers and get the factorials for each of them.
	You immediately think your friend the &lt;code&gt;map&lt;/code&gt; function will
	save the day. You start and...
&lt;/p&gt;

 &lt;pre name="code" class="js:nogutter"&gt;//return the factorials
var userNumbers = [1, 2, 3, 4];
var factorials = map(userNumbers, function(number){ 
  if(number &amp;lt;= 1) { return 1; }
  return number * ????????(number - 1); // ooops! I need to recurse here.
} );&lt;/pre&gt;

 &lt;p&gt;You see, there&amp;#39;s this thing with anonymous functions. 
 &lt;b&gt;They don&amp;#39;t have a name&lt;/b&gt;, d&amp;#39;oh. As I said in the beginning, we
 typically use them in situations where they are called only once so
 we can inline them and forego the need fora name. But now we&amp;#39;re kind of
 wishing they had a name. 

 &lt;h3&gt;Anonymity won&amp;#39;t hide you from me&lt;/h3&gt;
 &lt;p&gt;
	Well, if the post tittle didn&amp;#39;t already give it away, we can achieve that
	with 
	&lt;a href="https://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments/callee"&gt;&lt;code&gt;arguments.callee&lt;/code&gt;&lt;/a&gt;. Using &lt;code&gt;arguments.callee&lt;/code&gt; inside a function gives 
	us a reference to the function itself. So now we can finish our code.
 &lt;/p&gt;
 &lt;pre name="code" class="js:nogutter"&gt;//return the factorials
var userNumbers = [1, 2, 3, 4];
var factorials = map(userNumbers, function(number){ 
  if(number &amp;lt;= 1) { return 1; }
  return number * arguments.callee(number - 1);
  //or if you were using &amp;quot;this&amp;quot; in the function you&amp;#39;ll probably want to:
  // return number * arguments.callee.apply(this, [number - 1]);
} );
//==&amp;gt; [1, 2, 6, 24]&lt;/pre&gt;

&lt;h3&gt;A more real world scenario&lt;/h3&gt;
&lt;p&gt;
I won&amp;#39;t leave you without at least a reference to a real use
case for this feature. The example I&amp;#39;ll show comes
from &lt;a href="http://www.nczonline.net/"&gt;Nicholas Zakas&lt;/a&gt;. In
&lt;a href="http://www.nczonline.net/blog/2009/08/11/timed-array-processing-in-javascript/"&gt;a blog post a while ago&lt;/a&gt; he showed how we can
break up long running tasks with smaller timed/deferred chunks,
improving the browser&amp;#39;s responsiveness.
&lt;/p&gt;

&lt;p&gt;Here&amp;#39;s the function from his blog post, which process chunks of
an array for 50ms, then stops and call itself back to process
the remaining items soon after that &amp;mdash; giving the browser
a chance to breathe and take care of its interaction with the 
user&lt;p&gt;

&lt;pre name="code" class="js:nogutter"&gt;//Copyright 2009 Nicholas C. Zakas. All rights reserved.
//MIT Licensed
function timedChunk(items, process, context, callback){
   var todo = items.concat();   //create a clone of the original

  setTimeout(function(){

    var start = +new Date();

    do {
       process.call(context, todo.shift());
    } while (todo.length &amp;gt; 0 &amp;amp;&amp;amp; (+new Date() - start &amp;lt; 50));

    if (todo.length &amp;gt; 0){
      setTimeout(arguments.callee, 25);
    } else {
      callback(items);
    }
  }, 25);
}&lt;/pre&gt;

 &lt;p&gt;I hope this shows you a little new trick.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=62061" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript-Demystified/default.aspx">JavaScript-Demystified</category></item><item><title>More on blocked files</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/06/23/more-on-blocked-files.aspx</link><pubDate>Thu, 24 Jun 2010 03:26:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:60722</guid><dc:creator>sergiopereira</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I&amp;#39;ve &lt;a href="http://devlicio.us/blogs/sergio_pereira/archive/2009/04/03/blocked-js-files-keep-biting-me.aspx"&gt;written about this&lt;/a&gt; before.
You download a file to use in your web application, like a JavaScript library or an image file
but the browser just can&amp;#39;t seem to load it. You spend hours looking for a typo or broken link
until you find out about that Unblock button and you realize that it&amp;#39;s IIS that isn&amp;#39;t serving 
the file. The file had been there; you had the correct URL all along; it&amp;#39;s just disallowed.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/properties_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/properties_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I actually developed the reflex to right click and unblock each an every file I
download now. It&amp;#39;s stupid, isn&amp;#39;t it? I should have imagined there was a way to 
disable that Windows feature instead of just learning how to live with the problem.
&lt;/p&gt;
&lt;p&gt;Well, no more. Here&amp;#39;s how you can disable it. Credit goes to &lt;a href="http://www.petri.co.il/unblock-files-windows-vista.htm"&gt;this article&lt;/a&gt;.
&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Run &lt;b&gt;gpedit.msc&lt;/b&gt; (the group policy editor)&lt;/li&gt;
	&lt;li&gt;Go to &lt;b&gt;User Configuration/Administrative Templates/Windows Components/Attachment Manager&lt;/b&gt;&lt;/li&gt;
	&lt;li&gt;Find the setting named &lt;b&gt;Do not preserve zone information in file attachments&lt;/b&gt; and &lt;b&gt;enable&lt;/b&gt; it&lt;/li&gt;
	&lt;li&gt;Log off then log back on, or update the current policies with: &lt;b&gt;Gpupdate /force&lt;/b&gt; in any command prompt.
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.06/unblock.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.06/unblock_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Note:&lt;/b&gt; If you&amp;#39;re using Chrome it looks like &lt;a href="http://codereview.chromium.org/590001"&gt;there&amp;#39;s some bug&lt;/a&gt; that may or may not be
taken care of as you read this. Chrome doesn&amp;#39;t seem to honor the policy setting and always mark the downloaded files as unsafe.&lt;/p&gt;

&lt;p&gt;Now I just need to add this to the list of tasks anytime I get a new machine or repave one of them.&lt;/p&gt;

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=60722" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Rule "Previous releases of Microsoft Visual Studio 2008" failed</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/03/07/rule-quot-previous-releases-of-microsoft-visual-studio-2008-quot-failed.aspx</link><pubDate>Sun, 07 Mar 2010 10:43:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55695</guid><dc:creator>sergiopereira</dc:creator><slash:comments>18</slash:comments><description>&lt;p&gt;
 Today I was trying to install SQL 2008 on my box and the setup stopped after checking a bunch of
rules. The error message was the title of this post.
&lt;/p&gt;

&lt;p&gt;
A quick search on the internet revealed that somehow the installer didn&amp;#39;t believe I had VS 2008 &lt;b&gt;SP1&lt;/b&gt;
installed, which I did. The recommendations in &lt;a href="http://support.microsoft.com/kb/956139"&gt;the KB article&lt;/a&gt;
were kind of insulting. There&amp;#39;s no way I&amp;#39;d spend hours of my day uninstalling and reinstalling VS and SQL &amp;mdash; sorry, no chance. I
also could not accept not installing the Management Tools, for example. I also did not have any Express version of VS or SQL installed in this box.
&lt;/p&gt;

&lt;p&gt;
A little snooping around with &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx"&gt;ProcMon&lt;/a&gt;
led me to the following registry key: 
&lt;/p&gt;

&lt;pre&gt;HKLM\SOFTWARE\Wow6432Node\Microsoft\DevDiv\VS\Servicing\9.0\IDE\1033&lt;/pre&gt;

&lt;p&gt;
In that key I noticed the suspicious values:
&lt;/p&gt;

&lt;pre&gt;&amp;quot;SP&amp;quot;=dword:00000000
&amp;quot;SPIndex&amp;quot;=dword:00000000
&amp;quot;SPName&amp;quot;=&amp;quot;RTM&amp;quot;
&lt;/pre&gt;

&lt;p&gt;
Without quitting the SQL server installer validaton screen, I changed these values to what you see below, crossed my fingers 
and rerun the installer validation, &lt;b&gt;which passed!&lt;/b&gt;
&lt;/p&gt;

&lt;pre&gt;&amp;quot;SP&amp;quot;=dword:00000001
&amp;quot;SPIndex&amp;quot;=dword:00000001
&amp;quot;SPName&amp;quot;=&amp;quot;SP1&amp;quot;
&lt;/pre&gt;

&lt;p&gt;
Now, I didn&amp;#39;t really guess those values. I looked in a sibling registry key (...Servicing\9.0\PRO\1033) and saw
that it contained those new values, then I copied them. 
&lt;/p&gt;

&lt;p&gt;
I think I didn&amp;#39;t break anything. So far all seems to be working. But, as usual with anything related
to manual registry hacking, you have to be really insane to change your settings because you
read on a random blog on the &amp;#39;net. I&amp;#39;m just saying... Don&amp;#39;t come crying if your house burns down because of this.
&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55695" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/SQLServer/default.aspx">SQLServer</category></item><item><title>Code coverage reports with NCover and MSBuild</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/02/09/code-coverage-reports-with-ncover-and-msbuild.aspx</link><pubDate>Tue, 09 Feb 2010 18:11:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55327</guid><dc:creator>sergiopereira</dc:creator><slash:comments>7</slash:comments><description>&lt;p&gt;
I&amp;#39;ve been doing a lot of static analysis on our projects at work lately. As 
part of that task we added &lt;a href="http://www.ncover.com/"&gt;NCover&lt;/a&gt; to our automated build process. Our
build runs on Team Build (TFS) and is specified in an MSBuild file.

&lt;/p&gt;
&lt;p&gt;
We wanted to take code metrics very seriously and we purchased the 
complete version of the product to take full advantage of its 
capabilities.

&lt;/p&gt;
&lt;p&gt;
Getting NCover to run in your build is very simple and the online 
documentation will be enough to figure it out. The problem comes
when you begin needing to create more and more variations of the
reports. The online documentation is a little short on this aspect,
especially on how to use the MSBuild or NAnt custom tasks. I hear
they plan to update the site with better docs for the next version 
of the product.

&lt;/p&gt;
&lt;p&gt;
NCover Complete comes with 23 different types of reports and 
a ton of parameters that can be configured to produce far
more helpful reports than just sticking to the defaults.

&lt;/p&gt;
&lt;p&gt;
For example, we are working on a new release of our product and
we are pushing ourselves to produce more testable code and
write more unit tests for all the new code. The problem is
that the new code is a just tiny fraction of the existing code and
the metrics get averaged down by the older code.

&lt;/p&gt;
&lt;p&gt;
The key is to separate the code coverage profiling (which is
done by NCover while it runs all the unit tests with NUnit) from
the rendering of the reports. That way we only run the code coverage once; and that
can sometimes take a good chunk of time to produce the coverage data. 
Rendering the reports is much quicker since the NCover reporting engine can feed off the
coverage data as many times as we need, very quickly.

&lt;/p&gt;
&lt;p&gt;
Once we have the coverage data we can choose which report types we want 
to create, the thresholds for sufficient coverage (or to fail the build), which assemblies/types/methods
we want to include/exclude from each report and where to save each of them.

&lt;h3&gt;Example&lt;/h3&gt;

&lt;p&gt;
To demonstrate what I just described in practice, I decided to take
an existing open source project and add NCover reporting to it. The
project I selected was &lt;a href="http://www.codeplex.com/AutoMapper"&gt;AutoMapper&lt;/a&gt; mostly because it&amp;#39;s not very big
and has decent test coverage.
&lt;/p&gt;
&lt;p&gt;
I downloaded the project&amp;#39;s source code from the repository and
added a file named AutoMapper.msbuild to its root directory. You
can &lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/automapper.msbuild.zip"&gt;download 
this entire file&lt;/a&gt; but I&amp;#39;ll go over it piece by piece.
&lt;/p&gt;

&lt;p&gt;We start by just importing the MSBuild tasks that ship with NCover into our script and
declaring a few targets, including one to collect coverage data and one to generate the reports.
I added the NCover tasks dll to the project directory &lt;b&gt;tools/NCoverComplete&lt;/b&gt;.&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;&amp;lt;Project DefaultTargets=&amp;quot;RebuildReports&amp;quot; 
  xmlns=&amp;quot;http://schemas.microsoft.com/developer/msbuild/2003&amp;quot; &amp;gt;
  &amp;lt;UsingTask  TaskName=&amp;quot;NCover.MSBuildTasks.NCover&amp;quot; 
        AssemblyFile=&amp;quot;$(ProjectDir)tools\NCoverComplete\NCover.MSBuildTasks.dll&amp;quot;/&amp;gt;
  &amp;lt;UsingTask  TaskName=&amp;quot;NCover.MSBuildTasks.NCoverReporting&amp;quot; 
        AssemblyFile=&amp;quot;$(ProjectDir)tools\NCoverComplete\NCover.MSBuildTasks.dll&amp;quot;/&amp;gt;

  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;Configuration Condition=&amp;quot; &amp;#39;$(Configuration)&amp;#39; == &amp;#39;&amp;#39; &amp;quot;&amp;gt;Debug&amp;lt;/Configuration&amp;gt;
    &amp;lt;BuildDir&amp;gt;$(MSBuildProjectDirectory)\build\$(Configuration)&amp;lt;/BuildDir&amp;gt;
    &amp;lt;NUnitBinDirectoryPath&amp;gt;$(MSBuildProjectDirectory)\tools\NUnit&amp;lt;/NUnitBinDirectoryPath&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;

  &amp;lt;Target Name=&amp;quot;RebuildReports&amp;quot; DependsOnTargets=&amp;quot;RunCoverage;ExportReports&amp;quot; &amp;gt;
    &amp;lt;Message Text=&amp;quot;We will rebuild the coverage data than refresh the reports.&amp;quot; 
          Importance=&amp;quot;High&amp;quot; /&amp;gt;
  &amp;lt;/Target&amp;gt;

  &amp;lt;Target Name=&amp;quot;RunCoverage&amp;quot; &amp;gt;
    &amp;lt;!-- snip --&amp;gt;
  &amp;lt;/Target&amp;gt;

  &amp;lt;Target Name=&amp;quot;ExportReports&amp;quot; &amp;gt;
    &amp;lt;!-- snip --&amp;gt;
  &amp;lt;/Target&amp;gt;
&amp;lt;/Project&amp;gt;&lt;/pre&gt;


&lt;p&gt;
	Now let&amp;#39;s look closely at the target that gathers the coverage data. All it
	does is tell NCover (NCover console, really) to run NUnit over the
	AutoMapper.UnitTests.dll and save all the output to well-known locations.
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;&amp;lt;Target Name=&amp;quot;RunCoverage&amp;quot; &amp;gt;
  &amp;lt;Message Text=&amp;quot;Starting Code Coverage Analysis (NCover) ...&amp;quot; Importance=&amp;quot;High&amp;quot; /&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;NCoverOutDir&amp;gt;$(MSBuildProjectDirectory)\build\NCoverOut&amp;lt;/NCoverOutDir&amp;gt;
    &amp;lt;NUnitResultsFile&amp;gt;build\NCoverOut\automapper-nunit-result.xml&amp;lt;/NUnitResultsFile&amp;gt;
    &amp;lt;NUnitOutFile&amp;gt;build\NCoverOut\automapper-nunit-Out.txt&amp;lt;/NUnitOutFile&amp;gt;
    &amp;lt;InputFile&amp;gt;$(BuildDir)\UnitTests\AutoMapper.UnitTests.dll&amp;lt;/InputFile&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;

  &amp;lt;NCover ToolPath=&amp;quot;$(ProgramFiles)\NCover&amp;quot;
    ProjectName=&amp;quot;$(Scenario)&amp;quot;
    WorkingDirectory=&amp;quot;$(MSBuildProjectDirectory)&amp;quot;   
    TestRunnerExe=&amp;quot;$(NUnitBinDirectoryPath)\nunit-console.exe&amp;quot;

    TestRunnerArgs=&amp;quot;$(InputFile) /xml=$(NUnitResultsFile) /out=$(NUnitOutFile)&amp;quot;

    AppendTrendTo=&amp;quot;$(NCoverOutDir)\automapper-coverage.trend&amp;quot;
    CoverageFile=&amp;quot;$(NCoverOutDir)\automapper-coverage.xml&amp;quot;
    LogFile=&amp;quot;$(NCoverOutDir)\automapper-coverage.log&amp;quot;
    IncludeTypes=&amp;quot;AutoMapper\..*&amp;quot;
    ExcludeTypes=&amp;quot;AutoMapper\.UnitTests\..*;AutoMapper\.Tests\..*&amp;quot;
    SymbolSearchLocations=&amp;quot;Registry, SymbolServer, BuildPath, ExecutingDir&amp;quot;
  /&amp;gt;
&amp;lt;/Target&amp;gt;&lt;/pre&gt;

&lt;p&gt;
	Of special interest in the NCover task above are the output files named
	&lt;b&gt;automapper)-coverage.xml&lt;/b&gt; and &lt;b&gt;automapper-coverage.trend&lt;/b&gt;, which
	contain the precious coverage data and historical trending respectively. In case
	you&amp;#39;re curious, the trend file is actually a SQLite3 database file that you
	can report directly from or export to other database formats if you want.
&lt;/p&gt;
&lt;p&gt;
	Also note the &lt;code&gt;IncludeTypes&lt;/code&gt; and &lt;code&gt;ExcludeTypes&lt;/code&gt; parameters,
	which guarantee that we are not tracking coverage on code that we don&amp;#39;t care about.
&lt;/p&gt;

&lt;p&gt;
	Now that we have our coverage and trend data collected and saved to
	files we know, we can run as many reports as we want without needing
	to execute the whole set of tests again. That&amp;#39;s in the next target.
&lt;/p&gt;


&lt;pre name="code" class="xml:nogutter"&gt;&amp;lt;Target Name=&amp;quot;ExportReports&amp;quot; &amp;gt;
  &amp;lt;Message Text=&amp;quot;Starting Producing NCover Reports...&amp;quot; Importance=&amp;quot;High&amp;quot; /&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;Scenario&amp;gt;AutoMapper-Full&amp;lt;/Scenario&amp;gt;
    &amp;lt;NCoverOutDir&amp;gt;$(MSBuildProjectDirectory)\build\NCoverOut&amp;lt;/NCoverOutDir&amp;gt;
    &amp;lt;RptOutFolder&amp;gt;$(NCoverOutDir)\$(Scenario)Coverage&amp;lt;/RptOutFolder&amp;gt;
    &amp;lt;Reports&amp;gt;
      &amp;lt;Report&amp;gt;
        &amp;lt;ReportType&amp;gt;FullCoverageReport&amp;lt;/ReportType&amp;gt;
        &amp;lt;OutputPath&amp;gt;$(RptOutFolder)\Full\index.html&amp;lt;/OutputPath&amp;gt;
        &amp;lt;Format&amp;gt;Html&amp;lt;/Format&amp;gt;
      &amp;lt;/Report&amp;gt;
      &amp;lt;Report&amp;gt;
        &amp;lt;ReportType&amp;gt;SymbolModuleNamespaceClass&amp;lt;/ReportType&amp;gt;
        &amp;lt;OutputPath&amp;gt;$(RptOutFolder)\ClassCoverage\index.html&amp;lt;/OutputPath&amp;gt;
        &amp;lt;Format&amp;gt;Html&amp;lt;/Format&amp;gt;
      &amp;lt;/Report&amp;gt;
      &amp;lt;Report&amp;gt;
        &amp;lt;ReportType&amp;gt;Trends&amp;lt;/ReportType&amp;gt;
        &amp;lt;OutputPath&amp;gt;$(RptOutFolder)\Trends\index.html&amp;lt;/OutputPath&amp;gt;
        &amp;lt;Format&amp;gt;Html&amp;lt;/Format&amp;gt;
      &amp;lt;/Report&amp;gt;
    &amp;lt;/Reports&amp;gt;
    &amp;lt;SatisfactoryCoverage&amp;gt;
      &amp;lt;Threshold&amp;gt;
        &amp;lt;CoverageMetric&amp;gt;MethodCoverage&amp;lt;/CoverageMetric&amp;gt;
        &amp;lt;Type&amp;gt;View&amp;lt;/Type&amp;gt;
        &amp;lt;Value&amp;gt;80.0&amp;lt;/Value&amp;gt;
      &amp;lt;/Threshold&amp;gt;
      &amp;lt;Threshold&amp;gt;
        &amp;lt;CoverageMetric&amp;gt;SymbolCoverage&amp;lt;/CoverageMetric&amp;gt;
        &amp;lt;Value&amp;gt;80.0&amp;lt;/Value&amp;gt;
      &amp;lt;/Threshold&amp;gt;
      &amp;lt;Threshold&amp;gt;
        &amp;lt;CoverageMetric&amp;gt;BranchCoverage&amp;lt;/CoverageMetric&amp;gt;
        &amp;lt;Value&amp;gt;80.0&amp;lt;/Value&amp;gt;
      &amp;lt;/Threshold&amp;gt;
      &amp;lt;Threshold&amp;gt;
        &amp;lt;CoverageMetric&amp;gt;CyclomaticComplexity&amp;lt;/CoverageMetric&amp;gt;
        &amp;lt;Value&amp;gt;8&amp;lt;/Value&amp;gt;
      &amp;lt;/Threshold&amp;gt;
    &amp;lt;/SatisfactoryCoverage&amp;gt;

  &amp;lt;/PropertyGroup&amp;gt;

  &amp;lt;NCoverReporting 
    ToolPath=&amp;quot;$(ProgramFiles)\NCover&amp;quot;
    CoverageDataPaths=&amp;quot;$(NCoverOutDir)\automapper-coverage.xml&amp;quot;
    LoadTrendPath=&amp;quot;$(NCoverOutDir)\automapper-coverage.trend&amp;quot;
    ProjectName=&amp;quot;$(Scenario) Code&amp;quot;
    OutputReport=&amp;quot;$(Reports)&amp;quot;
    SatisfactoryCoverage=&amp;quot;$(SatisfactoryCoverage)&amp;quot;
  /&amp;gt;
&amp;lt;/Target&amp;gt;&lt;/pre&gt;

&lt;p&gt;
	What you can see in this target is that we are creating three different
	reports, represented by the &lt;code&gt;Report&lt;/code&gt; elements and that
	we are changing the satisfactory threshold to 80% code coverage 
	(down from the default of 95%) and the maximum cyclomatic complexity 
	to 8. These two blocks of configuration are passer to the NCoverReporting
	task via the parameters &lt;code&gt;OutputReport&lt;/code&gt; and &lt;code&gt;SatisfactoryCoverage&lt;/code&gt;, 
	respectively.
&lt;/p&gt;

&lt;p&gt;
	The above reports are shown in the images below.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_full.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_full_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;

&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_class.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_class_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_trend.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.02/ncover_2D00_trend_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;
&lt;/p&gt;


&lt;h3&gt;Focus on specific areas&lt;/h3&gt;

&lt;p&gt;
	Let&amp;#39;s now say that, in addition to the reports for the entire source code, we
	also want to keep a closer eye on the classes under the &lt;code&gt;AutoMapper.Mappers&lt;/code&gt;
	namespace. We can get that going with another reporting target, filtering the reported
	data down to just the code we are interested in:
&lt;/p&gt;

&lt;pre name="code" class="xml:nogutter"&gt;&amp;lt;Target Name=&amp;quot;ExportReportsMappers&amp;quot; &amp;gt;
  &amp;lt;Message Text=&amp;quot;Reports just for the Mappers&amp;quot; Importance=&amp;quot;High&amp;quot; /&amp;gt;
  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;Scenario&amp;gt;AutoMapper-OnlyMappers&amp;lt;/Scenario&amp;gt;
    &amp;lt;NCoverOutDir&amp;gt;$(MSBuildProjectDirectory)\build\NCoverOut&amp;lt;/NCoverOutDir&amp;gt;
    &amp;lt;RptOutFolder&amp;gt;$(NCoverOutDir)\$(Scenario)Coverage&amp;lt;/RptOutFolder&amp;gt;
    &amp;lt;Reports&amp;gt;
      &amp;lt;Report&amp;gt;
        &amp;lt;ReportType&amp;gt;SymbolModuleNamespaceClass&amp;lt;/ReportType&amp;gt;
        &amp;lt;OutputPath&amp;gt;$(RptOutFolder)\ClassCoverage\index.html&amp;lt;/OutputPath&amp;gt;
        &amp;lt;Format&amp;gt;Html&amp;lt;/Format&amp;gt;
      &amp;lt;/Report&amp;gt;
      &amp;lt;!-- add more Report elements as desired --&amp;gt;
    &amp;lt;/Reports&amp;gt;
    &amp;lt;CoverageFilters&amp;gt;
      &amp;lt;Filter&amp;gt;
        &amp;lt;Pattern&amp;gt;AutoMapper\.Mappers\..*&amp;lt;/Pattern&amp;gt;
        &amp;lt;Type&amp;gt;Class&amp;lt;/Type&amp;gt;
        &amp;lt;IsRegex&amp;gt;True&amp;lt;/IsRegex&amp;gt;
        &amp;lt;IsInclude&amp;gt;True&amp;lt;/IsInclude&amp;gt;
      &amp;lt;/Filter&amp;gt;
      &amp;lt;!-- include/exclude more classes, assemblies, namespaces, 
      methods, files as desired --&amp;gt;
    &amp;lt;/CoverageFilters&amp;gt;

  &amp;lt;/PropertyGroup&amp;gt;

  &amp;lt;NCoverReporting 
    ToolPath=&amp;quot;$(ProgramFiles)\NCover&amp;quot;
    CoverageDataPaths=&amp;quot;$(NCoverOutDir)\automapper-coverage.xml&amp;quot;
    ClearCoverageFilters=&amp;quot;true&amp;quot;
    CoverageFilters=&amp;quot;$(CoverageFilters)&amp;quot;
    LoadTrendPath=&amp;quot;$(NCoverOutDir)\automapper-coverage.trend&amp;quot;
    ProjectName=&amp;quot;$(Scenario) Code&amp;quot;
    OutputReport=&amp;quot;$(Reports)&amp;quot;
  /&amp;gt;
&amp;lt;/Target/&amp;gt;&lt;/pre&gt;

&lt;p&gt;
	Now that we have this basic template our plan is to identify
	problem areas in the code and create reports aimed at them.
	The URLs of the reports will be included in the CI build reports 
	and notification emails.
&lt;/p&gt;
&lt;p&gt;
	It&amp;#39;s so easy to add more reports that we will have reports
	that will live for a single release cycle or even less if
	we need it.
&lt;/p&gt;
&lt;p&gt;
	I hope this was helpful for more people because it did take
	a good amount of time to get it all sorted out. Even if
	you&amp;#39;re using NAnt instead of MSBuild, the syntax is
	similar and I&amp;#39;m sure you can port the idea easily.
&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55327" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/.NET/default.aspx">.NET</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Automation/default.aspx">Automation</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/UnitTesting/default.aspx">UnitTesting</category></item><item><title>How to detect the text encoding of a file</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/01/26/how-to-detect-the-text-encoding-of-a-file.aspx</link><pubDate>Wed, 27 Jan 2010 01:18:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:55142</guid><dc:creator>sergiopereira</dc:creator><slash:comments>10</slash:comments><description>&lt;p&gt;
Today I needed a way to identify ANSI (Windows-1252) and UTF-8 files in a directory filled with files of
these two types. I was surprised to not find a simple way of doing this via a property of method somewhere
under the &lt;code&gt;System.IO&lt;/code&gt; namespace.
&lt;/p&gt;
&lt;p&gt;
Not that it&amp;#39;s that hard to identify the encoding programmatically, but it&amp;#39;s always better when you
don&amp;#39;t need to write a method yourself. Anyway, here&amp;#39;s what I came up with. It detects UTF-8 encoding
based on the encoding signature added to the beginning of the file.
&lt;/p&gt;
&lt;p&gt;
The code below is specific to UTF-8 but shouldn&amp;#39;t be too hard to extend the example to
detect more encodings.
&lt;/p&gt;
&lt;pre name="code" class="csharp:nogutter"&gt;public static bool IsUtf8(string fname){
  using(var f = File.Open(fname, FileMode.Open)){
    var sig = new byte[Encoding.UTF8.GetPreamble().Length];
    f.Read(sig, 0, sig.Length);
    return sig.SequenceEqual(Encoding.UTF8.GetPreamble());
  }
}&lt;/pre&gt;

&lt;p&gt;
Maybe I just looked in the wrong places. Does anyone know a simpler way in the framework to accomplish this?
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=55142" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/.NET/default.aspx">.NET</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Oh, no. My TortoiseSVN overlays are missing</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2010/01/05/oh-no-my-tortoisesvn-overlays-are-missing.aspx</link><pubDate>Tue, 05 Jan 2010 09:13:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:54881</guid><dc:creator>sergiopereira</dc:creator><slash:comments>24</slash:comments><description>	&lt;p&gt;It&amp;#39;s a matter of time. Good were the days when almost no application
	knew how to put overlays on your file icons in Explorer. These days it
	seems this is the coolest thing ever and virtually all file system type
	of utilities&lt;a href="http://stackoverflow.com/questions/843506/shell-icon-overlay-c"&gt; want to add their own&lt;/a&gt;.&lt;/p&gt;

	&lt;p&gt;Sooner or later you will install some utility and not notice anything different. But
	after the next reboot, poof, your &lt;a href="http://tortoisesvn.net/"&gt;TortoiseSVN&lt;/a&gt; overlays are gone. And,
       depending on
	how much time elapsed between the utility installation and that reboot,
	you may not have the slightest clue of what happened. Reinstalling
	TSVN won&amp;#39;t fix it&lt;/p&gt;

	&lt;h3&gt;TFS Power tools, Dropbox, Mozy, stop breaking my TSVN overlays&lt;/h3&gt;

	&lt;p&gt;I should not blame these applications for a Windows shell
	limitation. To be fair, TSVN is the greater offender of them all.&lt;/p&gt;

	&lt;p&gt;It seems that the shell only supports 15 different
	icon overlays and TSVN creates 9 of those. After 15 the 
	shell starts ignoring the extra ones. The trick is that
	Windows chooses the first 15 alphabetically from their entries in
	the system registry.&lt;/p&gt;

	&lt;h3&gt;I love simple fixes&lt;/h3&gt;

	&lt;p&gt;The fix is rather obvious; just make sure the overlays you
	want to be active are registered alphabetically before the
	ones you can live without.&lt;/p&gt;

	&lt;p&gt;Open the registry editor and go to 
	&lt;b&gt;HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers&lt;/b&gt;
	and look at all the child keys in there. It will be obvious that, if you want to
	preserve the TSVN overlays like me, you need to keep the ones starting with Tortoise*
	before the other ones. 
	&lt;/p&gt;
	&lt;p&gt;If you look at the image below you&amp;#39;ll see that I changed my entries by
	prefixing the undesirable ones with &lt;b&gt;z_&lt;/b&gt;, following 
	&lt;a href="http://blog.falafel.com/2009/12/17/WindowsIconOverlayLimitations.aspx"&gt;someone else&amp;#39;s suggestion&lt;/a&gt;.&lt;/p&gt;

	&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2010.01/registry_2D00_overlays.PNG" alt="" /&gt;&lt;/p&gt;

	&lt;p&gt;After that change you just need to kill and restart explorer.exe using Task Manager (or
	logoff or reboot the machine depending on your tolerance to pain.)
	&lt;/p&gt;

	&lt;p&gt;
		I believe this is a common problem so I hope this tip helps somebody.
	&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=54881" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>IE6 still haunts me</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/10/21/ie6-still-haunts-me.aspx</link><pubDate>Wed, 21 Oct 2009 22:16:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:52894</guid><dc:creator>sergiopereira</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;Oh, the woes of supporting IE6 (or, better put, IE666 &amp;mdash; the browser of the beast.)&lt;/p&gt;

&lt;p&gt;
	Halloween is definitely upon us. Today I spent a good chunk of time trying to identify the source of a problem in
	my application. Right now I&amp;#39;m in the process of jQuery-fying some legacy JavaScript,
	which includes Ajax calls and error handling logic.
&lt;/p&gt;
&lt;p&gt;
	At some point I needed to pop-up a DIV that was supposed to look like a modal message box,
	reporting some error that happened during the Ajax call. That was not hard at all. I used
	the &lt;a href="http://www.ericmmartin.com/projects/simplemodal/"&gt;SimpleModal&lt;/a&gt; plugin and
	got the message box up in not time at all.
&lt;/p&gt;
&lt;h3&gt;Not so fast, you have IE6 users&lt;/h3&gt;
&lt;p&gt;
	As with many web developers out there, I don&amp;#39;t have the luxury of ignoring IE6 users because
	they are upwards of 60% of our user base (corporate users that for some reason can&amp;#39;t easily
	upgrade their browsers.)
&lt;/p&gt;
&lt;p&gt;
	I thought it wouldn&amp;#39;t be a problem because the SimpleModal plugin handles a number of IE6 issues,
	including the insertion of an &lt;code&gt;IFrame&lt;/code&gt; to overcome the bleedthrough of &lt;code&gt;Select&lt;/code&gt; tags.
	But of course it couldn&amp;#39;t be that easy right?
&lt;/p&gt;
&lt;p&gt;
In some of my tests IE6 was simply &lt;b&gt;crashing&lt;/b&gt; when I tried to open the &amp;quot;modal&amp;quot; message. After a lot or hair 
pulling, I saw this suspicious HTML in one of my messages:
&lt;/p&gt;
&lt;pre name="code" class="html"&gt;&amp;lt;table style=&amp;quot;font-size: expression(parentnode.currentstyle.fontsize);&amp;quot; &amp;gt;
    &amp;lt;!-- rest of the table is normal --&amp;gt;
&amp;lt;/table&amp;gt;&lt;/pre&gt;

&lt;p&gt;
	Sure enough, moving that &lt;i&gt;hack&lt;/i&gt; to a proper CSS rule in the external .css file made the error go away.
	We shouldn&amp;#39;t be using dynamic CSS expressions anyway, since 
	&lt;a href="http://blogs.msdn.com/ie/archive/2008/10/16/ending-expressions.aspx"&gt;they were removed from IE8&lt;/a&gt;, 
	so I went ahead and ditched that kind of usage wherever I could find it.
&lt;/p&gt;

&lt;p&gt;This is just to keep us on our toes regarding IE6 support. Even though the modern JavaScript libraries go
to great lengths to support IE6 and make our coding transparent, nothing substitutes good old manual testing
to make sure IE6 doesn&amp;#39;t play pranks on us in production.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=52894" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>JavaScript and its love for zeroes</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/09/19/javascript-and-its-love-for-zeroes.aspx</link><pubDate>Sat, 19 Sep 2009 13:54:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:51520</guid><dc:creator>sergiopereira</dc:creator><slash:comments>6</slash:comments><description>&lt;div class="note"&gt;
	This post is part of a series called &lt;a href="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript-Demystified/default.aspx"&gt;
	JavaScript Demystified&lt;/a&gt;.
&lt;/div&gt;

&lt;p&gt;Answer quick. Do you know what date is being created here?&lt;/p&gt;
&lt;pre name="code" class="js:nogutter"&gt;var year = &amp;#39;2009&amp;#39;, month = &amp;#39;09&amp;#39;, day = &amp;#39;01&amp;#39;;
var date = new Date( 
             parseInt(year),
			 parseInt(month),
			 parseInt(day)
			 );	&lt;/pre&gt;

&lt;p&gt;
At first glance, it wouldn&amp;#39;t surprising that someone guesseed &lt;i&gt;September 1&lt;sup&gt;st&lt;/sup&gt; 2009&lt;/i&gt;.
However, I&amp;#39;d not be writing this post if that was the correct answer, right?
&lt;/p&gt;
&lt;p&gt;
There&amp;#39;s an interesting and tricky thing with the JavaScript &lt;code&gt;parseInt&lt;/code&gt; function: it
can parse strings with a numeric value in the decimal radix, but also in other radices. See the
following examples.
&lt;/p&gt;

&lt;pre name="code" class="js:nogutter"&gt;//passing the radix explicitly
parseInt(&amp;#39;1011&amp;#39;, 10); // ==&amp;gt; 1011
parseInt(&amp;#39;1011&amp;#39;,  2); // ==&amp;gt; 11
parseInt(&amp;#39;1011&amp;#39;,  8); // ==&amp;gt; 521
parseInt(&amp;#39;1011&amp;#39;, 16); // ==&amp;gt; 4113
&lt;/pre&gt;

&lt;p&gt;Maybe you thought that if you didn&amp;#39;t pass the radix, then it would default to 10 because
it&amp;#39;s the obvious behavior. Well, no. In JavaScript the default behavior is to try to
identify one of the literal formats and interpret that. So here&amp;#39;s that in action:&lt;/p&gt;

&lt;pre name="code" class="js:nogutter"&gt;//leaving JavaScript on its own
parseInt(&amp;#39;1011&amp;#39;); // ==&amp;gt; 1011 (decimal literal)
parseInt(&amp;#39;0x12&amp;#39;); // ==&amp;gt; 18   (hexadecimal literal)
parseInt(&amp;#39;0511&amp;#39;); // ==&amp;gt; 329  (octal literal)
parseInt(&amp;#39;0182&amp;#39;); // ==&amp;gt; 1    (whaaaa?!?!)
&lt;/pre&gt;

&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.09/js_2D00_newyear.png" align="left" alt="" /&gt;

&lt;p&gt;
If you are familiar with the literal notation for integer numbers in JavaScript,
and after I explained the default behavior of &lt;code&gt;parseInt&lt;/code&gt;, then
you probaly understood the results shown above. Well, maybe the last one deserves 
some comments.
&lt;/p&gt;
&lt;p&gt;
When JavaScript is parsing the string, if it finds a digit (number or alpha) that is invalid
in the chosen radix, it stops right there and parses only the portion of the string that
comes before that digit. So, since we started &lt;code&gt;&amp;#39;0182&amp;#39;&lt;/code&gt; with a leading zero, the 
octal radix is assumed. Then, because &lt;b&gt;8&lt;/b&gt; is not a valid octal digit, only &lt;code&gt;&amp;#39;01&amp;#39;&lt;/code&gt;
will be parsed, which becomes &lt;b&gt;1&lt;/b&gt;.
&lt;/p&gt;

&lt;div class="note"&gt;&lt;span class="legend"&gt;Tip #1:&lt;/span&gt;
If there&amp;#39;s any chance the string value you plan to parse into an integer number has
a leading zero (or a less likely &lt;b&gt;0x&lt;/b&gt;,) then be safe and pass the radix parameter
to your &lt;code&gt;parseInt&lt;/code&gt; call. If you&amp;#39;re extra paranoid, then always pass the radix.
&lt;/div&gt;


&lt;h3&gt;Back to our original question&lt;/h3&gt;

&lt;p&gt;Armed with the clarification made above, we can expand our example like this:&lt;/p&gt;
&lt;pre name="code" class="js:nogutter"&gt;//given:
var year = &amp;#39;2009&amp;#39;, month = &amp;#39;09&amp;#39;, day = &amp;#39;01&amp;#39;;
// then the following statement:
var date = new Date( 
         parseInt(year),
         parseInt(month),
         parseInt(day)
         );	
//...is equivalent to:
var date = new Date( 
         2009,
         0,  // ===&amp;gt; oopsie
         1
         );	&lt;/pre&gt;

&lt;p&gt;Hmmm, a zero in the month parameter. Will we have an error here? No, here comes the second potential surprise of this post.&lt;/p&gt;

&lt;div class="note"&gt;&lt;span class="legend"&gt;Tip #2:&lt;/span&gt;
When creating a new date using &lt;code&gt;new Date(year, month, day)&lt;/code&gt;, the &lt;code&gt;month&lt;/code&gt;
parameter, and &lt;b&gt;only&lt;/b&gt; the month parameter is zero-based (0 to 11).
&lt;/div&gt;

&lt;p&gt;So, in case the tips and the picture in this text were not enough to help you guessing the
date being created, here goes another completely gratuitous one with the answer.

&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.09/js_2D00_newyear2.png" alt="" /&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=51520" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript-Demystified/default.aspx">JavaScript-Demystified</category></item><item><title>Taming Firebug with Profiles</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/09/01/taming-firebug-with-profiles.aspx</link><pubDate>Tue, 01 Sep 2009 10:03:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:50941</guid><dc:creator>sergiopereira</dc:creator><slash:comments>1</slash:comments><description>	&lt;p&gt;
		This is a tip for anyone using Firefox and &lt;a href="http://getfirebug.com/" title="Firebug - Web Development Evolved"&gt;Firebug&lt;/a&gt; for web development
		that is not leveraging the Profiles feature of that browser. 
	&lt;/p&gt;
	&lt;p&gt;
		Recent versions of Firebug (after v1.3 I think) removed the ability to enable Firebug panes
		on a per-domain basis. Now it&amp;#39;s kind of all or nothing. And you know
		that you don&amp;#39;t want to have Firebug enabled when using Ajax-intensive
		applications like GMail, for example. 
	&lt;/p&gt;
	&lt;p&gt;
		The end result is that you are stuck in this annoying dance of of enabling/disabling,
		open/close Firebug when switching tabs.
	&lt;/p&gt;
	&lt;p&gt;
		There are some workarounds for that but I think the best solution for this problem
		is through &lt;a href="http://support.mozilla.com/en-US/kb/Profiles"&gt;Profiles&lt;/a&gt;, which is also a very nice approach for web development overall.
	&lt;/p&gt;
	
	&lt;h3&gt;Firefox Profiles&lt;/h3&gt;
	&lt;p&gt;
		Firefox stores all your preferences (add-ons, state, saved passwords, history, etc)
		inside profile directories. 
		It installs a default profile and that&amp;#39;s perfectly enough
		for the casual browser user. Web developers, add-on developers, and power users in
		general, on the other hand, can find handy uses for extra profiles.
	&lt;/p&gt;
	&lt;p&gt;
		You can see your profile directories in &lt;b&gt;%APPDATA%\Mozilla\Firefox\Profiles&lt;/b&gt;
		(or, on the Mac, &lt;b&gt;~/Library/Application Support/Firefox/Profiles&lt;/b&gt;).
	&lt;/p&gt;
	&lt;h3&gt;Development profile&lt;/h3&gt;
	&lt;p&gt;
		The suggestion I&amp;#39;m giving is to create a separate profile just to be used during web
		development work. That way you can exclude some of the add-ons (like ad blockers, 
		bookmarking extensions like Delicious, and any other non development-related extensions.)
		The opposite applies to your default profile &amp;mdash; you can now remove all the 
		development stuff from that profile and keep your browser a little lighter. In addition to that
                I use a different skin/theme in each profile, just to make it screaming obvious which one I&amp;#39;m 
                looking at.
	&lt;/p&gt;
	&lt;p&gt;
		Here&amp;#39;s how we create a new profile. First close all your Firefox windows and make sure 
		there&amp;#39;s no Firefox process running in the background. Now go to the command line 
		and enter this:
	&lt;/p&gt;
	&lt;pre&gt;(on Windows)
%ProgramFiles%\Mozilla Firefox\firefox.exe -ProfileManager
(or on the Mac)
/Applications/Firefox.app/Contents/MacOS/firefox -ProfileManager&lt;/pre&gt;
	
	&lt;p&gt;
		This will bring up the Profile Manager, where you can easily create a new
		profile. Create one named &lt;i&gt;Development&lt;/i&gt; and start it. 
	&lt;/p&gt;
&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.09/profiles.png" alt="" /&gt;&lt;/p&gt;
	&lt;p&gt;
		Once started, you&amp;#39;ll notice that Firefox will open looking just like it did
		the first time you installed it. You can now install your favorite extensions
		for web development (like Firebug, &lt;a href="http://developer.yahoo.com/yslow/" title="Yahoo! YSlow for Firebug"&gt;YSlow&lt;/a&gt;, 
		&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/60"&gt;Web Developer Toolbar&lt;/a&gt;, 
		&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/59"&gt;User Agent Switcher&lt;/a&gt;,  etc)
	&lt;/p&gt;
	&lt;p&gt;
		To launch Firefox using the the Development profile you can create a shortcut
		that passes some arguments to Firefox, like &lt;b&gt;firefox.exe -P Development -no-remote&lt;/b&gt;.
		For example, I added that shortcut to my Desktop, Quick Launch, and Launchy. &lt;i&gt;(Firefox will
               remember which profile you started last using the Profile Manager, and use that one
               next time you start Firefox without explicitly choosing a profile. You may want to leave the default profile 
               selected in the Profile Manager.)&lt;/i&gt;
	&lt;/p&gt;
	
	&lt;h3&gt;More uses for Profiles&lt;/h3&gt;
	&lt;p&gt;
		Besides creating a profile dedicated to web development work, I can very well see
		myself eventually creating extra ones for different activities, like a &lt;i&gt;Presentation&lt;/i&gt; profile and
		a &lt;i&gt;NoAddons&lt;/i&gt; profile, for example. 
	&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=50941" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tools/default.aspx">Tools</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Circular Refactoring</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/08/14/circular-refactoring.aspx</link><pubDate>Fri, 14 Aug 2009 17:21:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:50065</guid><dc:creator>sergiopereira</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;One of these days I was chatting with &lt;a href="http://devlicio.us/blogs/Derik_whittaker/"&gt;Derik&lt;/a&gt; and we were
talking about refactoring and when to stop refactoring. We thought it
was funny (and embarrassing) how sometimes, after a few consecutive refactorings,
we are back at the starting point.&lt;/p&gt;

&lt;p&gt;This type of &lt;b&gt;Circular Refactoring&lt;/b&gt; is a real productivity enemy. In our
genuine desire to improve the code, and wishing to dive into an interesting task,
we sometimes lose sight of the code history and the real need for this change. It reminds 
me a lot of &lt;a href="http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered/482129#482129"&gt;this funny comment&lt;/a&gt; (second part).&lt;/p&gt;

&lt;p&gt;How do you tell when you&amp;#39;re being a victim of this variation of the premature
optimization monster? Well, here&amp;#39;s a start:
&lt;/p&gt;

&lt;h3&gt;Top 10 signs you&amp;#39;ve fallen into circular refactoring&lt;/h3&gt;

&lt;div style="background-color:#eee;border:solid 1px #aaa;padding:4px;"&gt;
&lt;b&gt;
9 - Code gets eerily familiar by the minute.&lt;br /&gt;
8 - Your git repository doesn&amp;#39;t seem to grow.&lt;br /&gt;
7 - Work feels too much fun to be real.&lt;br /&gt;
6 - Your code metrics trending charts look like Bart Simpson&amp;#39;s hair.&lt;br /&gt;
5 - You&amp;#39;re never breaking any of your unit tests after each change.&lt;br /&gt;
4 - You&amp;#39;ve created macros in the IDE to help with almost all the steps.&lt;br /&gt;
3 - You&amp;#39;re refactoring your macros.&lt;br /&gt;
2 - Clippy is asking if you&amp;#39;ve heard about the &amp;quot;svn merge&amp;quot; command.&lt;br /&gt;
1 - TFS, on the other hand, still can&amp;#39;t offer you much help.&lt;br /&gt;
0 - Your Find/Replace drop-downs seem to read your mind.&lt;br /&gt;
&lt;/b&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=50065" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Resharper Test Runner in 64-bit Windows</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/07/20/resharper-test-runner-in-64-bit-windows.aspx</link><pubDate>Tue, 21 Jul 2009 00:47:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:49502</guid><dc:creator>sergiopereira</dc:creator><slash:comments>4</slash:comments><description>&lt;p&gt;In the spirit of helping the next guy, here&amp;#39;s some explanation for a problem that 
was surprising to me.&lt;/p&gt;

&lt;p&gt;We have recently upgraded our product to 64-bits and all developer workstations 
to Windows 2008 x64. The transition was easy and most things worked with minor or no
tweak at all. We&amp;#39;re still battling a &lt;a href="http://www.mail-archive.com/oztfs@oztfs.com/msg00493.html"&gt;TFS issue&lt;/a&gt; 
but that will be the subject for another day, once we figure it out.&lt;/p&gt;

&lt;p&gt;I noticed that a bunch of my unit test cases were failing when I ran them
using &lt;a href="http://www.jetbrains.com/resharper/features/unit_testing.html"&gt;Resharper&amp;#39;s test runner&lt;/a&gt;. I traced the 
problem down to missing registry values that were needed by the tests. The 
intriguing part was that I could see the registry settings there (see image below)
and the tests were working fine using &lt;a href="http://www.nunit.org/index.php?p=nunit-gui&amp;amp;r=2.5"&gt;NUnit&amp;#39;s GUI runner&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.07/reg64.png" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;After a little poking around, I saw this in Process Explorer:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.07/procs.png" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;Hmmm. Visual Studio and Resharper run as 32-bit processes and NUnit&amp;#39;s (and my application itself) as 64-bit ones. 
Could there be a difference between Registry access for 32-bit vs. 64-bit processes?
&lt;a href="http://support.microsoft.com/kb/896459"&gt;Yessir&lt;/a&gt;. It turns out that my settings were in the right place
but Windows was redirecting the 32-bit Registry accesses to the path shown below, which is obviously empty.
&lt;/p&gt;
&lt;p&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.07/reg32.png" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;I don&amp;#39;t know of any elegant work-around for this issue but for now I&amp;#39;m simply duplicating the
values in both places for the sake of testing. I&amp;#39;m not happy with this duplication but it&amp;#39;s got me 
back on track until someone bright chimes in with a better alternative.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=49502" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/.NET/default.aspx">.NET</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tools/default.aspx">Tools</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Git, SSH, PuTTY, GitHub, Unfuddle, the kitchen sink</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/05/06/git-ssh-putty-github-unfuddle-the-kitchen-sink.aspx</link><pubDate>Wed, 06 May 2009 09:09:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:46514</guid><dc:creator>sergiopereira</dc:creator><slash:comments>16</slash:comments><description>&lt;p&gt;
   After reading a good number of the guides for getting 
   &lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt;/
   &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt;/
   &lt;a href="http://unfuddle.com"&gt;Unfuddle&lt;/a&gt; working correctly in Windows,
   I finally got it sorted out. I had to use a bunch of things I had not
   used before so I realized it&amp;#39;s probably a good idea to share my findings, hoping
   to help someone else (and maybe myself again) in the future.
&lt;/p&gt;

&lt;h3&gt;Local git is easier&lt;/h3&gt;
&lt;p&gt;
	Getting Git to run locally in Windows is not hard. It gets a little
	trickier when you want to work with remote repositories. Especially
	if, like me, you have little or no experience using SSH in Windows.
&lt;/p&gt;
&lt;p&gt;
	In this post I&amp;#39;ll install and configure the tools that enable Git
	to work with remote repositories (e.g. post changes to a server), which 
	I think is probably what a lot of people will want to do, even if you&amp;#39;re just 
	toying with Git or evaluating it.
&lt;/p&gt;

&lt;h3&gt;You will need SSH for serious Gitting&lt;/h3&gt;
&lt;p&gt;
	The way Git will authenticate and communicate with hosted repositories like GitHub or 
	Unfuddle is through an &lt;a href="http://en.wikipedia.org/wiki/Secure_Shell"&gt;SSH&lt;/a&gt;
	tunnel. That means we will need an SSH client to connect to the server
	and Git will use that connection to securely transfer the repository data
	up and down.
&lt;/p&gt;
&lt;p&gt;
	In Linux or on the Mac, SSH is a trivial thing. It&amp;#39;s just part of the default
	installation. For whatever reason, Windows does not come with an SSH client, so
	we need to find ourselves a 3rd party client.
&lt;/p&gt;


&lt;h3&gt;PuTTY, a family of tools&lt;/h3&gt;
&lt;p&gt;
	Luckily for us, there&amp;#39;s a free and very popular SSH client for Windows,	called
	&lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/"&gt;PuTTY&lt;/a&gt;. PuTTY is
	actually a family of utilities that play together to configure and establish
	SSH (and Telnet) connections.
&lt;/p&gt;
&lt;p&gt;
	From the PuTTY &lt;a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html"&gt;downloads
	page&lt;/a&gt; get the following programs and put somewhere in your hard disk. I like to put these
	types of things in a c:\tools\bin directory, which is included in my &lt;code&gt;%PATH%&lt;/code&gt;.
&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe"&gt;putty.exe&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe"&gt;plink.exe&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://the.earth.li/~sgtatham/putty/latest/x86/pageant.exe"&gt;pageant.exe&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href="http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe"&gt;puttygen.exe&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Create your SSH key pair&lt;/h3&gt;
&lt;p&gt;
	The most common way to authenticate your SSH connection with the server is
	using an &lt;a href="http://en.wikipedia.org/wiki/RSA"&gt;RSA&lt;/a&gt; key pair. The
	pair contains a public key and a private key. Typically these keys will be
	stored in two files &amp;mdash; make sure that the private key file is in a
	directory location that only your user account has rights. I&amp;#39;m gonna
	keep both files in &lt;code&gt;%USERPROFILE%\SSH&lt;/code&gt; (type &lt;code&gt;echo %USERPROFILE%&lt;/code&gt;
	in a command window to see where yours is.)
&lt;/p&gt;
&lt;p&gt;
	To create a key pair we will use &lt;i&gt;puttygen.exe&lt;/i&gt;. Just click &lt;i&gt;Generate&lt;/i&gt; and then
	&lt;i&gt;Save public key&lt;/i&gt; and &lt;i&gt;Save private key&lt;/i&gt;. I chose to leave the password blank
	and trust that my directory security is enough to protect my keys. Let&amp;#39;s assume I saved 
	my keys at &lt;code&gt;%USERPROFILE%\SSH\private.ppk&lt;/code&gt; and &lt;code&gt;%USERPROFILE%\SSH\public.ppk&lt;/code&gt;, 
	respectively.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/puttygen.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/puttygen_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;We&amp;#39;re not done with PuTTY yet&lt;/h3&gt;
&lt;p&gt;
	Before starting an SSH connection with PuTTY, we need to run Pageant.exe. Pageant is a
	background process that will handle the authentication requests. We will add our private key(s)
	in Pageant and it will keep them available for new connections, without the need to
	retype the password (if you entered one) every single time.
&lt;/p&gt;
&lt;p&gt;
	Run Pageant.exe, double click its icon in the notification area, and add your private key file.
	If you specified a password, it will now prompt you for that.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/pageant_2D00_1.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/pageant_2D00_1_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;
	Phew! We are done with the SSH crap. Now on to Git. Finally.
&lt;/p&gt;

&lt;h3&gt;Git via msysgit&lt;/h3&gt;
&lt;p&gt;
	There are a few ways of installing the git client in Windows, including downloading
	and compiling the source. But guess if I want to go down that route. Instead,
	let&amp;#39;s just press the easy button and use a pre-packaged installer.
&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://code.google.com/p/msysgit/"&gt;msysgit&lt;/a&gt; is what you&amp;#39;ll want to
	install. Donwload the latest release from the site. The file name of the full installer, 
	as of this writing,	will be named like &lt;i&gt;Git-&lt;b&gt;[version]&lt;/b&gt;-preview&lt;b&gt;[yyyymmdd]&lt;/b&gt;.exe&lt;/i&gt;.
&lt;/p&gt;
&lt;p&gt;
	Run the installer accepting most of the defaults, with the exception of these
	two screens below. We want to &lt;b&gt;Run Git from the Windows Command Prompt&lt;/b&gt;
	and &lt;b&gt;Use PLink&lt;/b&gt; (PuTTY.)
&lt;/p&gt;
&lt;p&gt;
	&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/msysgit.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/msysgit_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;
	&amp;nbsp;
	&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/msysgit_2D00_2.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/msysgit_2D00_2_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
	After this we should have a working installation of Git. You should be
	able to use Git from both the Windows command prompt and from the Git Bash
	shell.
&lt;/p&gt;

&lt;h3&gt;Register your public key with the remote server&lt;/h3&gt;
&lt;p&gt;
	Now we need to tell the server that hosts the remote repository that
	it should expect and accept SSH connections from our machine. The
	way we do this is similar in GitHub and Unfuddle. We just need to 
	associate our &lt;b&gt;public&lt;/b&gt; key with our account on that site.
&lt;/p&gt;
&lt;p&gt;
	For example, in my GitHub account settings there&amp;#39;s a section 
	called &lt;i&gt;SSH Public Keys&lt;/i&gt;, where we can add all public keys that we own. Don&amp;#39;t use 
	the public key straight from your PuTTY public key file, it uses a different format.
	Instead, open Puttygen again and load the &lt;b&gt;private&lt;/b&gt; key. The public key,
	in the right format, will be shown in the big text box at the top of the window. Copy
	that entire text and paste in a new key in your GitHub settings, as seen below.
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/github_2D00_ssh.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2009.05/github_2D00_ssh_2D00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;Troubleshooting&lt;/h3&gt;
&lt;p&gt;
	After all that you should have all it takes to use Git in Windows. Until I
	got to this point I came across some problems. Here are some of them.
&lt;/p&gt;
&lt;p&gt;
	&lt;b&gt;No supported authentication methods available&lt;/b&gt;. I got that error while trying
	to &lt;i&gt;push&lt;/i&gt; changes because I either forgot to run Pageant or to add the right
	key into it. The full error is below.
&lt;/p&gt;
&lt;pre&gt;C:\myproject&amp;gt;git push origin master
FATAL ERROR: Disconnected: No supported authentication methods available
fatal: The remote end hung up unexpectedly&lt;/pre&gt;
&lt;p&gt;
	&lt;b&gt;The server&amp;#39;s host key is not cached in the registry&lt;/b&gt;. Sometimes when
	connecting to a remote server for the first time, the PuTYY will output this
	message after your Git command.
&lt;/p&gt;
&lt;pre&gt;The server&amp;#39;s host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server&amp;#39;s rsa2 key fingerprint is:
ssh-rsa 1024 [fingerprint here]
If you trust this host, enter &amp;quot;y&amp;quot; to add the key to
PuTTY&amp;#39;s cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter &amp;quot;n&amp;quot;.
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n)&lt;/pre&gt;
&lt;/p&gt;
	The problem is that Git will not read your keyboard input so
	you can&amp;#39;t type &amp;quot;y&amp;quot; (or &amp;quot;n&amp;quot;). You have to CTRL+C out of it.
&lt;/p&gt;
&lt;p&gt;
	The fix for this, is to connect to your server initially using
	&lt;code&gt;plink -agent github.com&lt;/code&gt; directly and then you&amp;#39;ll be able to press &amp;quot;y&amp;quot; to cache
	the server&amp;#39;s key locally (and not be prompted again in Git.) Enter &amp;quot;git&amp;quot; as the username if
	prompted. Now we can get back to Git without that prompt.
&lt;/p&gt;

&lt;h3&gt;Now, that was nerdy&lt;/h3&gt;
&lt;p&gt;
	By now, if you got this far in this post, you&amp;#39;re probably thinking this is too much work
	just to get a simple Git client working. I think the current situation reflects at least two
	things: the people behind Git are definitely not Windows users (d&amp;#39;oh, what a surprise) and
	the toolset is still relatively immature (in terms of polish, not under the hood) compared
	to Subversion and CVS for example. The existing GUI&amp;#39;s are still very raw and young but, given
	the increasing popularity of Git, I&amp;#39;ll be surprised if by the end of this year this problem
	isn&amp;#39;t gone.
&lt;/p&gt;

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=46514" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>Blocked .js files keep biting me</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/04/03/blocked-js-files-keep-biting-me.aspx</link><pubDate>Sat, 04 Apr 2009 03:14:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:45379</guid><dc:creator>sergiopereira</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;
This is a tip for those working with JavaScript (and possibly other types of files) that is freely available for download. For the n&lt;sup&gt;th&lt;/sup&gt; time in the last few months I spent an unnecessary amount of time trying to find a problem in my code that wasn&amp;#39;t really there.
&lt;/p&gt;
&lt;p&gt;
Windows keeps track of the files you save to your hard disk which came from the Internet. Maybe you have seen this problem when you try to open a CHM file that you downloaded and see that it opens to a blank page. The same type of thing happens with JavaScript files that you download. Let&amp;#39;s see what happened to me today.
&lt;/p&gt;
&lt;p&gt;First I downloaded the latest version of &lt;a href="http://docs.jquery.com/QUnit"&gt;QUnit&lt;/a&gt; and saved to my application&amp;#39;s directory. I did this the usual way, as shown in the image below.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/save_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/save_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Then I proceeded to use the downloaded testrunner.js file in my HTML page, via a &lt;code&gt;&amp;lt;script src=&amp;quot;testrunner.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt; tag. When I tried to open my HTML page, I was not expecting to see the particular error shown below.
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/error_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/error_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;I started to look for common problems: Did I save the file in the right place? Did I spell its name right? Did I mispell the function name? Did I miss a dependency? No, no, no, and no. All looked good.
&lt;/p&gt;

&lt;p&gt;That&amp;#39;s when I remembered that the file might have been flagged by Windows. I opened its properties dialog and, sure enough, there it was, the infuriating &lt;i&gt;Unblock&lt;/i&gt; button. 
&lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/properties_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/properties_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ah, that&amp;#39;s easy. I just clicked it and refreshed my page. Wah-wah! Problem persists. I tried typing the .js url in the address bar and saw this 401 error message from IIS, not 404. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/err_5F00_403.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/err_5F00_403_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;That told me that there was still something messed up with file access. I checked the file&amp;#39;s permissions, comparing to an older .js file in the application. The new one did not grant access to local users, so I added Read access to local users.
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/security_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/security_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;
Now it works. Depending on how your IIS and/or ASP.NET security is configured, you may not need this last step (e.g. if the process identity already has admin rights, in which case I salute you, brave friend.) The system at hand was a Win2008-x64 installation with the default IIS/ASP.NET settings.
&lt;/p&gt;

&lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/fixed_5F00_js.png"&gt;&lt;img src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/sergio_5F00_pereira.2008.04/fixed_5F00_js_5F00_small.png" border="0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;
	This problem seems to happen to me every other week and I still did
	not develop the reflex to take care of it right when I download the file. 
	On the other hand, I&amp;#39;m getting better at remembering about it when I
	see stuff like &lt;i&gt;&amp;quot;function not defined&amp;quot;&lt;/i&gt; in an error message. 
	
&lt;/p&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=45379" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript/default.aspx">JavaScript</category></item><item><title>Resharper an OutOfMemory Exceptions</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2009/02/03/resharper-an-outofmemory-exceptions.aspx</link><pubDate>Wed, 04 Feb 2009 00:24:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:43967</guid><dc:creator>sergiopereira</dc:creator><slash:comments>3</slash:comments><description>&lt;p&gt;
My current project has an interesting story of being converted 
across platforms and programming languages. I hope I can talk
about this conversion process some day (it was not manual).
&lt;/p&gt;

&lt;p&gt;
One of the side effects of mass conversions like this is
that the final result tends to carry over some weird
patterns. These patterns used to make total sense in
the previous programming language, but look very
unnatural in the new one.
&lt;/p&gt;

&lt;p&gt;
We ended up with some very large classes inside a single namespace that, 
while work exactly as in the previous language, cause an unusual amount
of stress inside Visual Studio, especially with Resharper (version 4.1) installed.
Resharper would halt with OutOfMemory exceptions all the time, until
I disabled Code Analysis, arguably one of the most important features
of that product.
&lt;/p&gt;

&lt;p&gt;&lt;img src="http://devlicio.us/blogs/sergio_pereira/2009/02/resharper-oome.png" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;
Finally today a coworker pointed me to a 
&lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/OutOfMemoryException+Fix"&gt;fix for that&lt;/a&gt;.
I&amp;#39;m still getting the exceptions if I turn on solution-wide error analysis, but I think I can live without that.
&lt;/p&gt;

&lt;p&gt;I haven&amp;#39;t had a chance to try &lt;a href="http://www.jetbrains.net/confluence/display/ReSharper/ReSharper+4.5+Nightly+Builds"&gt;the nightly 
builds&lt;/a&gt; of Resharper 4.5. &lt;a href="http://twitter.com/orangy/status/1174500846"&gt;I have been told&lt;/a&gt; that 
those issues may go away.&lt;/p&gt;


&lt;b&gt;UPDATE: &lt;/b&gt; 
I installed version 4.5 (build 1169.15) but it didn&amp;#39;t help me. The only thing that changed was the layout of the error screen :) 
But I know my project is a tad extreme and I deserve to be punished for it.

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=43967" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/.NET/default.aspx">.NET</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tools/default.aspx">Tools</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Development/default.aspx">Development</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category></item><item><title>jQuery Character Table</title><link>http://devlicio.us/blogs/sergio_pereira/archive/2008/12/29/jquery-character-table.aspx</link><pubDate>Tue, 30 Dec 2008 01:31:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:43555</guid><dc:creator>sergiopereira</dc:creator><slash:comments>4</slash:comments><description>	&lt;p&gt;
		The other day I was looking for the HTML code for the ⌘ (in case you can&amp;#39;t see it, that&amp;#39;s 
              the command key symbol), found in 
		mac keyboards. It was not the first time I was looking for the HTML code
		for one of those funky characters. I remember having a hard time trying to
		represent some Math symbols, like sums and integral equations from my
		college Calculus days.
	&lt;/p&gt;


	&lt;p&gt;
		I thought this would be a nice opportunity to create a small jQuery sample
		that renders a range (or ranges) of HTML characters along with their codes.
	&lt;/p&gt;


	&lt;p&gt;
		I started with a simple HTML page, leaving all the JavaScript in an external file.
	&lt;/p&gt;

	&lt;pre name="code" class="html"&gt;&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;HTML Characters&amp;lt;/title&amp;gt;
    &amp;lt;meta http-equiv=&amp;quot;Content-Type&amp;quot; 
      content=&amp;quot;text/html; charset=utf-8&amp;quot;&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; 
      src=&amp;quot;jquery-1.2.6.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; 
      src=&amp;quot;char-table.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    From (hex): &amp;lt;input id=&amp;quot;range_from&amp;quot; type=&amp;quot;text&amp;quot;  /&amp;gt; &amp;lt;br/&amp;gt;
    To (hex): &amp;lt;input id=&amp;quot;range_to&amp;quot; type=&amp;quot;text&amp;quot;  /&amp;gt; &amp;lt;br/&amp;gt;
    &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Load&amp;quot; id=&amp;quot;btnLoad&amp;quot; /&amp;gt;
    &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Load Example&amp;quot; id=&amp;quot;btnLoadEx&amp;quot; /&amp;gt;
    &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Load Keyboard Symbols&amp;quot; 
         onclick=&amp;quot;CHARTABLE.loadKeyboardSymbols();&amp;quot; /&amp;gt;
    &amp;lt;table id=&amp;quot;char_table&amp;quot; border=&amp;quot;1&amp;quot; /&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;

	&lt;p&gt;
		Here&amp;#39;s the JavaScript in the file &lt;i&gt;char-table.js&lt;/i&gt;.
	&lt;/p&gt;

&lt;pre name="code" class="js"&gt;$(function(){
  //here we put everything that will run when the page is ready

  $(&amp;#39;#btnLoad&amp;#39;).click(function(){
    // notice how we get the value of the input fields using val()
    // notice how to parse hex numbers in JS
    var from = parseInt($(&amp;#39;#range_from&amp;#39;).val(), 16);
    var to = parseInt($(&amp;#39;#range_to&amp;#39;).val(), 16);
    CHARTABLE.loadRange(from, to);
  });

  $(&amp;#39;#btnLoadEx&amp;#39;).click(function(){
  //setting the value of each input field
    $(&amp;#39;#range_from&amp;#39;).val(&amp;#39;2190&amp;#39;);
    $(&amp;#39;#range_to&amp;#39;).val(&amp;#39;2195&amp;#39;);
  //fire the click event of the Load button
    $(&amp;#39;#btnLoad&amp;#39;).click();
  });

});

// the CHARTABLE object acts as a namespace
var CHARTABLE = {
   loadRanges: function() {
    this.clearTable();
    for(var i=0; i&amp;lt;arguments.length; i++) {
      this.appendRange(
        parseInt(arguments[i][0], 16), 
        parseInt(arguments[i][1], 16)
        );
    }
  },

  loadRange: function(from, to) {
    this.clearTable();
    this.appendRange(from, to);
  },

  clearTable: function(){
    //the html() function is how we replace the innerHTML with jQuery
    $(&amp;#39;#char_table&amp;#39;).        
      html(&amp;#39;&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Character&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Code&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;&amp;#39;);
  },

  appendRange: function(from, to){
    //we can create stand alone DOM elements with $()
    var tbody = $(&amp;#39;&amp;lt;tbody/&amp;gt;&amp;#39;);
    for(var i=from; i&amp;lt;=to; i++) {
      //notice how we can convert a number to hex
      $(&amp;#39;&amp;lt;tr&amp;gt;&amp;#39;).
        append(&amp;#39;&amp;lt;td&amp;gt;&amp;amp;#x&amp;#39; + i.toString(16) + &amp;#39;;&amp;lt;/td&amp;gt;&amp;#39;).
        append(&amp;#39;&amp;lt;td&amp;gt;&amp;amp;amp;#x&amp;#39; + i.toString(16) + &amp;#39;;&amp;lt;/td&amp;gt;&amp;#39;).
        appendTo(tbody);
    }
    //adding the tbody to the table at the end
    //  renders faster than adding each row to
    //  the table as we go
    $(&amp;#39;#char_table&amp;#39;).append(tbody);
  },

  loadKeyboardSymbols: function(){
    this.loadRanges(
      [&amp;#39;21e7&amp;#39;, &amp;#39;21e7&amp;#39;],
      [&amp;#39;21a9&amp;#39;, &amp;#39;21a9&amp;#39;],
      [&amp;#39;2303&amp;#39;, &amp;#39;2305&amp;#39;],
      [&amp;#39;2318&amp;#39;, &amp;#39;2318&amp;#39;],
      [&amp;#39;2324&amp;#39;, &amp;#39;2327&amp;#39;],
      [&amp;#39;232b&amp;#39;, &amp;#39;232b&amp;#39;],
      [&amp;#39;2190&amp;#39;, &amp;#39;2198&amp;#39;],
      [&amp;#39;21de&amp;#39;, &amp;#39;21df&amp;#39;],
      [&amp;#39;21e4&amp;#39;, &amp;#39;21e9&amp;#39;]
    );
  }
};&lt;/pre&gt;

	&lt;p&gt;
		Now enter the range from 2100 to 2400 and stare at a whole
		bunch of characters that can become useful in some situations.
	&lt;/p&gt;


	&lt;p&gt;
		&lt;b&gt;Note:&lt;/b&gt; The characters don&amp;#39;t render equally in IE and Firefox, but
		a large number of them render just fine in both browsers.
	&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=43555" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/Tips-and-Tricks/default.aspx">Tips-and-Tricks</category><category domain="http://devlicio.us/blogs/sergio_pereira/archive/tags/JavaScript/default.aspx">JavaScript</category></item></channel></rss>