using namespace System.Collections.Generic
$example = 9, 4, 3
[List[int]]::new( [int[]]$example ) - I had to type it as an
[int[]]
| filter EscapeCC { | |
| ($_)?.EnumerateRunes() | % { | |
| ($_.Value -le 32) ? [Text.Rune]( $_.Value + 0x2400 ) : $_ | |
| } | Join-String | |
| } | |
| "sdf `a sdjf hi world`t`n ${fg:#feaa99} more stuff `u{0} `r`n blah" | escapeCC | |
| # outputs: sdf␠␇␠sdjf␠hi␠world␉␊␠␛[38;2;254;170;153m␠more␠stuff␠␀␠␍␊␠blah |
| let | |
| startDate = DateTime.Date( DateTime.LocalNow() ), | |
| endingOffset = 1000, // in days | |
| endingOffsetDate = Date.AddDays( startDate, endingOffset ), | |
| allDays = List.Transform( | |
| { Number.From(startDate)..Number.From(endingOffsetDate) }, | |
| each { Date.From( _ ) } | |
| ), |
| <html><body> | |
| <table class="cols-3"> | |
| <tr> | |
| <th>Company</th> | |
| <th>Contact</th> | |
| <th>Country</th> | |
| </tr> | |
| <tr> | |
| <td>Alfreds Futterkiste</td> | |
| <td>Maria Anders</td> |
| 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' | |
| <# |
| void updateHunger() { | |
| // applied about every 1 second? | |
| curDrain = GetCurrentDrain(); | |
| energy -= curDrain // but clamps to keep it >= 0 | |
| newTier = GetTier( energy ) | |
| if ( newTier != curTier ) { | |
| SetTier( newTier ) | |
| } | |
| } |
| # Assumes pwsh7 | |
| # tip: pwsh 7 added overloads | |
| $StrIn = 'Г¶' | |
| $bytes = [Text.Encoding]::GetEncoding(1252).GetBytes( $StrIn ) | |
| $Bytes = [Text.Encoding]::GetEncoding('utf-8').GetString( $bytes ) | |
| # and also | |
| $StrIn.EnumerateRunes | Ft -auto |