Jan 22, 2010

PATH environment variable

Command prompt:

set PATH=%PATH%;c:\newdir

Appends a new path to the PATH variable. However this is scoped to the running CMD window. To make it a permanent change there is a utility called setx.exe (details here)

Jan 20, 2010

Microsoft Log Parser

This is a tool that provides query access to text-based data such as log files, XML/CVS files, as well as Event Log, the Registry, the file system and Active Directory.
Download here.
Here is a sample query that returns the top bandwidth by URL

SELECT top 50 DISTINCT 
SUBSTR(TO_LOWERCASE(cs-uri-stem), 0, 55) AS Url, 
Count(*) AS Hits, 
AVG(sc-bytes) AS AvgBytes, 
SUM(sc-bytes) as ServedBytes 
FROM {filename} 
GROUP BY Url 
HAVING Hits >= 20 
ORDER BY ServedBytes DESC

So at the command line run:
logparser -i:iiswc3 "SELECT STATEMENT GOES HERE"

Here are some links to example queries:
LogParserPlus Queries
ServerFault IIS Queries
Tutorial
IIS Forum

Net command in CMD

Useful when you want to find out where the SHARES are located on a computer:

C:\net share

Returns a list of Share Names <--> Resource (local paths)

Notice that shares ending with $ are admin shares

Jan 18, 2010

SQL Server Email

EXEC msdb.dbo.sp_send_dbmail
@recipients= @Recipients,
@body= @temp,
@subject = 'Test',
@profile_name = 'DBMailProfile'

See this Example

Jan 15, 2010

C# BubbleSort routine

So I wrote the first version (not optimized) in 5 minutes. For the optimization it took another 5 minutes.
This algorithm is O(n2) and as Knuth puts it, "...bubble sort seems to have nothing to recommend it, except a catchy name".

/// <summary>
/// Optimized version of BubbleSort that parses one less item each iteration
/// </summary>
public static class BubbleSort
{
public static int[] Sort(int[] input)
{
int temp, count = input.Length - 1;

while (count > 0)
{
for (int i = 0; i < count; i++)
{
if (input[i] > input[i + 1])
{
temp = input[i + 1];
input[i + 1] = input[i];
input[i] = temp;
}
}
count--;
}
return input;
}
}

There is also this interesting BubbleSort question on stackoverflow

Jan 13, 2010

Assembly Binding Log Viewer FUSLOGVW.exe

The Assembly Binding Log Viewer displays details for failed assembly binds.

This is useful when for instance your ASP.NET app craps out on you because it can't find an assembly or it finds one with a different verision.

The viewer is available with the Windows SDK.

MSDN info

ASSEMBLY PROBING, FUSION AND FUSLOGVW IN 5 MINUTES