Skip to content

Instantly share code, notes, and snippets.

View Schniz's full-sized avatar

Gal Schlezinger Schniz

View GitHub Profile
function* enumerate(xs) {
let i = 0;
for (const x of xs) {
yield [i++, x];
}
}
function mregex(modifiers) {
return (strings, ...args) => {
let result = "";
function SetUUID() {
var spreadsheet = SpreadsheetApp.getActive();
const range = spreadsheet.getActiveRange()
range.setValues(range.getValues().map(v => v.map(() => Utilities.getUuid())));
};
@Schniz
Schniz / machine.js
Created April 21, 2020 19:41
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@Schniz
Schniz / playground.rs
Created September 18, 2019 20:05 — forked from rust-play/playground.rs
Code shared from the Rust Playground
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())
////////////////////////////////////////////////////////////// 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]
@Schniz
Schniz / rmt
Created August 27, 2019 08:49
Remind me to (using Apple reminders)
#!/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 -
@Schniz
Schniz / typesafe-commander.ts
Last active July 31, 2019 10:52
TypeSafe builder pattern for commander
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;
}
@Schniz
Schniz / event_emitter.ts
Created July 25, 2019 09:11
Typesafe event emitters
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));
@Schniz
Schniz / TaskEither_record.ts
Last active August 8, 2019 06:25
A record combinator for fp-ts TaskEither
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.