Skip to content

Instantly share code, notes, and snippets.

View peteraritchie's full-sized avatar
😖

Peter Ritchie peteraritchie

😖
View GitHub Profile
@peteraritchie
peteraritchie / results.md
Last active March 4, 2026 20:27
Comparing use of Microsoft.Extensions.FileSystemGlobbing.Matcher to Directory.EnumerateFiles

Directory.EnumerateFiles is slightly faster (12%) for simply searching all subdirectories for files with a certain extension. (e.g. **/*.cs)

Method Mean Error StdDev
Globbing 98.14 ms 1.930 ms 2.222 ms
DirectoryEnumerateFiles 86.32 ms 1.695 ms 2.376 ms
@peteraritchie
peteraritchie / SignDataAndVerifySignatureShould.cs
Last active March 3, 2026 22:14
Example code that models signing data then verifying data against the signature.
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace ProofsOfConcept.Tests;
public class SignDataAndVerifySignatureShould
{
private readonly byte[] generatedPfxBytes = CreateX509CertificatePfxBytes(PfxPassword);
private const string PfxPassword = "StrongPassword123!";
@peteraritchie
peteraritchie / New-LinkFrom.ps1
Last active January 24, 2026 18:01
#Powershell script to move a file to a new location but leave a #symbolic #link behind
<#
.SYNOPSIS
Move a file to a new location but leave a symbolic link behind
.DESCRIPTION
.
.PARAMETER SourcePath
The path to the existing file to move and replace with a symbolic link.
.PARAMETER TargetPath
The target directory where the non-symbolic link file should be moved.
.PARAMETER Verify
@peteraritchie
peteraritchie / new-repo.ps1
Created January 15, 2026 18:13
create empty local git repo and push as public repo to github
git init . && echo "# $(split-path -Leaf $PWD)" > README.md && git add . && git commit -m "Initial commit." && gh repo create --source=. --public --push;
@peteraritchie
peteraritchie / view_gh_rates.ps1
Created January 9, 2026 14:00
View GitHub Rate Limit Usage
gh api rate_limit --jq '.resources | keys[] as $k | "GitHub \($k): \(.[$k].used) of \(.[$k].limit)"'

Make <summary> comments with single line comment into one line

Search for:

^(\s*/// )\<summary\>\s*\r?\n\s*\1(.+\S)\r?\n\s*\1\</summary\>

Replace with:

$1 $2

@peteraritchie
peteraritchie / Svc-Restarter.cs
Created November 13, 2025 23:14
#hypothesis a small program to stop a windows service and restart it when service status is ` Stopped`
// Example in helper process (e.g., RestartService.exe)
using System.ServiceProcess;
using System.Threading;
public class Program
{
public static void Main(string[] args)
{
if (args.Length > 0)
{
// a class to wrapp xunits ITestOutputHelper as a TextWriter
public class TestOutputHelperWriter(ITestOutputHelper helper) : TextWriter
{
public override Encoding Encoding { get; } = Encoding.Unicode;
public override void WriteLine(string? value)
{
helper.WriteLine(value);
}
public override void WriteLine([StringSyntax("CompositeFormat")] string format, params object?[] args)
{
@peteraritchie
peteraritchie / setdns.ps1
Created April 11, 2025 18:30
Set all connected physical network adapters to use google DNS in Admin PowerShell
$nics = (get-netadapter -Physical | where Status -EQ -Value 'Up')
#(get-netadapter -Physical | ? Status -EQ -Value 'Up') | % { Write-Host $_.InterfaceDescription; };
#(get-netadapter -Physical | ? Status -EQ -Value 'Up') | % { Set-DNSClientServerAddress –interfaceIndex $_.ifIndex –ServerAddresses ("8.8.8.8", "8.8.4.4"); };
foreach($nic in $nics)
{
Write-Host "Setting $($nic.InterfaceDescription) DNS to 8.8.8.8, 8.8.4.4";
Set-DNSClientServerAddress –interfaceIndex $nic.ifIndex –ServerAddresses ("8.8.8.8", "8.8.4.4");
}

az devops invoke Areas - Slim

area resourceName routeTemplate
acs WRAPv0.9 {resource}
AdminEngagement Organization _apis/{area}/{resource}/{action}
advSec Enablement _apis/{area}/{resource}
advSec billableCommitters {project}/_apis/{area}/{resource}
advSec EstimateProject {project}/_apis/{area}/Estimate
advSec EstimateRepo {project}/_apis/{area}/repositories/{repositoryId}/Estimate