Skip to content

Instantly share code, notes, and snippets.

View michaeljbailey's full-sized avatar

Mike Bailey michaeljbailey

  • Converged Technology Group
  • Long Island, New York
View GitHub Profile
@michaeljbailey
michaeljbailey / LogReuseWait.sql
Created August 29, 2014 18:52
Run this query on a server to figure out why your database log files aren't shrinking. Typically, you'll find databases that have been switch to 'Simple recovery model' but haven't had a full backup taken yet.
SELECT
[state_desc] [State],
[recovery_model_desc] [Recovery Model],
[log_reuse_wait_desc] [Log Reuse Wait Reason],
[name] [Database],
[is_auto_shrink_on] [Auto Shrink Enabled]
FROM [master].[sys].[databases]
ORDER BY [State], [Recovery Model], [Log Reuse Wait Reason], [Database]
@michaeljbailey
michaeljbailey / GetAdministrators.sql
Created October 22, 2014 14:23
Finds all users in the sysadmin role that are not the sa account or are NT Services.
SELECT name
FROM master.sys.syslogins [Login]
WHERE [Login].[sysadmin] = 1
AND [name] <> 'sa'
AND [name] NOT LIKE 'NT Service%'
@michaeljbailey
michaeljbailey / DataFlowTimings.sql
Created October 24, 2014 15:41
Returns the minimum, maximum, average, deviation and total time spent executing data flow components.
-- Set this value to a reasonable value to filter out extraneous timings
DECLARE @MinTimingThresholdMilliseconds = 10;
SELECT
[EventSource],
[Component],
COUNT([Timing]) [EventCount],
MIN([Timing]) [Min Time (ms)],
AVG([Timing]) [Average Time (ms)],
MAX([Timing]) [Max Time (ms)],
@michaeljbailey
michaeljbailey / MockSequence.cs
Created October 28, 2014 16:11
Allows sequencing of Moq'd objects to enforce specific call orders.
using System;
using System.Collections.Generic;
using System.Linq;
using Moq.Language.Flow;
namespace Moq.Sequencing
{
public static class CallSequenceExtensions
{
public static void InSequence<TMock>(this ISetup<TMock> setup, CallSequence callSequence) where TMock : class
public class CommandLineArgumentParserHandler : IHandler<string, IArgumentParser>
{
private readonly CommandLineArgumentParser _service;
public CommandLineArgumentParserHandler(CommandLineArgumentParser service)
{
_service = service;
}
@michaeljbailey
michaeljbailey / InstallUnifiService.ps1
Last active January 12, 2021 08:13
Automation script for installing the Ubiquiti UniFi Controller as a Windows Service. This takes care of doing tedious things like setting JAVA_HOME or including it within your PATH variable. Use at your own risk!
# Written by Mike Bantegui (Last Updated 2015-03-05)
# Use at your own caution! I take no responsibility for any damage you may cause on your system.
# Known to support: Windows Server 2012 R2
function Request-ElevatedPrompt
{
# Adapted from Benjamin Armstrong's "A self elevating PowerShell script"
# http://blogs.msdn.com/b/virtual_pc_guy/archive/2010/09/23/a-self-elevating-powershell-script.aspx
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object System.Security.Principal.WindowsPrincipal($identity)
@michaeljbailey
michaeljbailey / SvnAdmin.ps1
Last active August 29, 2015 14:17
Some PowerShell wrappers for commonly used svnadmin commands. The functions exported make several assumptions and are *very* simple. Think of these as more of starter scripts to modify or build up on.
# Note: The below does not yet handle paths with spaces because I was being lazy.
function Import-SvnRepository($SvnAdminPath, $RepositoryPath, $InputPath)
{
& cmd /c "`"$SvnAdminPath`" load $RepositoryPath --memory-cache-size 256 < $InputPath"
}
function Export-SvnRepository($SvnAdminPath, $RepositoryPath, $OutputPath, [Switch]$UseDelta)
{
if ($UseDelta)
@michaeljbailey
michaeljbailey / FileDialogFilter.cs
Created April 13, 2015 18:39
Builds up the filter for a file dialog.
public class FileDialogFilter
{
private readonly string _filter;
private readonly string _description;
public string Description
{
get { return _description; }
}
@michaeljbailey
michaeljbailey / NotifyPropertyChangedExtensions.cs
Created April 13, 2015 19:02
Wires up the PropertyChanged handler in a type safe and filtered way
public static class NotifyPropertyChangedExtensions
{
private static PropertyInfo GetPropertyInfo<TSource, TProperty>(Expression<Func<TSource, TProperty>> propertyExpression)
{
var type = typeof(TSource);
var memberExpression = propertyExpression.Body as MemberExpression;
if (memberExpression == null)
{
var message = string.Format("Expression '{0}' refers to a method, not a property.", propertyExpression);
@michaeljbailey
michaeljbailey / FormatterConfig.cs
Created April 15, 2015 21:12
Sane defaults to use for pure JSON Web APIs
public static class FormatConfig
{
private class JsonContentNegotiator : IContentNegotiator
{
private readonly JsonMediaTypeFormatter _jsonFormatter;
public JsonContentNegotiator(JsonMediaTypeFormatter formatter)
{
_jsonFormatter = formatter;
}