Skip to content

Instantly share code, notes, and snippets.

@duncansmart
duncansmart / IISExpress.cmd
Created March 10, 2011 15:16
IISExpress runner
:: Runs IIS Express and exits. IIS Express is kept alive by WScript.exe
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: NOTE, these are ignored if a file called IISExpress.config exists
set SITE_PORT=8080
set SITE_PATH=%~dp0
set SITE_CLR=v4.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set IISEXPRESS=%ProgramFiles%\IIS Express\iisexpress.exe
@duncansmart
duncansmart / IISExpress.js
Created March 10, 2011 15:56
IISExpress runner
// Runs IIS Express without a console window (if started with wscript.exe)
var sitePort = 8080;
var sitePath = ".";
var siteClr = "v4.0";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var wshell = new ActiveXObject("WScript.Shell");
// Resolve path
@duncansmart
duncansmart / SortItOut.cs
Created March 30, 2011 09:00
Shows effect of culture on sorting
using System;
using System.Globalization;
using System.Threading;
class Program
{
static void Main(string[] args)
{
string[] words = "chat city cabs".Split(' ');
@duncansmart
duncansmart / ExpressionUtil.cs
Created April 4, 2011 09:08
Type-safe GetMethod: get a MethodInfo without a magic string
using System;
using System.Reflection;
using System.Linq.Expressions;
class ExpressionUtil
{
// Returns the MethodInfo of the given lambda. Use instead of Type.GetMethod("name", paramTypes).
public static MethodInfo GetMethod<T>(Expression<Action<T>> lambda)
{
var call = lambda.Body as MethodCallExpression;
@duncansmart
duncansmart / CheckoutBuildAndPackage.cmd
Created April 7, 2011 19:55
A batch file that checks out a solution from SVN, builds it and packages it ready for MSDeploy.
@echo off
:: Required Config
set SVN_SOURCE=http://svnserver/svn/myrepo/mysolution
set WEB_PROJ_SUBDIR=Web
set PACKAGE_OUTPUT=C:\Builds\Packages
:: Required binaries
set SVN="%ProgramFiles(x86)%\CollabNet Subversion Client\svn.exe"
set MSBUILD="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Diagnostics;
// Our model classes
class Person
{
public int Id { get; set; }
public FullName FullName { get; set; }
@duncansmart
duncansmart / gist:1601540
Created January 12, 2012 16:45
Dump SqlCommand
static void DumpCommand(SqlCommand command)
{
foreach (SqlParameter p in command.Parameters)
{
Debug.Write("DECLARE " + p.ParameterName + " " + p.SqlDbType.ToString().ToLower());
if (p.Size > 0)
Debug.Write("(" + p.Size + ")");
Debug.Write(" = ");
if (p.Value is Enum)
Debug.Write((int)p.Value);
@duncansmart
duncansmart / DataReaderUtil.cs
Created January 24, 2012 16:23
Returns, and converts as appropriate, the value of the supplied data record (DataReader) that corresponds with the named column
internal static class DataReaderUtil
{
public static T GetValue<T>(this IDataRecord record, string columnName)
{
T result = default(T);
int ordinal = record.GetOrdinal(columnName);
if (record.IsDBNull(ordinal))
return result;
@duncansmart
duncansmart / NugetDownload.ps1
Created February 23, 2012 15:15
Script to download Nuget packages
$http = new-object System.Net.WebClient
$feed = [xml]$http.DownloadString("https://nuget.org/api/v2/Packages")
$feed.feed.entry | % {
$http.DownloadFile($_.content.src, ("C:\temp\"+ $_.title.InnerText + "." + $_.Properties.Version +".nupkg"))
}
@duncansmart
duncansmart / RestoreDatabase.sql
Created May 2, 2012 13:38
Restore SQL Server Database from BAK file
SET NOCOUNT ON
DECLARE @bakfile nvarchar(max) = 'C:\Temp\MyDb.BAK';
DECLARE @dbname nvarchar(max) = 'MyDb';
--DECLARE @datapath nvarchar(max) = 'c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA';
DECLARE @datapath nvarchar(max) = (SELECT TOP(1) left(physical_name, len(physical_name) - len('\master.mdf')) FROM master.sys.database_files)
--SELECT @datapath
--Drop db if exists