Compare if NaN fails a round trip in Powershell or when using System.Text.Json
Ran using: pwsh.exe 7.4. context
| let | |
| Path_Xlsx = "c:\data\workbook.xlsx", | |
| Summary = [ | |
| // [1] using "enter-data" saves a table as json like this | |
| b64_str = "i45WSkosUoqNBQA=", | |
| bytes = Binary.FromText( b64_str, BinaryEncoding.Base64), | |
| bytes_decompressed = Binary.Decompress( bytes, Compression.Deflate), | |
| final_json_str = Text.FromBinary( bytes_decompressed, TextEncoding.Utf8 ), | |
| // [2] converting some binary file to base64 |
| #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) | |
| #> |
| using namespace System.Collections.Generic | |
| function GetLogs { | |
| # BinArgs is built conditionally based on what parameters are used | |
| param( | |
| [int] $Limit, | |
| [datetime] $Since, | |
| [switch] $OneLine, | |
| # preview the command line that's generated without running git |