Skip to content

Instantly share code, notes, and snippets.

@disco0
disco0 / PSReadLineMetaInfoKeyHandler.ps1
Created April 26, 2021 10:20 — forked from mklement0/PSReadLineMetaInfoKeyHandler.ps1
PowerShell sample code that demonstrates a PSReadLine key handler that display meta-information about the command being typed in real time.
<#
License: MIT
Author: Michael Klement <[email protected]>
#>
$printableAsciiRangeChars = [char[]] (0x20..0x7f) # 0x7f seemingly acts like Backspace.
$printableAsciiRangeChars + 'Delete' + 'Enter' + 'Escape' | ForEach-Object {
@disco0
disco0 / You Need To Implement Non-Generic.md
Created April 26, 2021 09:19 — forked from NoCheroot/You Need To Implement Non-Generic.md
Implementing IEnumerator<T> in PowerShell

In order to implement IEnumerator<T> you have to explicitly implement the Current member for IEnumerator<T> and IEnumerator ... but PowerShell won't let you have two different implementations of the same property, nor will it let you explicitly implement an interface member. So we do one at a time, like this:

First, make a non-generic IEnumerator, but implemented with the type you want in the end:

    class __Generator : System.Collections.IEnumerator {
        [int]$Actual = 0

        [object]get_Current() {
            return $this.Actual
@disco0
disco0 / index.js
Created April 19, 2021 05:22 — forked from nihonjinrxs/index.js
segment & concat with ffmpeg via node + fessonia
/* original command:
ffmpeg -i video.mp4 -filter_complex "[0:v]trim=1:2,setpts=PTS-STARTPTS[v0]; [0:a]atrim=1:2,asetpts=PTS-STARTPTS[a0]; [0:v]trim=120:125,setpts=PTS-STARTPTS[v1]; [0:a]atrim=120:125,asetpts=PTS-STARTPTS[a1]; [v0][a0][v1][a1]concat=n=2:v=1:a=1[out]" -map "[out]" output.mp4
*/
/*
Rewrite using Fessonia library in node.js
Get Fessonia: https://www.npmjs.com/package/@tedconf/fessonia
Fessonia Docs: https://tedconf.github.io/fessonia/
*/
function Get-ArgumentCompleter {
<#
.SYNOPSIS
Get custom argument completers registered in the current session.
.DESCRIPTION
Get custom argument completers registered in the current session.
By default Get-ArgumentCompleter lists all of the completers registered in the session.
.EXAMPLE
Get-ArgumentCompleter
@disco0
disco0 / wsl2-network.ps1
Created April 5, 2021 10:14 — forked from daehahn/wsl2-network.ps1
WSL 2 TCP NETWORK FORWARDING
# WSL2 network port forwarding script v1
# for enable script, 'Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser' in Powershell,
# for delete exist rules and ports use 'delete' as parameter, for show ports use 'list' as parameter.
# written by Daehyuk Ahn, Aug-1-2020
# Display all portproxy information
If ($Args[0] -eq "list") {
netsh interface portproxy show v4tov4;
exit;
}
@disco0
disco0 / clip
Last active March 27, 2021 19:50 — forked from vor0nwe/clip
clip: WSL zsh script to both read and write to the Windows Clipboard
#!/usr/bin/env zsh
# Drop in xclip replacement for WSL
builtin emulate zsh -L
zparseopts -E -D -- {-help,h}=OPT_HELP {i,-in}=OPT_IN {o,-o}=OPT_OUT
local cmd=${0}
function xclip-help()
@disco0
disco0 / DisplayManager.cs
Created March 25, 2021 09:54 — forked from emoacht/DisplayManager.cs
Manage display devices.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
public static class DisplayManager
{
@disco0
disco0 / About Split-WtTab.md
Created January 25, 2021 07:40 — forked from Jaykul/About Split-WtTab.md
I wrote all of this just to get Split-WTTab

I've been using Windows Terminal since the source code was released, and now that we have support for split panes, I wanted a way to easily create a tab with three panes (one for each version of PowerShell I want to test against).

Unfortunately, there's no support for opening tabs from the command-line yet, nor is there any support yet for specifying which profile to use in a new split terminal. There are open issues for those features, but although I've done a PR or two for it, I didn't think it would be an easy thing to pull together, but I knew that new tabs use the default profile.

Switching the default profile and then creating a new split with the hotkeys works great,

@disco0
disco0 / Show-JsonTreeView.ps1
Created January 18, 2021 05:50 — forked from matthewoestreich/Show-JsonTreeView.ps1
Displays JSON Data in TreeView
function Show-JsonTreeView {
param (
[Parameter(Mandatory)]
$Json
)
function Show-jsonTreeView_psf {
#----------------------------------------------
@disco0
disco0 / Console-TemplateLiteralFormatSpecifiers.ts
Last active December 21, 2020 11:52 — forked from joaomilho/log.ts
A printf with dependant types in TypeScript, similar to Idris (https://gist.github.com/chrisdone/672efcd784528b7d0b7e17ad9c115292)
///<reference lib="dom"/>
//#region Implementation
type FieldType<Field> =
's' extends Field ? string :
'f' extends Field ? number :
'i' extends Field ? number :
'd' extends Field ? number :
'o' extends Field ? HTMLElement :