Skip to content

Instantly share code, notes, and snippets.

View colinbowern's full-sized avatar

Colin Bowern colinbowern

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using NodaTime;
using Xunit;
namespace EntityFrameworkNodaTimePersistence
{
@colinbowern
colinbowern / gist:6337487
Created August 26, 2013 01:51
Choosing the web
The web and, in particular, JavaScript are at a stage of explosive innovation which makes it difficult to be certain of choices around libraries and frameworks. What is certain, though, is that choosing the web means a shift in mindset from an eco-system driven largely by a single vendor to one which is chaotic at times and whose strength is measured by capability, compatibility, community and contributions.
# Reads CSV generated by CSVDE and updates the properties for Active Directory User
param([Parameter(Position=0, Mandatory=$true)] $FileName)
$ReadOnlyProperties = "DN", "objectClass", "sAMAccountName"
Write-Host "Reading from $FileName"
$UserRecords = Import-Csv $FileName
foreach($UserRecord in $UserRecords) {
Write-Host "Updating $($UserRecord.DN)"
$User = [adsi]$("LDAP://" + $UserRecord.DN)
@colinbowern
colinbowern / WebProject.ps1
Created August 22, 2013 03:27
MSBuild is being replaced with PSAKE in my toolkit - so much easier to read than angle brackets.
# Input Properties
# ================
# TEAMCITY_BUILDCONF_NAME = Build definition name from CI Server
# BUILD_NUMBER = Major.Minor.Revision.Build
# Targets
# =======
# 1. Clean: Cleans build output folders
# 2. Build: Update version tags, compile solution, run static code analysis
# 3. Test: Run unit and/or integration tests
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<security>
<requestFiltering>
<hiddenSegments>
<add segment="/bin/" />
<add segment="/conf/" />
<add segment="/data/" />
<add segment="/inc/" />
@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
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 / 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) ??
@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
{
<?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=