Skip to content

Instantly share code, notes, and snippets.

View Jaykul's full-sized avatar
😀
Learning

Joel Bennett Jaykul

😀
Learning
View GitHub Profile
@Jaykul
Jaykul / Import-NugetLibrary.ps1
Last active December 29, 2023 04:59
(Install and) load the assemblies from a NuGet package into PowerShell
#requires -Module PackageManagement
using namespace NuGet
[CmdletBinding(DefaultParameterSetName = 'MaybeUseExisting')]
param(
[Parameter(Mandatory, Position = 0)]
[String]$Name,
[String]$Destination = "$(Split-Path $Profile)\Libraries",
[switch]$ForceReinstall,
@Jaykul
Jaykul / Manifest.psm1
Last active December 28, 2023 05:34
Update Module Version ... or anything else
function Update-Manifest {
#.Synopsis
# Update a PowerShell module manifest
#.Description
# By default Update-Manifest increments the ModuleVersion, but it can set any key in the Module Manifest, its PrivateData, or the PSData in PrivateData.
#
# NOTE: This cannot currently create new keys, or uncomment keys.
#.Example
# Update-Manifest .\Configuration.psd1
#
@Jaykul
Jaykul / Mandelbrot.psm1
Last active December 26, 2023 11:41
ASCII Mandelbrots in the PowerShell console
using namespace System.Numerics
class Mandelbrot : System.Collections.IEnumerator {
# From the constructor?
# Sadly, PowerShell doesn't support optional parameters
[double]$HorizontalViewOffset = -0.5
[double]$VerticalViewOffset = 0
$Columns = 120
$Rows = 28
$ZoomViewDistance = 6.75
@Jaykul
Jaykul / Measure-CommandUsage.ps1
Created November 29, 2023 06:03
Let's have a look at what commands we use
[CmdletBinding()]
param(
# Limit the number of results
[int]$Top
)
$Tokens = @()
$Names = @{}
foreach ($history in [Microsoft.PowerShell.PSConsoleReadLine]::GetHistoryItems()) {
$null = [System.Management.Automation.Language.Parser]::ParseInput($history.CommandLine, [ref]$Tokens, [ref]$null)
@Jaykul
Jaykul / Adding Fonts Without Elevation.md
Last active November 20, 2023 20:55
Temporary Font Install?

Did you know you can install fonts without elevation?

The catch is that they're only available for the duration of your session. They are, however, available in all apps across the system.

Someone asked about how to do it on Facebook this week, and at first, I just pointed them at the install script for PowerLineFonts which loops through all the fonts in a folder and install them.

I've used this more than a few times to install some fonts, including the PowerLine ones, which are great:

$sa = New-Object -ComObject Shell.Application
@Jaykul
Jaykul / WslInstall.psm1
Last active October 3, 2023 21:16
Install WSL2 distros non-interactively
function Add-WslUser {
<#
.SYNOPSIS
Adds a user to a WSL distro
#>
[CmdletBinding()]
param(
# The distro to add the user to
[Parameter(Mandatory)]
$Distribution,
@Jaykul
Jaykul / About Versioning.md
Last active August 29, 2023 17:48
Versioning

Versioning Software

We need our software builds to label the software with a version number.

We want each build to produce a label that is unique enough that we can track a binary back to it's build and the commit it was based on.

We want to follow "Semantic Versioning" because our industry as a whole has decided it's useful.

We want the version number to be predictable, so that (as developers) we know what version of the software we're working on.

When I'm having a bad day, I can spend hours just fiddling with colors and recursion ...

Today I wrote an HslEnumerator class which is fun because if you output it to the PowerShell terminal it just goes on producing colors forever:

[HslEnumerator][PoshCode.Pansies.RgbColor]"Goldenrod" | Format-Wide 30 # I do have a wide screen

But I also made something more fun. Out-Colors will colorize tables or lists with fun HSL rainbows...

@Jaykul
Jaykul / Get-WebCertificate.ps1
Last active August 5, 2023 23:36
ServerCertificateValidationCallback (or rather, collector) for .NET Core
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[Uri]$url
)
Add-Type -TypeDefinition @'
using System;
using System.Net.Http;
using System.Net.Security;
@Jaykul
Jaykul / Reset-Alias.ps1
Last active August 5, 2023 08:09
Set all the default Windows PowerShell aliases, in a powerful, flexible, way.
<#
.SYNOPSIS
Resets all the default PowerShell 5 aliases.
.NOTES
This script must be run by dot-sourcing if you want it to clear the defaul aliases.
It can take quite a while when it's validating all of the commands (a minute and a half, on my system), so it is by far fastest to run it in -Force
.EXAMPLE
Reset-Alias.ps1 -Force -Quiet