Monday, May 21, 2012

Using WinMerge as merge/diff tool in TFS


Original source: http://jonfuller.codingtomusic.com/2008/08/26/tfs-using-winmerge-as-your-mergediff-tool/
Thanks Jon!

In VS, go To: Tools/Options/SourceControl/Visual Studio Team Foundation Server/Configure User Tools

Click "Add..."
Extension:  .*
Operation: Compare
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /e /wl /dl %6 /dr %7 %1 %2
Click "Add..."

Extension:  .*
Operation: Merge
Command: C:\Program Files\WinMerge\WinMergeU.exe
Arguments: /ub /dl %6 /dr %7 %1 %2 %4

The winmerge command line reference can be found here.

Thursday, May 17, 2012

Javascript console.log() and IE

Arg how I loath IE, why doesn't it support console.log(obj)?

To prevent IE from throwing an exception when it encounters console.log, add the following to a site-wide js file:

if (!window.console) console = { log: function () { } };


This makes cross browser testing much easier while in development.

Wednesday, May 16, 2012

Configure Elmah on IIS7.x vs IIS6

Elmah in IIS 7.x:

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" /> <!-- false if you also have httpModules in config -->
    <modules runAllManagedModulesForAllRequests="true">
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" />
    </modules>
    <handlers>
      <add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
    </handlers>
</system.webServer>


Elmah in IIS 6, if you must:

<elmah>
    <!-- See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for more information on remote access and securing ELMAH. -->
    <security allowRemoteAccess="false" />
</elmah>


<system.web>
   <httpModules>
      <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
      <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
      <add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
    </httpModules>
    <httpHandlers>
      <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
    </httpHandlers>
</system.web>

Thanks Elmah - you're awesome!

Sunday, April 29, 2012

Contained Javascript Library template

This Javascript template enables a library to be written in its own namespace and handle being included multiple times on a page.
It's based on Douglas Crockford's json2.js library.


var MyLibrary;
if (!MyLibrary) {
    MyLibrary = {};
}


(function () {
    //'use strict';
    if (typeof MyLibrary.myFunction !== 'function') {
        MyLibrary.myFunction = function (arg1, arg2) {
          //...method body here...
          return true;
        };
    }
}());

Thursday, April 26, 2012

Enable IE F12 Dev Tools

New contract, new machine.....and the Internet Explorer F12 debug tools don't work for me.

This fixed it:

Run gpedit.msc
In the left pane, click on to expand Computer Configuration, Administrative Templates, Windows Components, Internet Explorer, and Toolbars.
In the right pane, double click on Turn off Developer Tools
Select Disabled

Arg, how I hate IE.

Wednesday, April 25, 2012

Help Internet Explorer suck less by removing compat mode

The compatibility mode in IE has it's uses, but can cause nightmares when clients are testing.

To remove it as an option add the following as teh first line after the <head> tag in your mark up:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

More info:
http://blogs.msdn.com/b/askie/archive/2009/03/23/understanding-compatibility-modes-in-internet-explorer-8.aspx
http://stackoverflow.com/questions/3960120/turn-off-ie-8-compatibility-mode-for-site

Saturday, April 21, 2012

SQL 2005/2008 Median function

This is this simplest SQL 2005/2008 Median function I've come across:



SELECT
(
 (SELECT MAX(MyColumn) FROM
   (SELECT TOP 50 PERCENT MyColumn FROM MyTable ORDER BY MyColumn) AS BottomHalf)
 +
 (SELECT MIN(MyColumn) FROM
   (SELECT TOP 50 PERCENT MyColumn FROM MyTable ORDER BY MyColumn DESC) AS TopHalf)
) / 2 AS Median


Thanks Jeff Atwood!
http://stackoverflow.com/questions/1342898/function-to-calculate-median-in-sql-server