Skip to content

Instantly share code, notes, and snippets.

View chrisoldwood's full-sized avatar

Chris Oldwood chrisoldwood

View GitHub Profile
@chrisoldwood
chrisoldwood / http-request-tests.sil
Created October 12, 2022 16:25
Example unit tests for verifying outbound HTTP request parameters in a pure functional language
private anyHostname = builders.randomHostname(10)
private anyToken = builders.randomToken(10)
private anyResourcePath = builders.randomPathName(8) ~ "/" ~ builders.randomPathName(8)
private emptyResponse = "[]"
Test2(Fixture, "Fetching a resource passes the access token in the PRIVATE-TOKEN header", () => {
token = builders.randomToken(12)
getMethod = (url, headers) => {
assert.that(headers, isTableWithKey("PRIVATE-TOKEN"), "The access token header is missing")
assert.that(get(headers, "PRIVATE-TOKEN", ""), isEqualTo(token), "The access token was incorrect")
@chrisoldwood
chrisoldwood / CheckDubSelections.ps1
Last active February 27, 2020 12:25
Scans dub.selections.json files looking for package version mismatches.
<#
.synopsis
Scans the dub.selections.json files under a folder looking for
inconsistent versions of the same package dependency.
.description
Ideally your projects should always be using a consistent set of
package versions to avoid impedance mismatches. This script analyses
all the packages used by your projects (e.g. libraries) and tells you
if multiple package versions are being referenced.
using System;
using System.Reflection;
using System.Runtime.InteropServices;
[assembly:Guid("11111111-2222-3333-4444-555555555555")]
namespace GUID_Test
{
class Program
{
@chrisoldwood
chrisoldwood / autounattend.xml
Created November 25, 2019 16:12
Example Packer configuration files for creating a Windows 10 VM on QEMU/KVM/libvirt.
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-International-Core-WinPE" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SetupUILanguage>
<UILanguage>en-US</UILanguage>
</SetupUILanguage>
<SystemLocale>en-US</SystemLocale>
@chrisoldwood
chrisoldwood / windows10.auto.xml
Last active November 25, 2019 15:10
Example Oz configuration files for creating a Windows 10 VM on QEMU/KVM/libvirt with oz-install.
<?xml version="1.0" encoding="utf-8"?>
<unattend xmlns="urn:schemas-microsoft-com:unattend">
<settings pass="windowsPE">
<component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"
xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DiskConfiguration>
<Disk>
<CreatePartitions>
<CreatePartition>
@chrisoldwood
chrisoldwood / Log-SQL-Plan.ps1
Last active March 29, 2019 10:53
Example for how to get the query plan from SQL Server via .Net code,
Set-StrictMode -Version Latest
$ErrorActionPreference = 'stop'
$instance = '.\SQLEXPRESS'
$database = 'database'
$configuration = "Server=$instance;Database=$database;Trusted_Connection=True;"
$connection = New-Object System.Data.SqlClient.SqlConnection $configuration
$connection.Open()
$command = $connection.CreateCommand()
@chrisoldwood
chrisoldwood / ShowProjectBuildTypes.ps1
Last active November 24, 2018 23:35
List Visual Studio solution file project build configurations.
<#
.synopsis
Shows which build configurations are supported for which projects in a
Visual Studio solution file (.sln).
.description
With a large Visual Studio solution that has more than just the default
build configurations it's easy for them to get out of step. This script
analyses a .sln file and shows you which build configurations are
available for which projects so that you can find inconsistencies.
@chrisoldwood
chrisoldwood / Log-SQL-IO-Stats.ps1
Last active August 6, 2018 12:11
Example of how to capture SQL Server query IO statistics from a .Net based client.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'stop'
$configuration = 'Server=.\SQLEXPRESS;Database=master;Trusted_Connection=True;'
$connection = New-Object System.Data.SqlClient.SqlConnection $configuration
$connection.Open()
$handler = [System.Data.SqlClient.SqlInfoMessageEventHandler] {
param($sender, $event)
@chrisoldwood
chrisoldwood / fixr.py
Created June 2, 2018 23:19
Python script to query the Fixr REST API
import requests
import argparse
import sys
def listVenues():
response = requests.get(f'{baseUrl}/venue?limit=1000&offset=0')
json = response.json()
for venue in json['data']:
id = venue['id']
@chrisoldwood
chrisoldwood / CustomJsonConverter.cs
Last active February 17, 2023 23:16
Example showing infinite loop deserialising polymorphic types with a custom JsonConverter.
namespace JsonTests
{
public class CustomJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return typeof(BaseType).IsAssignableFrom(objectType);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)