Skip to content

Instantly share code, notes, and snippets.


Joel Bennett Jaykul

View GitHub Profile
Jaykul / PSReadlineHotkeys.ps1
Last active Jul 2, 2021
Indent and Outdent hotkeys for PSReadline
View PSReadlineHotkeys.ps1
# Hack in a [ReadLine] accelerator
$xlr8r = [psobject].assembly.gettype("System.Management.Automation.TypeAccelerators")
if ($xlr8r::AddReplace) {
$xlr8r::AddReplace("ReadLine", [Microsoft.PowerShell.PSConsoleReadLine])
} else {
$null = $xlr8r::Remove("ReadLine")
$xlr8r::Add("ReadLine", [Microsoft.PowerShell.PSConsoleReadLine])
# Now some key handlers
Jaykul / A retro
Last active Apr 20, 2021
Retro Terminal
View A retro

I borrowed crt.hlsl from Hammster although I've tweaked it a little.

You need a terminal profile with something like this in it:

    // This is the shader and a background with the monitor in it, because that's easy
    "experimental.pixelShaderPath": "C:\\Users\\Jaykul\\crt.hlsl",
    "backgroundImage": "C:\\Users\\Jaykul\\crt.png",
    "backgroundImageAlignment": "center",
Jaykul / About Non-Mandatory Dynamic
Last active Mar 2, 2021
Sometimes you need that parameter to be mandatory, but the rest of the time, you use an environment variable.
View About Non-Mandatory Dynamic

When you're writing scripts that are primarily meant for use in continuous integration or deployment environments, a lot of your inputs (maybe all of your inputs) are going to come from environment variables that are always set when you're running the scripts in production (but which rarely exist on your development box). There are a lot of different ways of handling this, but the one I find most elegant is to use PowerShell's dynamic parameter block.

Dynamic parameters in PowerShell have a couple of downsides (which, now that I think of it, we should really see about fixing, since PowerShell is open source).

  • The first is that they are not easily discoverable. Even when you're in the conditions where the dynamic parameters will be emitted, they do not show up in either Get-Help or Get-Command (nor even in Get-Parameter, which does fetch dynamic parameters added by providers, but doesn't find the ones added by the command itself).
  • The second is that they don't set variables in the function
Jaykul / Invoke-WithRetry.ps1
Created Jan 20, 2021
There are so many ways to write this...
View Invoke-WithRetry.ps1
function Invoke-WithRetry {
Invoke a ScriptBlock until it returns a value (or until a certain ammount of time elapses)
Invokes the given ScriptBlock on $RetryEvery interval until it returns a value.
If the $Limit time passes without a value, returns nothing.
$Time = (Get-Date).AddMinutes(0.5)
Invoke-WithRetry { if($Time -lt (Get-Date)) { return $Time } }
Jaykul / ProgrammerNotebooks.ipynb
Last active Jan 14, 2021
Interactive Coding Notebooks: The Swiss Army Knife of data programming
View ProgrammerNotebooks.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Jaykul / About the better
Last active Dec 18, 2020
You really should be able to control the prompt ...
View About the better

Here's something I was inspired to write by a thread on twitter this morning: a better [Credential()] attribute. It allows you to configure the prompt that is presented to the user if they only provide a name -- and by specifying a default value (even an empty string), to make the credential mandatory while still controlling the prompt:

function Test-Credential {
    [BetterCredential(Title="Mandatory Credential", Prompt="Please provide the password for the TeamLab", MandatoryPassword)]
    [PSCredential]$Credential = "TeamAdmin"
Jaykul / Get-HelpInfo.ps1
Created Dec 12, 2020
Some simple analysis of updateable help
View Get-HelpInfo.ps1
filter Get-HelpInfo {
Get a ((list of) en-US culture-specific?) HelpInfo details (the URL and version number) for modules
Get-Module Microsoft.* -ListAvailable | Get-HelpInfo
[System.Management.Automation.PSModuleInfo]$Module = $((Get-Module WindowsUpdateProvider -List)[0])
View Expand-StringVariables
function Expand-AstVariables {
param (
[Parameter(Mandatory, ValueFromPipeline)]
[System.Management.Automation.Language.Ast] $Statement,
[ref] $result,
[PSObject] $Properties
Jaykul / Packer.ps1
Last active Jun 14, 2021
There are so many ways to embed code (dlls OR script)
View Packer.ps1
using namespace System.IO
using namespace System.IO.Compression
using namespace System.Text
[string]$Path = $PSCommandPath
function CompressToString {
Jaykul / Measure-Script.ps1
Created Oct 22, 2020
We need a better Measure-Command which can show averages
View Measure-Script.ps1
filter Measure-Script {
A wrapper for Measure-Command to run commands multiple times and report averages (avg, min, max)
# The script to measure