Skip to content

Instantly share code, notes, and snippets.

@ninmonkey
ninmonkey / Fixing PS1 files utf8 encoded files with no BOM mark and Japanese culture.md
Last active August 16, 2026 19:07
Claude and Powershell 5 - Fixing PS1 files with Japanese and no BOM mark

I found these CLAUDE.md examples that help mitigate when claude or external tools are executed ie: Cases where you can't just modify your profile

The problem is powerh

Traditional fix for current user

In the file $Profile.CurrentUserAllHosts add

@ninmonkey
ninmonkey / Css Pwsh Web Scraping Example - Using CSS Selector Queries.ps1
Last active July 28, 2026 16:16
Web Scraping Example - Using CSS Selector Queries.js
#requires -Modules PSParseHTML
<#
.link
javascript answer: https://gist.github.com/ninmonkey/b59e33cec6765a2c782edaf5c4807b17
#>
Import-Module PSParseHTML
$url = 'https://tavex.pl/zloto/zlote-sztabki/page/1?filter%5Bweight%5D%5B0%5D=1&meta%5B0%5D=tax-gold%3Azlote-sztabki&sorting=recommended'
$html ??= Invoke-WebRequest -url $Url -UseBasicParsing
@ninmonkey
ninmonkey / EditFunc-Definition.ps1
Created July 10, 2026 16:35
EditFunc - Jump to profile functions in Vs Code.ps1
function EditFunc {
<#
.SYNOPSIS
Finds where a function is defined, opens it in vs code -- and jumps to the line number it starts on
.example
gcm prompt | EditFunc
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
@ninmonkey
ninmonkey / PwshExponents.md
Last active June 5, 2026 19:22
Powershell sugar for exponents
function Pow { param( $base, $pow ) [Math]::Pow( $base, $pow ) }
filter  fPow { param( $Pow ) [Math]::Pow( $_, $pow ) }
filter  IPow { param( $Base ) [Math]::Pow( $base, $_ ) }
function Csv { $input | Join-String -sep ', ' }

3 Different interfaces

Pow 2 7    
@ninmonkey
ninmonkey / Simple-EscapeControlChar.ps1
Created October 12, 2025 20:50
Tiny Escape Control Char Pwsh7
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
@ninmonkey
ninmonkey / Combine-Table.AddRows.pq
Created July 19, 2025 21:22
Merge multiple `Table.AddRows` and schema transforms into fewer steps
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( _ ) }
),
@ninmonkey
ninmonkey / Using Powershell New or Assignment.md
Last active May 17, 2025 17:46
Testing `type = @( $data )` and `[type]::new( $data )`

Explicitly calling ::new()

using namespace System.Collections.Generic
$example = 9, 4, 3

[List[int]]::new( [int[]]$example ) 
  • I had to type it as an [int[]]
@ninmonkey
ninmonkey / BasicTable.html
Last active May 16, 2025 19:04
Focing Html with 3 columns to `<table>` to share column widths
<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>
@ninmonkey
ninmonkey / Saving-Excel-Workbook-As-Base64-Round-Trip.pq
Last active April 25, 2025 17:14
Saving-Excel-Workbook-As-Base64-Round-Trip.pq
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
@ninmonkey
ninmonkey / PwshClass▸Using▸Text.Json.ps1
Last active April 20, 2025 21:06
AutoJson.Basic-Text.Json.md
#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'
<#