Skip to content

Instantly share code, notes, and snippets.

Piers Williams piers7

Block or report user

Report or block piers7

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
piers7 / Octopus - Diff Variables.linq
Created Sep 25, 2018
Compare Octopus Deploy Project's current variables with last release's snapshot
View Octopus - Diff Variables.linq
Diff's a project's variables with the snapshot associated with its latest release
Need to include Octopus.Client nuget package
var server = "http://my-octopus-server/";
var projectName = "my-project-name";
// Util.SetPassword("Octopus key for " + server, null); // run this line to unsave the password (if it changes, or you stuff up the entry)
var apiKey = Util.GetPassword("Octopus key for " + server, false);
var endpoint = new Octopus.Client.OctopusServerEndpoint(server, apiKey);
piers7 / Dump Explorer.linq
Created Nov 22, 2017
Memory dump explorer in Linqpad using the Microsoft.Diagnostics.Runtime engine
View Dump Explorer.linq
<Query Kind="Program">
<NuGetReference Prerelease="true">Microsoft.Diagnostics.Runtime</NuGetReference>
//string sourceDump = @"C:\MyLocalData\piers.williams\Downloads\temp\xunit.dmp";
piers7 / UpdateScriptFromTable.ps1
Created Oct 30, 2017
Generates a reference data insert/update script, based on contents of an existing table
View UpdateScriptFromTable.ps1
Generates a table-sync script, based on the current contents of a table
$schema = 'Dim',
$database = 'ITS_DataMart',
$server = 'localhost',
piers7 / fnProRataOverDays
Last active Jan 23, 2018
Power Query / Power BI function to prorata / explode / proportionally allocate data over calendar days
View fnProRataOverDays
Source = (StartDate as datetime, EndDate as datetime, Value as number) =>
OverallDuration = EndDate - StartDate,
PerMinuteAllocation = Value / Duration.TotalMinutes(OverallDuration),
OneDay = #duration(1,0,0,0),
// Date that the overall window starts
d0 = DateTime.From(Date.From(StartDate)),
piers7 / OracleDotNetDriverScan.ps1
Created Apr 12, 2017
Tells you what the currently registered ODP.Net (native) assembly is for x64 and x32 Oracle .net drivers
View OracleDotNetDriverScan.ps1
# .synopsis
# Sees what Oracle .net driver is installed for x32 and x64
# .author
# Piers
$providerName = 'Oracle.DataAccess.Client'
$job = {
$providerName = $args[0]
piers7 / AdHelper.ps1
Created Jan 11, 2017
Helpful Active Directory scripts for finding user records (before I lose them again)
View AdHelper.ps1
function Get-ADObject($adspath){
$obj = new-object System.DirectoryServices.DirectoryEntry "LDAP://$adspath";
new-object PSObject -Property:$obj.Properties;
function Find-ADUserByLogin($login){
$ds = new-object System.DirectoryServices.DirectorySearcher
$ds.Filter = "(samAccountName=$login)";
$result = $ds.FindOne();
piers7 / SmartUnbox.fs
Created Oct 21, 2016
Smartly unboxes a value from a data reader into various target representations
View SmartUnbox.fs
/// Smartly unboxes a nullable value, with different semantics depending on the target type (nullable, option etc...)
let SmartUnbox<'a> isNull (value:obj) : 'a =
// help from from
let targetType = typeof<'a>
let typeFlavour = TypeFlavour.Create<'a>()
match (isNull,typeFlavour) with
| true, ValueType -> failwithf "Can't return null for type %s" targetType.Name
| true, _ -> (box null) :?> 'a // cast null to nullable/option/reference type works fine!
| false, OptionT t ->
// Have to create the 'Some' member via reflection
piers7 / SyncPackageVersions.ps1
Created Dec 21, 2015
Upgrade nuget packages in one project to match another
View SyncPackageVersions.ps1
# Run this from Package Manager Console
# Make sure 'Default Project' is the one you want to update
# No refunds. YMMV
Select-Xml -Path:.\projectname\packages.config -xpath:'//package' | select-object -ExpandProperty:Node | % { Update-Package $_.Id -Version:$_.Version }
piers7 / deploy.ps1
Created Dec 16, 2015
General purpose Octopus Deploy -> Install.ps1 bootstrapper
View deploy.ps1
General-purpose Octopus Deploy boostrapper
Binds Octopus variables directly on to parameters on an install script, passing the rest as a hashtable
This means your Install script can itself have 'proper' parameters, making local testing easier
$entryPoint = '.\Install.ps1'
piers7 / exec.ps1
Created Nov 18, 2015
PowerShell - reliably detect failure from external scripts
View exec.ps1
Detects failure from an external script has failed based on both $? and $LASTEXITCODE checking
Tested with a .net console app in 4 modes:
- no stderr, exit 0 (should be the only passing case)
- stderr, exit 0 ($? should indicate failure)
- no stderr, exit 1 ($LASTEXITCODE should indicate failure)
- stderr, exit 1 (both $? and $LASTEXITCODE should indicate failure)
See for background
You can’t perform that action at this time.