Skip to content

Instantly share code, notes, and snippets.

@JasonKleban
JasonKleban / lock-step.ts
Last active March 27, 2019 11:53
Convert events into Promises to be awaited
export interface LockStep<T = void> {
edge : Promise<T>;
}
export class LockStepper<T = void> implements LockStep<T> {
private _edge! : Promise<T>;
private _resolve! : (value?: T | PromiseLike<T> | undefined) => void;
constructor () {
this.rearm();
@JasonKleban
JasonKleban / LiteEventStricter.ts
Last active June 17, 2021 18:40
A stricter variation of https://gist.github.com/JasonKleban/50cee44960c225ac1993c922563aa540 . This version changes function signatures in the case of `T extends void` to take no data parameter, freeing the non-void case to require its data parameter.
interface ILiteEvent<T> {
on(handler: T extends void
? { (): void }
: { (data: T): void }): void;
off(handler: T extends void
? { (): void }
: { (data: T): void }): void;
}
class LiteEvent<T> implements ILiteEvent<T> {
@JasonKleban
JasonKleban / raph.ts
Last active October 22, 2019 16:15
raph.ts - DSL for specifying immutable graphs of nodes and edges.
/**
* DSL for specifying graphs of nodes and edges.
* Graphs are immutable and create a new graph object for each operation.
* Graphs are stateful about a subject node and a subject edge for purposes of
* creating new edges and adding attributes to the subject node or subject edge.
* From the perspective of a user DSL code listing, the last _mentioned_ node is the
* subject node to which new edges or attributes are added and the last mentioned
* edge is the subject edge to which attributes are added.
*/
namespace Raph {
@JasonKleban
JasonKleban / argParser.fs
Created November 5, 2019 02:16
Minimal monadic parsing combinator, example grammar, and test cases
#nowarn "40"
open System
// Complete Monadic Parsing "Library"
type Parser<'r> = Parser of (char list -> ('r*char list) list)
let parse (Parser p) = p
let (>>=) p f = Parser(fun cs ->
List.concat [for (r,cs') in parse p cs -> parse (f r) cs'])
@JasonKleban
JasonKleban / declaration-bundler-webpack-plugin.js
Created December 31, 2020 19:56
WIP declaration-bundler-webpack-plugin.js adapted for Webpack 5?
/* adapted from recommended but unmaintained and archived
smol/declaration-bundler-webpack-plugin. Rather than maintaining a fork, let's
just see how far we can get by rolling it in */
module.exports = class DeclarationBundlerPlugin
{
out /* :string */;
moduleName /* :string */;
mode /* :string */;
@JasonKleban
JasonKleban / profile.ps1
Last active February 24, 2025 14:55
posh-git add last command duration
# Might not work before Powershell 7 (`$PSVersionTable`)
# Might not work before Posh-Git v1 (https://github.com/dahlbyk/posh-git#installing-posh-git-via-powershellget-on-linux-macos-and-windows)
#
# Find this file's path by running `$Profile`
Import-Module posh-git
$begin = (Get-Date)
function Prefix {