Skip to content

Instantly share code, notes, and snippets.

View piers7's full-sized avatar

Piers Williams piers7

View GitHub Profile
@piers7
piers7 / ddotnet.sh
Created March 12, 2023 05:43
dotnet CLI via docker container only - no locally installed SDK
#!/bin/bash
docker run --rm -it -v "$PWD:/app" -w /app -p 8000:80 mcr.microsoft.com/dotnet/sdk:6.0 dotnet $@
@piers7
piers7 / Octopus - Diff Variables.linq
Created September 25, 2018 06:00
Compare Octopus Deploy Project's current variables with last release's snapshot
/*
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
piers7 / Dump Explorer.linq
Created November 22, 2017 02:21
Memory dump explorer in Linqpad using the Microsoft.Diagnostics.Runtime engine
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Windows.Forms.dll</Reference>
<NuGetReference>Rx-Main</NuGetReference>
<NuGetReference Prerelease="true">Microsoft.Diagnostics.Runtime</NuGetReference>
<Namespace>Microsoft.Diagnostics.Runtime</Namespace>
<Namespace>System.Reactive</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
</Query>
//string sourceDump = @"C:\MyLocalData\piers.williams\Downloads\temp\xunit.dmp";
@piers7
piers7 / UpdateScriptFromTable.ps1
Created October 30, 2017 07:37
Generates a reference data insert/update script, based on contents of an existing table
<#
.Synopsis
Generates a table-sync script, based on the current contents of a table
#>
param(
[Parameter(Mandatory=$true)]
$table,
$schema = 'Dim',
$database = 'ITS_DataMart',
$server = 'localhost',
@piers7
piers7 / fnProRataOverDays
Last active January 23, 2018 03:40
Power Query / Power BI function to prorata / explode / proportionally allocate data over calendar days
let
Source = (StartDate as datetime, EndDate as datetime, Value as number) =>
let
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
piers7 / OracleDotNetDriverScan.ps1
Created April 12, 2017 08:46
Tells you what the currently registered ODP.Net (native) assembly is for x64 and x32 Oracle .net drivers
# .synopsis
# Sees what Oracle .net driver is installed for x32 and x64
# .author
# Piers
param(
$providerName = 'Oracle.DataAccess.Client'
)
$job = {
$providerName = $args[0]
@piers7
piers7 / AdHelper.ps1
Created January 11, 2017 08:42
Helpful Active Directory scripts for finding user records (before I lose them again)
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();
if($result){
@piers7
piers7 / SmartUnbox.fs
Created October 21, 2016 04:38
Smartly unboxes a value from a data reader into various target representations
/// 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 http://www.fssnip.net/hh
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
piers7 / SyncPackageVersions.ps1
Created December 21, 2015 04:47
Upgrade nuget packages in one project to match another
# 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
piers7 / deploy.ps1
Created December 16, 2015 07:49
General purpose Octopus Deploy -> Install.ps1 bootstrapper
<#
.Synopsis
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
#>
param(
$entryPoint = '.\Install.ps1'
)