Skip to content

Instantly share code, notes, and snippets.

View peteraritchie's full-sized avatar
😖

Peter Ritchie peteraritchie

😖
View GitHub Profile
@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

az devops invoke Areas

area id maxVersion minVersion releasedVersion resourceName resourceVersion routeTemplate
acs 8b1e4204-96e8-41c2-81ca-5cad5cd5ef25 7.20 0.00 7.1 WRAPv0.9 1 {resource}
AdminEngagement bec0e728-8f67-4ee3-81e8-9f475d184e45 5.10 1.00 0.0 Organization 1 _apis/{area}/{resource}/{action}
advSec 3aa66234-9ab4-4ff9-9d5a-09b7ac9133b1 7.20 7.10 0.0 Enablement 1 _apis/{area}/{resource}
advSec f890a08b-1e12-4f1a-be3f-31a8b361b24e 7.20 7.10 0.0 billableCommitters 1 {project}/_apis/{area}/{resource}
advSec bffb42ee-3cb6-450c-9d11-70797507c7d7 7.20 7.20 0.0 EstimateProject 1 {project}/_apis/{area}/Estimate
advSec 99e4aa9e-93dd-4f07-a70b-928b37aedde0 7.20 7.20 0.0 EstimateRepo 1 {project}/_apis/{area}/repositories/{repositoryId}/Estimate
@peteraritchie
peteraritchie / delete-merged-branches.md
Last active December 28, 2025 18:47
Delete git branches merged to main

Delete git branches merged to main

A simple powershell script to clean up local branches that have been merged to main:

git branch --merged main | Foreach-object { if($_.SubString(0,1) -ne '*'){ git branch -d $_.SubString(2);} }

Delete branches that have been removed in origin

@peteraritchie
peteraritchie / TrySingleExtensionMethod.cs
Created January 9, 2025 18:12
An extension method that uses the Try pattern to get a single value from a collection.
public static class Extensions
{
/// <summary>
/// Try to get the single value from the collection
/// </summary>
/// <typeparam name="T">The type of elements in the collection</typeparam>
/// <param name="source">the source collection</param>
/// <param name="predicate">The predicate to test elements</param>
/// <param name="item">The item found, or null</param>
/// <returns>true if found, false otherwise</returns>