Skip to content

Instantly share code, notes, and snippets.

View StartAutomating's full-sized avatar

James Brundage StartAutomating

View GitHub Profile
@StartAutomating
StartAutomating / GetLuma.ps1
Created October 18, 2024 05:17
Gist tell me how bright it is
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
@StartAutomating
StartAutomating / HistoryCompleter.ps1
Created October 17, 2024 05:35
Gist a quick history ArgumentCompleter
# 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 {
@StartAutomating
StartAutomating / NotOnAFriday.ps1
Created July 27, 2024 00:36
Gist a little friendly advice about Shipping Software
<#
.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') {
@StartAutomating
StartAutomating / FindReadWriteContainerMounts.ps1
Last active June 7, 2024 17:37
Find Read/Write Mounts in a Container
# When run within a container, this will output the directories that are mounted as read/write.
(Select-String "\S+\s(?<p>\S+).+rw,.+symlinkroot=/mnt/host" "/proc/mounts").Matches.Groups |
Where-Object Name -eq p |
Get-Item -path { $_.Value }
# Hope This Helps! / Have Fun!
@StartAutomating
StartAutomating / UsefulAttributes.md
Last active August 7, 2024 01:04
Potentially Useful Attributes in PowerShell

PowerShell, as a language, is very self-discoverable.

When you Get-Command, you get a rich object about a command.

This can have a lot of metadata.

You can and should also use inline help (like this script does).

Sometimes, I want more metadata than the command or parameter can actually provide.