Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Jaykul / Agent Passthru.md
Last active March 10, 2025 15:12
SSH Agent passthru to WSL 2 (working, in Windows 11, in May 2023)

For awhile now, each time I got a new Windows laptop I would dig up strasis gist on how to set up agent forwarding for SSH in WSL2 -- but recently I tried to point someone else at it and they were very confused by it, so this is my attempt at simpler instructions.

Installation

With Chocolatey, you must use an elevated PowerShell session. If there's no choco command found, it will fall back to winget for the npiperelay install. To force using Winget even if you have choco installed, you need to download it, so you can pass parameters to it.

Easy mode: just run this in PowerShell:

@JustinGrote
JustinGrote / Write-FunctionError.ps1
Last active February 28, 2023 21:57
Write an Error within a function in a nice way that displays the context of the function rather than the "Write-Error" context
using namespace System.Management.Automation
using namespace Microsoft.PowerShell.Commands
function Write-FunctionError {
<#
.SYNOPSIS
Writes an error within the context of the containing CmdletBinding() function. Makes errr displays prettier
#>
param(
[Parameter(Mandatory)][String]$Message,
[ValidateNotNullOrEmpty()][ErrorCategory]$Category = 'WriteError',
@ehrnst
ehrnst / containertest.bicep
Created June 16, 2022 07:02
bicep alter params to sub modules
param storageAccountName string
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2021-09-01' = {
name: '${storageAccountName}/default/mycontainer'
}
@fearthecowboy
fearthecowboy / FluentConsole.ps1
Created June 9, 2022 19:16
FluentConsole for PowerShell
<##
FluentConsole Functions
(C) 2022 Garrett Serack
License: MIT
Usage:
dot source this into your script (. FluentConsole.ps1 )
and then you can use the colon-prefixed functions.
You can separate colon-function calls with ';' or '|' or a newline.
@introt
introt / coauthor.py
Last active December 4, 2022 22:20
"Co-authored-by" lines from usernames and issue/PR urls using GitHub REST API
#!/usr/bin/env python3
"""
coauthor.py - credit GitHub users easily
Supports both issue and pull request urls
in addition to GitHub usernames.
Use directly in vim: ":r ! coauthor.py introt" or ":r ! coauthor.py https://github.com/user/repo/pull/1"".
@dfinke
dfinke / psncal.ps1
Created March 19, 2022 13:39
Print the calendar vertically i.e. the weekdays will be shown in a column, not in a row
function psncal {
<#
.SYNOPSIS
Print the calendar vertically i.e. the weekdays will be shown in a column, not in a row
.EXAMPLE
psncal
.EXAMPLE
psncal 1
@sba923
sba923 / df.ps1
Last active December 23, 2024 23:23
*nix work-alike's for PowerShell: df, dirname, whatis, whence
# this is one of Stéphane BARIZIEN's public domain scripts
# the most recent version can be found at:
# https://gist.github.com/sba923/d0d5ad16f2b12d7785adf830b0395dc2#file-df-ps1
function Format-AsKMG
{
param ($bytes,$precision='0')
foreach ($i in ("","KB","MB","GB","TB"))
{
if (($bytes -lt 1000) -or ($i -eq "TB"))
Event
| where EventID == "4104"
| extend ParsedEvent = parse_xml(strcat("<root>", ParameterXml, "</root>"))
| extend MessageNumber = tolong(ParsedEvent.root.Param[0])
| extend MessageTotal = tolong(ParsedEvent.root.Param[1])
| extend ScriptBlockElement = iff(
strlen(tostring(ParsedEvent.root.Param[2]["#text"])) > 0,
ParsedEvent.root.Param[2]["#text"],
ParsedEvent.root.Param[2])
| extend ScriptBlockId = tostring(ParsedEvent.root.Param[3])
@JustinGrote
JustinGrote / Show-MagickProgress.ps1
Last active March 10, 2022 11:41
An Example of parsing command output text into Write-Progress from a Foreach -Parallel Pipeline
$commandOutput = @'
save image[D:\2D\Test\Just Flow Dark 03.png]: 50 of 4500, 20% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 100 of 4500, 40% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 150 of 4500, 60% complete
save image[D:\2D\Test\Just Flow Dark 05.png]: 50 of 4500, 20% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 200 of 4500, 80% complete
save image[D:\2D\Test\Just Flow Dark 03.png]: 250 of 4500, 90% complete
save image[D:\2D\Test\Just Flow Dark 05.png]: 100 of 4500, 40% complete
save image[D:\2D\Test\Just Flow Dark 05.png]: 150 of 4500, 60% complete
save image[D:\2D\Test\Just Flow Dark 05.png]: 200 of 4500, 80% complete
@phil-scott-78
phil-scott-78 / Microsoft.PowerShell_profile.ps1
Last active November 19, 2022 18:19
Powershell Profile
function Run-Step([string] $Description, [ScriptBlock]$script)
{
Write-Host -NoNewline "Loading " $Description.PadRight(20)
& $script
Write-Host "`u{2705}" # checkmark emoji
}
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
$stopwatch = [system.diagnostics.stopwatch]::StartNew()