Skip to content

Instantly share code, notes, and snippets.

View petervandivier's full-sized avatar
🌶️
Why is it spicy?

Peter Vandivier petervandivier

🌶️
Why is it spicy?
View GitHub Profile

This is a markdown file.

graph TD;
    A(with a mermaid diagram)-->B;
    A-->C;
    B-->D;
    C-->D(embedded inside);
@petervandivier
petervandivier / parallel-begin-process-end.ps1
Created May 26, 2023 17:42
ValueFromPipeline processing in a function is serial unless you use a steppable pipeline
#Requires -PSEdition Core
# HT @santisq in powershell-slack
# https://powershell.slack.com/archives/C1RCWRDL4/p1685120926413089
function foo {
param(
[Parameter(Mandatory,ValueFromPipeline)]
[string]
$bar
function New-DateArray {
<#
.EXAMPLE
$days = New-DateArray '2021-01-01' '2021-02-01'
$days | % { $_.ToShortDateString() }
#>
[CmdletBinding()]
Param(
[Parameter()]
@petervandivier
petervandivier / !README.md
Last active July 7, 2022 16:07
Pester PS Class

I'm attempting (and failing) to run a data-driven Pester v5 test over a PS Class. In the Tests/ directory are the 3 (currently failing) implemetations.

@petervandivier
petervandivier / sql2019_showplanxml.xsd
Created May 26, 2022 13:56
schemas.microsoft.com_sqlserver_2004_07_showplan_sql2019_showplanxml.xsd
<xsd:schema xmlns:shp="http://schemas.microsoft.com/sqlserver/2004/07/showplan"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.microsoft.com/sqlserver/2004/07/showplan" elementFormDefault="qualified"
attributeFormDefault="unqualified" version="1.539" blockDefault="#all">
<xsd:annotation>
<xsd:documentation> The following schema for Microsoft SQL Server describes output from the showplan
functionality in XML format. Microsoft does not make any representation or warranty regarding the schema or
any product or item developed based on the schema. The schema is provided to you on an AS IS basis.
Microsoft disclaims all express, implied and statutory warranties, including but not limited to the implied
warranties of merchantability, fitness for a particular purpose, and freedom from infringement. Without
@petervandivier
petervandivier / Get-ClusterDiskSpacePivot.ps1
Last active June 6, 2022 12:34
Get-ClusterDiskSpacePivot
$ComputerList = 1..4 | ForEach-Object {"node-0${_}"}
$LocalHostName = hostname
$disks = foreach($computer in $ComputerList){
if($LocalHostName -eq $computer){
Get-PSDrive -PSProvider FileSystem
}else{
Invoke-Command -ComputerName $computer{
Get-PSDrive -PSProvider FileSystem
}
}
@petervandivier
petervandivier / Merge-ObjectArray.ps1
Created November 24, 2021 17:03
Merge-ObjectArray.ps1
function Merge-ObjectArray {
<#
.DESCRIPTION
Converts an array of objects into a single object with all constituent
properties of each input. If a synonymous property is detected between
inputs, the value is overwritten and a warning is raised but the merge
continues.
.EXAMPLE
$foo = @{foo=1}
date +%FT%T%z
date +%Y%m%dT%H%M%S%z
## 2020-04-30, 11:47:
diff <(jq -S . before.json) <(jq -S . after.json)
du -h --max-depth 1
stat -f "%SB %Sm %N" -t %Y%m%d%H%M%S /var/db/mongodb/index/*
@petervandivier
petervandivier / gdate_best_date.sh
Last active August 11, 2021 09:18
gdate_best_date.sh
#!/usr/bin/env bash
#
# usage: dot-source to export to the current shell context
# . ./gdate_best_date.sh
#
# remove the override with `unset -f`:
# unset -f date
#
if ! ( date --version 2>&1 | grep GNU > /dev/null ); then
#!/usr/bin/env pwsh
#Requires -Modules AWSPowerShell
# TODO: dispose of vars properly...
# not sure atm why they persist in caller scope when dot-sourced :\
[cmdletbinding()]param(
[Parameter(Mandatory=$true)]$AwsMfaCode
,$ProfileName = "default"
)
$serial_number = (aws sts get-caller-identity --profile $ProfileName --output text --query 'Arn').Replace('user','mfa')