Skip to content

Instantly share code, notes, and snippets.

View colinbowern's full-sized avatar

Colin Bowern colinbowern

View GitHub Profile
@colinbowern
colinbowern / Get-Build2011Sessions.ps1
Created September 18, 2011 16:20
Download Build 2011 Sessions using Titles
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$a = ([xml](new-object net.webclient).downloadstring("http://channel9.msdn.com/Events/BUILD/BUILD2011/RSS/wmv"))
$a.rss.channel.item | foreach{
$url = New-Object System.Uri($_.enclosure.url)
$sessionUrl = New-Object System.Uri($_.link)
$file = $sessionUrl.segments[-1] + " - " + $_.title.Replace("""", "'").Replace(":", "-") + ".wmv"
if (!(test-path $file))
{
Write-Host "Downloading $file"
(New-Object System.Net.WebClient).DownloadFile($url, $file)
@colinbowern
colinbowern / gist:1920943
Created February 27, 2012 02:48
AutoData Theories with AutoFixture and XUnit
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Ploeh.AutoFixture.Xunit;
using Xunit.Extensions;
namespace XunitSample
{
public class TestClass
public class ObserveringType
{
// Use Is prefix here because the purpose of this class it to describe the other class
public bool IsEnabled { get; protected set; }
public ObservingType(SomeType type) { ... }
}
public class SomeType
@colinbowern
colinbowern / gist:2821869
Created May 29, 2012 00:30
Ugly exceptions in System.DirectoryServices
try
{
directoryEntry.Children.Find(objectName, "domainDns");
}
catch (DirectoryServicesCOMException exception)
{
if (exception.ErrorCode != 0x2030)
{
throw;
}
@colinbowern
colinbowern / gist:2871906
Created June 5, 2012 01:39
Speaking at TechEd New Zealand
Dear Microsoft New Zealand Speaker Selection Team,
Wouldn’t you love to get bang for your buck while investing in me being here? There is a way: speaking at Microsoft TechEd New Zealand 2012. This year, the annual event will be held in Auckland from September 4 to 7 and it is the best way for me to meet some awesome developers and share my experiences - to add value to their team and their bottom line.
Microsoft TechEd 2012 is New Zealand’s largest technology conference, and it always has the best content because they bring down speakers from overseas. I could be one of them! I can get help deliver the most comprehensive training on Microsoft products, even those that haven't been released yet.
An added benefit this year is that I can update my industry certification on-site, as well as the skills that will help our organisation better understand, deploy and manage technologies.
In addition to over 160 unique breakout sessions with Microsoft and industry speakers, the conference would offer me the chanc
<?xml version="1.0" encoding="utf-16"?>
<instrumentationManifest xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" xmlns="http://schemas.microsoft.com/win/2004/08/events" xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:trace="http://schemas.microsoft.com/win/2004/08/events/trace">
<instrumentation>
<events>
<provider name="Company-Product-Module" guid="{11111111-3709-4551-821E-CF1DF1644D14}" symbol="company_product_module">
<events>
<event symbol="ApplicationStart" value="1" version="0" channel="Company-Product-Module/Operational" level="win:Informational" task="win:None" opcode="win:Start" message="$(string.Company-Product-Module.event.1.message)" />
<event symbol="ApplicationEnd" value="2" version="0" channel="Company-Product-Module/Operational" level="win:Informational" task="win:None" opcode="win:Stop" message=
@colinbowern
colinbowern / DataContractExtensions.cs
Last active December 17, 2015 04:39
Add functionality to verify mapping similar to FluentNHibernate's PersistenceSpecification class.
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Transactions;
using FluentAssertions;
// ReSharper disable CheckNamespace
namespace System.Data.Linq
// ReSharper restore CheckNamespace
{
@colinbowern
colinbowern / CreateEventSourceSnippet.cs
Created June 20, 2013 13:16
The call to EventLog.CreateEventSource causes a SecurityException because it has to cycle through the Security log to check. Alternatively you can go into the registry and setup the log and source yourself. Note that this either requires the process to be elevated (see http://stackoverflow.com/a/2818776/79842) or that your user has delegated mod…
// Need to go direct to the registry as the EventLog.CreateEventSource
// method cycles through all logs, including the Security log, to
// verify that the source does not exist and is unique
try
{
var logKeyName = String.Format(CultureInfo.InvariantCulture, @"SYSTEM\CurrentControlSet\Services\EventLog\{0}", log);
var sourceKeyName = String.Format(CultureInfo.InvariantCulture, @"SYSTEM\CurrentControlSet\Services\EventLog\{0}\{1}", log, source);
using (Registry.LocalMachine.OpenSubKey(logKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
Registry.LocalMachine.CreateSubKey(logKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree))
using (var sourceKey = Registry.LocalMachine.OpenSubKey(sourceKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree) ??
function Set-WebSiteOffline {
param(
[Parameter(Mandatory=$true)][string]$ServerName,
[Parameter(Mandatory=$true)][string]$SiteName,
[string]$UserName,
[string]$Password
)
$EncodedSiteName = [System.Web.HttpUtility]::UrlEncode($SiteName);
$SiteManagementEndpoint = "https://$ServerName.contoso.com:8172/MSDeploy.axd?Site=$EncodedSiteName";
@colinbowern
colinbowern / Import-SQLPS.ps1
Created July 5, 2013 22:40
Importing SQL PowerShell changes the current folder, make sure it doesn't by wrapping it with these two commands.
$CurrentFolder = $(Get-Location).Path
Import-Module SQLPS -DisableNameChecking
Set-Location $CurrentFolder