Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
GuyHarwood / reindexAzure.sql
Created May 11, 2013 08:06
Reindex Azure SQL Database
DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
exec('ALTER INDEX ALL ON ' + @TableName + ' REBUILD')
@GuyHarwood
GuyHarwood / parse-IIS-Log.cmd
Last active November 9, 2022 17:50
parse raw IIS logs using MS Log Parser into csv file
logparser -i:W3C -o:csv "SELECT * INTO c:\temp\results.csv FROM c:\temp\myLogFile.log"
@GuyHarwood
GuyHarwood / packages.config
Last active December 16, 2015 19:48
My default Chocolatey package for a new windows dev box. 1) Install Chocolatey 2) open a cmd window 3) cinst packages.config 4) enjoy chocolatey goodness
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="notepadplusplus" />
<package id="fiddler" />
<package id="cmder" />
<package id="sourcetree" />
<package id="TortoiseGit" />
<package id="winrar" />
<package id="rdcman" />
<package id="greenshot" />
@GuyHarwood
GuyHarwood / CustomerController.cs
Last active December 16, 2015 16:08
Returning the location of a newly created resource using Request Uri.
//Taken from http://codebetter.com/glennblock/2012/05/24/two-ways-to-work-with-http-responses-in-apicontroller-httpresponsemessage-and-httpresponseexception/
public class CustomerController : ApiController
{
private ICustomerContext repo;
public CustomerController(ICustomerContext repo)
{
this.repo = repo;
}
@GuyHarwood
GuyHarwood / BaseApiControllerTests.cs
Last active December 16, 2015 13:29
Scan all API controllers to ensure that they all inherit from the specified base controller
[Test]
public void AllApiControllersInProjectInheritFromBaseApiController()
{
var apiBaseType = typeof(BaseApiController);
var controllerTypes = (from type in apiBaseType.Assembly.GetTypes()
where type.Name.EndsWith("Controller") && type.IsSubclassOf(typeof(ApiController))
&& !type.IsSubclassOf(typeof (BaseApiController))
&& type != typeof(BaseApiController)
select type.Name).ToArray();
@GuyHarwood
GuyHarwood / EFDataContextTest.cs
Last active December 15, 2015 14:58
Base Test class with Lazy Entity Framework Context and database Initialisation.
using System;
using System.Data.Entity;
using System.Diagnostics;
using NUnit.Framework;
namespace EntityFrameworkTests
{
//TODO replace this stub with your own
public class MyDataContext : DbContext
{}
kernel.Bind(x => x.FromAssembliesMatching("Company.Product.Namespace.*")
.SelectAllClasses()
.BindDefaultInterface()
.Configure(b => b.InRequestScope()));
@GuyHarwood
GuyHarwood / AppPoolPerms.bat
Created February 26, 2013 12:33
On Windows Server 2008 v1 the GUI does not pick up the APPPOOL prefix for accounts. You need to use the command line to assign permissions for an application pool
ICACLS C:\inetpub\wwwroot\MyWebsite /grant "IIS APPPOOL\MyAppPool":(OI)(CI)(RX)
@GuyHarwood
GuyHarwood / stereotypicalLayers.cs
Last active December 14, 2015 04:39
I am sick of seeing code like this...
//the 'domain/service' layer...
public class ContactService
{
public ContactService(IContactRepository contactRepository)
{
_contactRepository = contactRepository;
}
public Contact GetContact(int id)
{
public static bool IsNull<T>(this T instanceToCheck) where T : class
{
return instanceToCheck == default(T);
}