Skip to content

Instantly share code, notes, and snippets.

@JasonKleban
JasonKleban / profile.ps1
Last active March 8, 2021 21:20
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 {
@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 / 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 / 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 / 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 / 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();
git remote get-url origin
git remote set-url origin https://...
Get-ChildItem -r C:\Repos\... |
Select-String -Pattern '^\s*import\s+((?:[^\s{]+)|(?:\*\sas\s[^\s]+))\s+from\s+[''"](\.[^''"]*)[''"];?\s*$' -AllMatches |
Foreach-Object { "import $($_.Matches.Groups[1].Value) from '$([System.IO.Path]::GetFullPath([System.IO.Path]::Combine([System.IO.Path]::GetDirectoryName($_.Path), $_.Matches.Groups[2].Value.replace("/", "\"))))'" }
Get-Unique
@JasonKleban
JasonKleban / convertToTs.ps1
Last active August 27, 2017 13:05
Notes on converting js project to ts
dir -Recurse -Filter "*.js" -Exclude ".git" | rename-item -NewName {$_.name -replace "\.js",".ts"}
@JasonKleban
JasonKleban / blocks.js
Created August 11, 2017 23:40
solves a blocks puzzle
window.addEventListener('load', function(e) {
var pieces = [
[ 28, 6 ],
[ 28, 14 ],
[ 21, 18 ],
[ 10, 7 ],
[ 32, 11 ],
[ 14, 4 ],
[ 28, 7 ],
[ 21, 14 ],