Skip to content

Instantly share code, notes, and snippets.

View trackd's full-sized avatar

Andree Renneus trackd

View GitHub Profile
@trackd
trackd / ConvertTo-MarkdownTable.ps1
Last active June 25, 2024 22:20
ft as markdowntable
function ConvertTo-MarkdownTable {
<#
.DESCRIPTION
Convert an object to a markdown table.
.PARAMETER InputObject
The object to convert to a markdown table.
.PARAMETER Property
The properties to display in the table.
function Get-PowershellDLEHint {
$iwr = (Invoke-WebRequest 'https://powershelldle.com/').Content
$strings = ($iwr | Select-String -Pattern '<div id="answer-char" class="(relative bottom-1)?">\s*[_-]\s*</div>' -AllMatches).Matches.Value
$verb, $noun = ($strings -replace '<[^>]+>').Trim() -join '' -split '-'
Get-Command | Where-Object { $_.Verb.Length -eq $verb.length -And $_.Noun.Length -eq $noun.length }
}
function Get-TableData {
<#
ls | ft | Get-TableData
.NOTES
https://gist.github.com/Jaykul/9999be71ee68f3036dc2529c451729f4
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline)]
$FormatStartData
@trackd
trackd / Get-AnsiEscape.ps1
Last active May 5, 2024 11:12
something
Update-TypeData -TypeName '_RegexAnsi' -MemberType ScriptMethod -MemberName ToString -Force -Value {
return ($this.Value ? $this.value : $this.Text)
}
Update-TypeData -TypeName 'System.Management.Automation.Internal.StringDecorated' -MemberType ScriptMethod -MemberName ToString -Force -Value {
return $this.IsDecorated
}
function Get-AnsiEscape {
<#
.DESCRIPTION
Get-AnsiEscape can be used to strip, escape, or regex VT codes from a string.
function Enable-DebugSpectre {
[cmdletbinding()]
param()
$moduleName = 'PwshSpectreConsole'
$module = Get-Module -Name $ModuleName
if (-Not $Module) {
$Module = Import-Module $ModuleName -PassThru
}
$new = {
param(
function Set-DemoPrompt {
<#
.SYNOPSIS
Creates a simple prompt with WT highlighting using a temporary module.
minor trickery with setting an alias for prompt so we can easily restore old prompt on module removal.
.NOTES
it adds terminal prompt markings for WT Preview.
see links below for more info
.LINK
https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration#powershell-pwshexe/
@trackd
trackd / protocolhandler-clipboard.ps1
Created December 28, 2023 01:50
prototype something something
function Add-ClipboardProtocolHandler {
# clipboard://
$custom = Get-Command "$env:temp\customclip.exe" -CommandType Application -ErrorAction 'Stop'
$uri = 'clipboard'
if (!(Test-Path "HKCU:\Software\Classes\$uri")) {
New-Item "HKCU:\Software\Classes\$uri"
}
Set-ItemProperty "HKCU:\Software\Classes\$uri" '(Default)' "URL:$uri Protocol"
Set-ItemProperty "HKCU:\Software\Classes\$uri" 'URL Protocol' ''
if (!(Test-Path "HKCU:\Software\Classes\$uri\shell")) {
function ConvertTo-TableFormat {
<#
.SYNOPSIS
Rebuild an object based on the Format Data for the object.
.DESCRIPTION
Allows an object to be rebuilt based on the view data for the object. Uses Select-Object to create a new PSCustomObject.
#>
[CmdletBinding()]
param (
<#
yoinked and just stripped the namespace and change internal to public
https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/utils/FuzzyMatch.cs
https://www.geeksforgeeks.org/damerau-levenshtein-distance/
https://yassineelkhal.medium.com/the-complete-guide-to-string-similarity-algorithms-1290ad07c6b7
#>
Add-Type -TypeDefinition @'
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
@trackd
trackd / Get-TibberMonth.ps1
Last active November 9, 2023 20:24
example code how to format query for retrieving a month from the GraphQL api
function Get-TibberMonth {
<#
.DESCRIPTION
gets tibber usage for a month, will automatically turn any date into the first day of the month
and will calculate the amount of hours for that month
.PARAMETER Startdate
startdate
if no enddate is given it will take day 1 of the month in startdate and +1 month
.PARAMETER Enddate
enddate