Skip to content

Instantly share code, notes, and snippets.

View StartAutomating's full-sized avatar

James Brundage StartAutomating

View GitHub Profile
@StartAutomating
StartAutomating / GetMyPowerShellGallery.ps1
Created June 19, 2025 01:44
Gist get My PowerShell Gallery
<#
.SYNOPSIS
Gets my module metadata from the PowerShell Gallery.
.DESCRIPTION
Gets my module metadata from the PowerShell Gallery, without using any modules.
#>
param(
[string[]]
$Conditions = @(
"CompanyName eq 'Start-Automating'",
@StartAutomating
StartAutomating / SparseCloneLexicons.ps1
Created May 23, 2025 01:31
Gist Sparsely Clone AtProto
git clone --depth 1 --no-checkout --sparse --filter=tree:0 https://github.com/bluesky-social/atproto/
Push-Location ./atproto
git sparse-checkout set --no-cone lexicons/**/**.json
git checkout
Pop-Location
@StartAutomating
StartAutomating / FindChromium.ps1
Created May 11, 2025 00:35
Gist Find Chromium
#region Find Chromium
if (-not $script:chromium) {
# Find the chromium executable or alias, pick the first one
$chromium = Get-Command -Name chromium -CommandType Application, Alias -ErrorAction Ignore |
Select-Object -First 1
# If we don't have a chromium alias, we'll try to find the chrome or edge executable.
if ($chromium) {
$script:chromium = $chromium
} else {
# If there's no running instance of chrome, we'll try to find it.
@StartAutomating
StartAutomating / MovingAverage.ps1
Created March 30, 2025 23:28
Gist using the object pipeline to calculate a moving average
function Get-MovingAverage {
<#
.SYNOPSIS
Gets a moving average.
.DESCRIPTION
Gets a moving average of numbers passed to it.
#>
[Alias('MovingAverage')]
param(
# The number we're averaging.
@StartAutomating
StartAutomating / ThereIsNoRouteTable.ps1
Created March 22, 2025 16:13
Gist a web server without a route table
<#
.SYNOPSIS
A pure PowerShell web server
.DESCRIPTION
A pure PowerShell web server proof of concept.
This creates a simple web server that routes commands directly by their local path
That is `/hello` would run the function `/hello` if it exists.
@StartAutomating
StartAutomating / TextToSpeech.ps1
Created February 25, 2025 00:36
Gist a bit of Text to Speech in PowerShell
param(
[string]
$Message = "Coming at you live from the uncanny valley"
)
if ($IsUnix -or $IsMacOS) {
throw "SAPI not available on Unix/MacOS"
}
Start-ThreadJob -ScriptBlock {
$sapi = New-Object -ComObject Sapi.SpVoice
@StartAutomating
StartAutomating / FunctionsInABackgroundJob
Created January 26, 2025 21:22
Gist showing how to declare functions in a background job
Start-ThreadJob {param($V)
foreach ($kv in $v.GetEnumerator()) {
$ExecutionContext.SessionState.PSVariable.Set($kv.Key, $kv.Value)
}
testing
} -Arg @{'function:testing' = {1..3}} | Wait-Job | Receive-Job
@StartAutomating
StartAutomating / EventBasedServer.ps1
Last active June 11, 2025 20:31
Gist a small event-based HTTP server in PowerShell
$JobName = "http://localhost:$(Get-Random -Min 4200 -Max 42000)/"
$httpListener = [Net.HttpListener]::new()
$httpListener.Prefixes.Add($JobName)
$httpListener.Start()
Start-ThreadJob -ScriptBlock {
param($MainRunspace, $httpListener, $SourceIdentifier = 'http')
while ($httpListener.IsListening) {
$contextAsync = $httpListener.GetContextAsync()
while (-not ($contextAsync.IsCompleted -or $contextAsync.IsFaulted -or $contextAsync.IsCanceled)) {}
@StartAutomating
StartAutomating / GetRandomColor.ps1
Created December 27, 2024 00:33
Gist a little random color generator in PowerShell
"#$('{0:x6}' -f (Get-Random -Maximum 0xFFFFFF))"
@StartAutomating
StartAutomating / FindFriday13th
Last active December 13, 2024 18:25
Gist gotta calculate Friday the 13th
function f13($n=13) {
$day, $f13 = (Get-Date).Date, @()
do {
if ($day.DayOfWeek * $day.Day -eq 65) {
$f13 += $day
}
$day = $day.AddDays(1)
} while ($f13.Count -lt $n)
$f13
}