Skip to content

Instantly share code, notes, and snippets.

@NoCheroot
NoCheroot / You Need To Implement Non-Generic.md
Created April 8, 2019 14:15 — forked from Jaykul/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
#![windows_subsystem = "windows"]
extern crate winapi;
extern crate user32;
extern crate kernel32;
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use std::iter::once;
use std::mem;
use std::ptr::null_mut;
@NoCheroot
NoCheroot / combinators.js
Created November 8, 2018 20:21 — forked from Avaq/combinators.js
Common combinators in JavaScript
const I = x => x;
const K = x => y => x;
const A = f => x => f(x);
const T = x => f => f(x);
const W = f => x => f(x)(x);
const C = f => y => x => f(x)(y);
const B = f => g => x => f(g(x));
const S = f => g => x => f(x)(g(x));
const P = f => g => x => y => f(g(x))(g(y));
const Y = f => (g => g(g))(g => f(x => g(g)(x)));
@NoCheroot
NoCheroot / state-example-game.js
Created October 24, 2018 14:15 — forked from hallettj/state-example-game.js
Implementation of a State monad in JavaScript
/*
* Example of a state monad in use. This is adapted from an example on
* the Haskell Wiki:
* http://www.haskell.org/haskellwiki/State_Monad#Complete_and_Concrete_Example_1
*/
require(['state', 'qunit'], function(state, qunit) {
/*
* playGame() is a recursive function that given an array of moves
* defines an algorithm for constructing a final game score. Along
@NoCheroot
NoCheroot / far.ps1
Created October 8, 2018 17:46
Powershell First and Rest
$a, $b = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Write-Host "First: $a"
Write-Host "Rest: $b"
@NoCheroot
NoCheroot / reset-wsl.sh
Created May 25, 2018 19:20 — forked from ishu3101/reset-wsl.sh
Resetting your Windows Subsystem for Linux (WSL) Environment
# Resetting your Windows Subsystem for Linux (WSL) Environment
lxrun.exe /uninstall /full
lxrun.exe /install
@NoCheroot
NoCheroot / struct-by-value.ss
Created May 12, 2018 18:52 — forked from egbulmer/struct-by-value.ss
Chez Scheme FFI - Structs returned by value
(load-shared-object "./libsbv.so")
(define-ftype color
(struct
[r float]
[g float]
[b float]
[a float]))
(define make-rgba
@NoCheroot
NoCheroot / mappedsymbols.rkt
Last active February 13, 2018 20:42
Racket namespace-mapped-symbols example
#lang racket
(let ([n (make-base-namespace)])
(parameterize ([current-namespace n])
(eval '(define (oneplusone) (+ 1 1)))
(eval '(define (oneplustwo) (+ 1 2)))
(filter (lambda (y) (regexp-match #px"^one" y))
(map (lambda (x) (symbol->string x)) (namespace-mapped-symbols n)))))
@NoCheroot
NoCheroot / completion.rkt
Created February 8, 2018 22:37
Quick and dirty completion for a word in Racket
#lang racket
(require framework)
(filter (lambda (x) (regexp-match #px"^def" x)) (text:get-completions/manuals #f))
@NoCheroot
NoCheroot / completion.ps1
Created February 8, 2018 01:45
Powershell CompleteInput example
$cmd = "ConvertTo-Json -"
$ret = [System.Management.Automation.CommandCompletion]::MapStringInputToParsedInput($cmd, $cmd.Length)
$candidates = [System.Management.Automation.CommandCompletion]::CompleteInput(
$ret.Item1,
$ret.Item2,
$ret.Item3,
$null,
[System.Management.Automation.PowerShell]::Create()
).CompletionMatches