Skip to content

Instantly share code, notes, and snippets.

@Jaykul
Jaykul / You Need To Implement Non-Generic.md
Created April 27, 2016 01:48
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
@ericclemmons
ericclemmons / example.md
Last active September 20, 2024 12:46
HTML5 <details> in GitHub

Using <details> in GitHub

Suppose you're opening an issue and there's a lot noisey logs that may be useful.

Rather than wrecking readability, wrap it in a <details> tag!

<details>
 Summary Goes Here
@Zetanova
Zetanova / signal-cancellation.ps1
Last active March 26, 2025 07:15
Use Signal 'ctrl+c' as CancellationTokenSource for sync-over-async calls
using namespace System.Linq.Expressions
#class to register on posix signal and provide a cancellation token
#many signal are working under windows (SIGINT, SIGQUIT ...)
class SignalToken : System.IDisposable {
hidden [System.Threading.CancellationTokenSource]$cts
hidden [System.Runtime.InteropServices.PosixSignalRegistration]$reg
[System.Runtime.InteropServices.PosixSignal]$Signal = [System.Runtime.InteropServices.PosixSignal]::SIGINT
[System.Threading.CancellationToken]$Token