Skip to content

Instantly share code, notes, and snippets.

@jasonmead
jasonmead / unused_indexes.sql
Created August 15, 2012 20:36
Unused indexes
SELECT OBJECT_SCHEMA_NAME(I.OBJECT_ID) AS SchemaName,
OBJECT_NAME(I.OBJECT_ID) AS ObjectName,
I.NAME AS IndexName
FROM sys.indexes I
WHERE -- only get indexes for user created tables
OBJECTPROPERTY(I.OBJECT_ID, 'IsUserTable') = 1
-- find all indexes that exists but are NOT used
AND NOT EXISTS (
SELECT index_id
FROM sys.dm_db_index_usage_stats
@jasonmead
jasonmead / missing_indexes.sql
Created August 15, 2012 15:17
Find missing indexes in SQL Server
PRINT 'Missing Indexes: '
PRINT 'The "improvement_measure" column is an indicator of the (estimated) improvement that might '
PRINT 'be seen if the index was created. This is a unitless number, and has meaning only relative '
PRINT 'the same number for other indexes. The measure is a combination of the avg_total_user_cost, '
PRINT 'avg_user_impact, user_seeks, and user_scans columns in sys.dm_db_missing_index_group_stats.'
PRINT ''
PRINT '-- Missing Indexes --'
SELECT CONVERT (varchar, getdate(), 126) AS runtime,
mig.index_group_handle, mid.index_handle,
CONVERT (decimal (28,1), migs.avg_total_user_cost * migs.avg_user_impact * (migs.user_seeks + migs.user_scans)) AS improvement_measure,
@jasonmead
jasonmead / ajaxErrorRedirect.js
Created April 24, 2012 14:41
Redirect Unauthenticated jQuery Ajax calls
$(document).ajaxError(function (event, xhr, settings) {
if (xhr.status == 401) {
var return_path = encodeURIComponent(window.location.pathname + window.location.search);
var loginPath = "/login.aspx" // Replace with your site's login page
window.location.href = loginPath + "?return_url=" + return_path + "";
}
});
@jasonmead
jasonmead / gist:1540274
Created December 30, 2011 15:16
Go To Hell Extension method
public static class Inferno {
public static bool GoToHell(this Person person) {
return person.GoTo(new HellLocation());
}
public static bool GoTo(this Person person, Location location) {
person.Location = location;
return true;
}
}
@jasonmead
jasonmead / gist:733877
Created December 8, 2010 20:37
OWIN GetBody Handler
namespace Owin
{
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
public interface IResponseHandler
{
Type TypeToHandle { get; }