Compare if NaN fails a round trip in Powershell or when using System.Text.Json
Ran using: pwsh.exe 7.4. context
#Requires -Version 7 | |
using namespace System.Collections.Generic | |
using namespace System.Text | |
using namespace System.Text.Json | |
using namespace System.Text.Json.Serialization | |
using namespace System.Linq | |
$assembly = Add-type -AssemblyName System.Text.Json -PassThru -ea 'stop' | |
<# |
<# | |
.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. |
function InvokeWingetInstall { | |
<# | |
.synopsis | |
example of using native commands with dynamic conditions. | |
.example | |
# example commands: Use -TestOnly and -Verbose to see cli arguments, without invoking it. | |
InvokeWingetInstall -Verbose -Package 'Microsoft.PowerBI' -TestOnly -Silent | |
VERBOSE: install --id Microsoft.PowerBI /silent | |
$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)) {} |
using System; | |
using System.Collections.Generic; | |
using System.Collections.ObjectModel; | |
using System.ComponentModel; | |
using System.IO; | |
using System.Management.Automation; | |
using Microsoft.PowerShell.Commands; | |
[EditorBrowsable(EditorBrowsableState.Never)] | |
public abstract class CmdletWithPathBase : PSCmdlet |
Compare if NaN fails a round trip in Powershell or when using System.Text.Json
Ran using: pwsh.exe 7.4. context
# Borrowed this one from https://github.com/chalk/ansi-regex | |
$script:AnsiPattern = "[\u001b\u009b][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?(?:\u001b\u005c|\u0007))|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))" | |
$script:AnsiRegex = [Regex]::new($AnsiPattern, "Compiled"); | |
function MeasureString { | |
[CmdletBinding()] | |
param( | |
[string]$InputObject | |
) | |
$AnsiRegex.Replace($InputObject, '').Length |
<# | |
.SYNOPSIS | |
gcixels is like gci, but with sixels... | |
.DESCRIPTION | |
Shows thumbnails of images with titles, directly in terminal. | |
However, it's done with ImageMagick montage, so it's awfully slow. | |
Just sharing it for your inspiration. | |
.NOTES | |
Requires ImageMagick and a Sixel terminal (like Windows Terminal 1.22+ or WezTerm) | |
#> |
#Requires -PSEdition Desktop | |
[CmdletBinding()] | |
param ( | |
[ValidateSet('AllUsers', 'CurrentUser')] | |
[string] | |
$Scope = 'CurrentUser' | |
) | |
$ErrorActionPreference = 'Stop' |
# Copyright: (c) 2024, Jordan Borean (@jborean93) <[email protected]> | |
# MIT License (see LICENSE or https://opensource.org/licenses/MIT) | |
#Requires -Module Ctypes | |
Function Split-ExeArgument { | |
[OutputType([string])] | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory, ValueFromPipeline)] |