Skip to content

Instantly share code, notes, and snippets.

[xml]$doc = gc (Join-Path $PSScriptRoot './sample.xml')
[xml]$Doc = @'
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<setting name = "logLevel" value = "verbose" />
<setting name = "root" value = "c:/foo" desc = "users root dir" />
</configuration>
'@
@ninmonkey
ninmonkey / Simple Format Control char Symbols in PowerShell 7.ps1
Last active September 19, 2024 16:18
Show ansi escapes for runes in Powershell 7
function Format-ControlChar {
<#
.synopsis
converts ANSI control chars into human-visible symbols.
.description
Because they are not ansi escapes ( control chars ), they have no special meaning
so they are save to pipe to your terminal or transport.
This is written in for Pwsh7 because it simplifes code
#>
@ninmonkey
ninmonkey / Power Query Sleep using Function.InvokeAfter.pq
Created September 10, 2024 17:43
Testing if Query Diagnostics include sleeping as the full duration for that step. Yes.
let
/* testing delays in query diagnostics */
seconds = 5,
resp1 = [
Bytes = Web.Contents( "https://httpbin.org", [ RelativePath = "/links/3/1" ] ),
Who = Diagnostics.ActivityId()
],
resp2 =
Function.InvokeAfter(
@ninmonkey
ninmonkey / Collect Favicons using DOM Selector Queries.ps1
Last active September 3, 2024 12:39
Combining a simple `CSS` / `XPath` query with regex works fairly well to find `icon` resources
#Requires -Module 'PSParseHtml'
<#
.Synopsis
Combining a simple `CSS` / `XPath` query with regex works fairly well to find `icon` resources
#>
[Uri] $Url = 'https://na.alienwarearena.com'
$xpath_doc ??= ConvertFrom-Html -Url $Url -Engine AgilityPack
$css_doc ??= ConvertFrom-Html -Url $Url -Engine AngleSharp
@ninmonkey
ninmonkey / Teams Invoke-WebRequest returns bytes vs text depending on Powershell Version Summary.md
Last active September 2, 2024 16:26
Stand-Alone test to reproduce similar errors with summary
@ninmonkey
ninmonkey / Invoke Aws S3 Command Line.ps1
Last active August 31, 2024 17:52
Powershell wrapper to invoke aws s3
function InvokeS3 {
<#
.SYNOPSIS
wraps the aws s3 command with some validation
.example
InvokeS3 -WhatIf -Source /tmp/foo -Recursive
# VERBOSE: s3 cp /tmp/foo s3://bucket/
InvokeS3 -WhatIf -Source '.' -Recursive -Includes '*.jpg', '*.png' -Excludes '*'
@ninmonkey
ninmonkey / Export gh gist list as object.ps1
Last active August 30, 2024 23:42
Converts gh repo list output to objects, sorted by a regex and optionally out-gridview
function Dotils.Gh.Gist.List.Export {
<#
.SYNOPSIS
Quickly list your own gists and pipe
#>
param(
[int] $Limit = 200,
[string] $Pattern,
[switch] $OutGridView
)
@ninmonkey
ninmonkey / Get Vscode cli.js Source mapping.ps1
Created August 30, 2024 16:25
View the Source Code for VsCode's luancher. It shows the not-minified version of "C:\Program Files\Microsoft VS Code\resources\app\out\cli.js"
<#
see also:
Cli and bootstrap files in: https://github.com/microsoft/vscode/tree/main/src
You could grep the tree for the Env vars it uses
Using this syntax prevents accidentally launching code (the native command) with a broken filepath. Like if you missed quotes.
otherwise it'll try to make it.
code -g (gi -ea 'stop' $path)
@ninmonkey
ninmonkey / ListObject-For-DynamicNativeCommands.ps1
Last active August 24, 2024 22:32
using `[List[Object]]` to build native `git` command arguments
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
@ninmonkey
ninmonkey / Git from powershell using conditional logic to build native args.ps1
Created August 6, 2024 23:21
Git from powershell using conditional logic to build native args.ps1
using namespace System.Collections.Generic
# the final command will be
# git clone --branch release/v7.4 --shallow-since=2024-07-07 https://github.com/PowerShell/PowerShell
$cloneUrl = 'https://github.com/PowerShell/PowerShell'
$Since = [datetime]::Now.AddDays(-30 )
$Branch = 'release/v7.4'
$binGit = Get-Command -Name 'git' -CommandType Application -ea 'stop'
# this bypasses most aliases or functions named 'git'