Skip to content

Instantly share code, notes, and snippets.

@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 July 11, 2025 12:22
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'
@ninmonkey
ninmonkey / Robocopy pwsh wrapper.ps1
Last active August 19, 2024 19:33
Robocopy, a simple wrapper
using namespace System.Collections.Generic
$RoboAppConf ??= @{
Root = $PSScriptRoot | Get-Item
Log = @{
Path = Join-Path (Get-item 'temp:') 'last-robocopy.log'
}
}
function Invoke-Robocopy {
@ninmonkey
ninmonkey / Convert Error To Pairs.js
Last active August 5, 2024 22:52
Convert Error To Pairs.js
// you can run it in your browser's dev console
clipboard = `Requested on,Dataflow name,Dataflow refresh status,Table name,Partition name,Refresh status,Start time,End time,Duration,Rows processed,Bytes processed (KB),Max commit (KB),Processor Time,Wait time,Compute engine,Error,
2024-07-23 11:07:21,MARIDateTable(PQuery),Failed,MariDateTable,NA,Failed,2024-07-23 11:07:21,2024-07-23 11:07:52,00:00:30.9630,NA,NA,NA,NA,NA,NA,Error: Request ID: 1d64d6e8-e9e4-c8e2-a34a-c8d1eddf9697 Activity ID: ed7e87a8-61c0-4dd4-94ab-feb90fa71269`
function ErrorAsPairs ( text ) {
let [ list1, list2 ] = clipboard.split('\n')
zip = (a, b) => a
.map( (k, i) => [ k, b[i] ] ) ;
@ninmonkey
ninmonkey / DockerUtils.Mini.psm1
Created July 23, 2024 20:10
Mini docker utils
Import-Module Rocker -ea 'stop'
function Dock.Container.FirstId {
return (docker container ls)[0].Id
}
Export-ModuleMember -function @('Dock.*') -alias @( 'Dock.*')
@ninmonkey
ninmonkey / Locations of Known Log Files.2024.md
Last active July 21, 2024 18:50
Log Locations for several apps, in one place. Started: 2024-07
@ninmonkey
ninmonkey / AsyncAwait-part1.js
Last active July 19, 2024 19:35
Executing Before Async Await finishes
function resolveAfterDelay(x, ms) {
// async invoke after x milliseconds
return new Promise((resolve) => {
setTimeout(() => {
resolve(x);
}, ms ?? 200 );
});
}
async function f1() {