This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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)) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"#$('{0:x6}' -f (Get-Random -Maximum 0xFFFFFF))" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter GetLuma { | |
$colorString = $_ | |
# Convert the background color to a uint32 | |
$rgb = ($colorString -replace "#", "0x" -replace ';') -as [UInt32] | |
# then make it into a percentage red, green, and blue. | |
$r, $g, $b = ([float][byte](($rgb -band 0xff0000) -shr 16)/255), | |
([float][byte](($rgb -band 0x00ff00) -shr 8)/255), | |
([float][byte]($rgb -band 0x0000ff)/255) | |
# Calculate the luma of the background color |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function without a [CmdletBinding] attribute or [Parameter] attributes is freeform. | |
# Let's declare a little function that just outputs the name and arguments | |
function I { | |
param() | |
@($MyInvocation.InvocationName) + $args | |
} | |
# We can use Register-ArgumentCompleter to register the completer for a named command. | |
# This simple completer will show any matching history items | |
Register-ArgumentCompleter -CommandName I -ScriptBlock { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Not On a Friday. | |
.Description | |
Gist a little bit of friendly advice about the wisdom of shipping software on a Friday. | |
.Notes | |
Yes, this runs. | |
#> | |
[ValidateScript({ | |
if ([DateTime]::Now.DayOfWeek -eq 'Friday') { |
NewerOlder