This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type IndexableKeys<T> = { [key in keyof T]: T[key] extends string ? key : never }[keyof T]; | |
function matcher<T>(): <K extends IndexableKeys<T>>(key: K) => <R>( | |
legs: { | |
[key in Extract<T[Extract<K, keyof T>], string>]: (arg: T & Record<K, key>) => R | |
} | |
) => (t: T) => R { | |
return (key) => (legs) => (t) => { | |
const state = t[key]; | |
return legs[state](t); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require("puppeteer"); | |
const { default: fetch } = require("node-fetch"); | |
const path = require("path"); | |
const fs = require("fs"); | |
const FILES = path.join(__dirname, "shvetz"); | |
async function main() { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let lastFocusedId = null; | |
document.addEventListener("turbolinks:request-start", function () { | |
const element = document.querySelector( | |
"[data-turbolinks-preserve-focus]:focus" | |
); | |
if (element) { | |
lastFocusedId = element.id; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* enumerate(xs) { | |
let i = 0; | |
for (const x of xs) { | |
yield [i++, x]; | |
} | |
} | |
function mregex(modifiers) { | |
return (strings, ...args) => { | |
let result = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SetUUID() { | |
var spreadsheet = SpreadsheetApp.getActive(); | |
const range = spreadsheet.getActiveRange() | |
range.setValues(range.getValues().map(v => v.map(() => Utilities.getUuid()))); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::HashMap; | |
trait Renderable: core::fmt::Debug { | |
fn render(&self) -> String; | |
} | |
impl<A: Renderable, B: Renderable> Renderable for (A, B) { | |
fn render(&self) -> String { | |
format!("{}{}", self.0.render(), self.1.render()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////// Array utilities | |
type Length<T extends any[]> = T["length"]; | |
type Head<T extends any[]> = T[0]; | |
type Tail<T extends any[]> = ((...xs: T) => any) extends ((_x: any, ...xs: infer R) => any) ? R : []; | |
type AllTrue<Ts extends any[]> = { | |
0: true, | |
1: false, | |
2: AllTrue<Tail<Ts>> | |
}[Length<Ts> extends 0 ? 0 : Head<Ts> extends false ? 1 : 2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo ' | |
activate application "Reminders" | |
tell application "System Events" to keystroke "n" using command down | |
tell application "System Events" to keystroke "'"$*"'" | |
tell application "System Events" to keystroke return | |
' | osascript - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Command } from 'commander'; | |
export class Program<ArgumentTypes extends { [key: string]: any }> { | |
private readonly parseFn: (cmd: Command) => ArgumentTypes; | |
private readonly command: Command; | |
constructor(command: Command, parse: (cmd: Command) => ArgumentTypes) { | |
this.parseFn = parse; | |
this.command = command; | |
} |