This file contains 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 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 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 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 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 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 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 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; | |
} |
This file contains 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
class EventEmitter<T extends object> { | |
private readonly listeners: { | |
[key in keyof T]?: ((value: T[key]) => void)[]; | |
} = {}; | |
emit<Event extends keyof T>(event: Event, value: T[Event]) { | |
const listeners = this.listeners[event]; | |
if (listeners) { | |
listeners.forEach(listener => listener(value)); |
This file contains 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 * as te from 'fp-ts/lib/TaskEither'; | |
import * as arr from 'fp-ts/lib/Array'; | |
import { pipe } from 'fp-ts/lib/pipeable'; | |
type TaskEither<A, B> = te.TaskEither<A, B>; | |
type TERight<T> = T extends TaskEither<any, infer R> ? R : never; | |
/** | |
* Transforms an object of `TaskEither`s into a TaskEither of the resolved objects. |