VS Code feature
WindowsTerminal

windowsTerminal
using "experimental.useBackgroundImageForWindow": true,
Vs Code Features
using multiple cursors
VS Code feature
windowsTerminal
using "experimental.useBackgroundImageForWindow": true,
using multiple cursors
Things to note
options
is an record, when used this way it’s similar to Python’s kwargs
defaults
after config
worksvalues_list
out of order so the logic is on topText.JoinSpecialValues_impl = (source as list, optional options as nullable record) as text =>
let
config = Record.Combine({defaults, options ?? []}),
defaults = [
Separator = "|",
UseSpecialSymbols = true
],
text_list = List.Transform( values_list, Text.From),
joined_string = Text.Combine( text_list, config[Separator] ),
values_list = if not config[UseSpecialSymbols] then source else
List.ReplaceMatchingItems( source,
{
// replace true null, and true empty strings (vs whitespace)
{ null, "␀"},
{ "#(cr,lf)", "#(240d)" }, // is #(2424)" }
{ "#(lf)", "" }, // is #(2424)" }
{"", "␠"}
} )
in
joined_string,
Goto /c/foo/bar
# go back
> Goto -Back
> Goto '-' # normal cd history works too
> Goto '+'
# Goto the world
$Profile | goto # go to string's path
Get-Item $PROFILE | goto # cd to the FileItem's path
gcm EditFunc | goto # jump to function declaration
gmo NameIt | Goto # go to module's folder
[CompletionResult] | goto # to docs for
# <https://docs.microsoft.com/en-us/dotnet/api/System.Management.Automation.CompletionResult>
# Open git repos in browser
goto git microsoft/powerquery-parser | goto
goto git@github.com:microsoft/powerquery-parser.git | goto
# goto the newest log
Get-ChildItem 'c:\root\manyLogs' -Recurse
| Sort LastWriteTime -desc -top 1 | goto
ctrl+spacebar
s
2, 40, 100, 200, 400, <#700, 2000,#> 20000 | %{ $i=$_;
0..10 | %{ $j = $_;
0..3000 | Get-Random -Count 300 | %{ $k = $_
[pscustomobject]@{ DisplayString = [string]$_ }} | fw -Column $i }
"Was: $i"
sleep -sec 0.7 }
Is it a bug, or, is the extra y-axis padding working as intended in a situation where intended is not intended ( ie: column count orders of magnitude larger than the terminal’s column count )
https://insider.office.com/en-us/blog/text-and-array-manipulation-functions-in-excel
a1: e1
, except new functions could dynamically change the selection based on variableWith the column set to Image Url, you’re able to
svg
image programmatically, by placing logic in a measure.png
image into the model/report itself[Inline Png ] :=
"data:image/png;base64, " & SelectedValue( [ColumnWithText] )
/*
note: make sure your GUIDs are strings, why?
because javascript does not have an integer type, so it has to squeeze
inside a floating point, see: <https://discord.com/developers/docs/reference#snowflakes>
*/
const cfg = {
"GuildId": "180528040881815552",
"Channel": "490008213056389120",
}
const apiUri = {
"prefix": "https://discord.com/api/v9/",
"activeThreads": `guilds/${ cfg.GuildId }/threads/active`, // bot only endpoint
"channelMessage50": `channels/${ cfg.Channel }/messages?limit=50`
}
// apiUri.curUri = apiUri.channels
apiUri.curUri = apiUri["channelMessage50"]
console.log(`Cur uri: "${ apiUri.curUri }"`)
curUri = `${ apiUri.prefix }${ apiUri.curUri }`
await fetch(
curUri, lastOpt
).then((r) => r.json()
).then((x) => console.log(JSON.stringify(x)))
Fetch()
or curllastOpt
# [3] main + UX for long exxtensions + Horizontal rules
fd --color=always --changed-within=10hours
| group {
$strExt = $_ | StripAnsi | gi | % Extension
# QOL: don't let massive names break the table
if($strExt.Length -gt 10) { $strExt.Substring(0, 10) } else {$strExt}
}
| %{ $_ ; hr }
| ft -AutoSize
# [1] Minimum required
fd --color=always --changed-within=10hours
| group { $_ | StripAnsi | gi | % Extension }
| ft -AutoSize
# [2] UX: Don't let super long extensions break break columns
fd --color=always --changed-within=10hours
| group {
$strExt = $_ | StripAnsi | gi | % Extension
if($strExt.Length -gt 10) { $strExt.Substring(0, 10) } else {$strExt}
}
| ft -AutoSize
wt
‘s ParametersPS> wt -w theme-test new-tab --title "Tango Light" --profile 'pwsh_nop' --colorScheme "Tango Dark"
PS> wt -w theme-test new-tab --title "Tango Light" --profile 'pwsh_nop' --colorScheme "BirdsOfParadise"
# or
ZD-Invoke-WtThemeTest -Random
bat
to preview results# For every file fd finds, print the first 15 lines
PS> fd --exec-batch bat --line-range=:15 --paging=always
# forcing paging /on/off
PS> fd --exec-batch bat --line-range=:15 --paging=never
'div.premium-box span.btn.btn-info'
Pwsh🐒> # test whether it's resolved by coerce to [type]
'catman' -as 'type' -is 'type'
'batman' -as 'type' -is 'type'
True
False
Pwsh🐒> # test whether it's resolved by coerce to [type]
'catman' -as 'type' -is 'type'
'batman' -as 'type' -is 'type'
True
False
# after
Pwsh🐒> @(
# Declaring a new type in inside a [ScriptBlock]
& {
class batman { [string]$Name }
[batman]
}
# verses dotsourcing a type into the current scope
. {
class catman { [string]$Name }
[catman]
}) | ft -AutoSize
Namespace: <4cf9efd5>
Access Modifiers Name BaseType
------ --------- ---- --------
public class batman object
Namespace: <f2200555>
Access Modifiers Name BaseType
------ --------- ---- --------
public class catman object
BASH
echo -e \\033[{0..100}mhiworld
fd
> grep -c '.*' -- $(fd -e ps1 -e txt -d 1) # ext:ps1,txt depth: 1
# using long-names
> fd --extension ps1 --extension txt --max-depth 1
# 1] highlight matches in red
# 2] preserves all lines
> history | grep --perl-regex --ignore-case --color=always 'less|$'
# 3] add paging
> history | grep --perl-regex --ignore-case --color=always 'less|$' | less --raw-control-chars
# 4] View a log
> less someLog
# 5 start on the last line of a log
> less +G someLog
gh
--json
— then Fzf filter them$allProperties ??= _enumerateGhProperty
$selectedProps = $allProperties
| Out-Fzf -MultiSelect -Layout reverse -Height 100
Invoke-GhRepoList -prop $selectedProps
Labeled Summary of all queries
let
Source = Record.RemoveFields(
#sections[Section1],
"AllQueries", MissingField.Error
),
Summary = Record.ToTable( Source ),
OnlyTables = Table.SelectRows(
Summary, each Value.Is( [Value], Table.Type )
),
#"Add Query Id" = Table.AddIndexColumn(OnlyTables, "Query Id", 0, 1, Int64.Type)
in
#"Add Query Id"
when $null + 3 + 3 = 12
#RRGGBB
or #RRGGBBAA
, you can set alpha
to 0%{ "editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "test1",
"scope": "keyword.operator.assignment.powershell",
"settings": {
"foreground": "#be85c5",
"foreground": "#be85c500",
"fontStyle": "underline"
}
}
],
}}
Power Query Sugar for selecting distinct filters. If the condition is not true, then it throws an error. Name = "Orders"
works because it results in a distinct value from the column Name
It’s valid even though the final query is many records. It’s the “distinctness” of the filter that is required to be true
Source{ [Name = "Orders", Signature = "table"] }
CSS Column Selectors to modify an existing table
https://gist.github.com/ninmonkey/8eb3805012660fc3f0fce86f137fb940
# session
## counting
| wc --lines
| wc --bytes
# hide long results
| tail -n 10
| head -n 10
| tail --lines=100
| tail --bytes=2MB
# or instead don't print to console
# allow colors, but no other ANSI codes
| tail -R
# file listings safer to use
# `ls` output is bad / breakable
find . -iname 'foo*'
find . -iname '*.py'
# as 1 call ?
find . -iname '*.py' -exec stat {} \;
# as many ?
find . -iname '*.py' -exec stat {} +
# require pattern
| grep -i 'required pattern'
# invert matches
| grep -iv 'not pattern'
# or xargs and with args that have whitespace
# and/or exec
# output to file (truncate)
foo > bar.log
# append to file
foo >> bar.log
# hide errors
VERIFY
> someCommand &2>/dev/null
history | grep 'find'
# view in pager, or just a few results
# too big of file
grep 'error' apache.log | less +G
grep 'error' apache.log | tail | less
grep 'error' apache.log > apache_errors.log
tail apache.log --lines=100 | less +G
tail apache.log --lines=100 > apache_mini.log
Discord Web Hooks are easier than you’d think. It uses a regular `HTTP` web request .
Go to: Server Settings -> Integrations -> View Webhooks
Then click create webhook.
copy webhook url
$webhookUri = 'https://discord.com/api/YourWebhookUrlHere'
$Body = @{
'username' = 'Nomad'
'content' = 'https://memory-alpha.fandom.com/wiki/Nomad'
}
Invoke-RestMethod -Uri $webhookUri -Method 'post' -Body $Body
Success!
There are optional webhook arguments to customize the output: https://discord.com/developers/docs/resources/webhook#execute-webhook
curl
I tried making curl
easier to read by splitting content, and pipe so that you don’t have to manually escape Json
$Json = @{ 'username' = 'Nomad'; 'content' = 'https://memory-alpha.fandom.com/wiki/Nomad' } | ConvertTo-Json -Compress
$Json | curl -X POST -H 'Content-Type: application/json' -d '@-' $webhookUri
Sometimes you’ll need to run a command with the same input with different logic.
This can be a hassle using a slow command like Get-ADUser
or Get-ChildItem
on a lot of files like ~
(Home) with -Depth
/ -Recurse
ls ~ -Depth 4 | Format-Table Name
Powershell 7 added the Ternary Operator, and several operators for handling $null
values.
All of these examples will only run Get-ChildItem
the first time. Any future calls are cached.
??=
Assignment OperatorThis is my favorite on the Command line. The RHS
(Right Hand Side) skips evaluation if the left side is not $null
$AllFiles ??= ls ~ -Depth 4
??
Operator$AllFiles = $AllFiles ?? ( ls ~ -Depth 4 )
? whenTrue : WhenFalse
$allFiles = $allFiles ? $allFiles : ( ls ~ -Depth 4 )
Windows PowerShell
and Powershell < 7
Windows Powershell can achieve the same effect with an if statement
if(! $AllFiles) { $AllFiles = ls ~ -Depth 4 }
There’s a lot of ways to use line continuations in Windows Powershell
without backticks . Powershell
added a new one, the |
pipe operator. It’s cleaner to read, and makes it easier to insert, delete, or toggle comments on the console.
Now you can write:
# Powershell
ls | sort Length
| Select -First 10
| ft Name, Length
Instead of piping on line endings
# Windows Powershell
ls | sort Length |
Select -First 10 |
ft Name, Length
# or
ls | sort Length | Select -First 10 | ft Name, Length
The function Label
is from the module: github.com/Ninmonkey.Console
$basePath = 'C:\Program Files'
$calcProp = @{}
$calcProp.FileSize = @{
n = 'Size'
e = { $_.Length | Format-FileSize }
Alignment = 'right'
}
# relative path defaults to relative your current location, so I override it
$calcProp.RelativePath = @{
n = 'RelativePath'
e = {
Push-Location $baseBath
$_.FullName | Resolve-Path -Relative
Pop-Location
}
}
$calcProp.ColorizedName = @{
n = 'ColorName'
e = {
$Color = ($_ | Test-IsDirectory) ? 'blue' : 'green'
Label $_.Name -fg $Color -Separator ''
}
}
$DefaultPropList = 'Name', $calcProp.ColorizedName, $calcProp.RelativePath
Label 'basePath' $basePath
$files = Get-ChildItem $basePath -Depth 2
$files | Format-Table Name, Length, $calcProp.FileSize, $calcProp.RelativePath
$files | Format-Table $calcProp.FileSize, $calcProp.ColorizedName
# Using pre-declared property lists, which may include scriptblocks like $calcProp.FileSize
$files | Format-Table -Property $DefaultPropList