Skip to content

Instantly share code, notes, and snippets.

View Schniz's full-sized avatar

Gal Schlezinger Schniz

View GitHub Profile
@Schniz
Schniz / censorCarbonSvg.js
Created April 21, 2021 14:32
Censor carbon.now.sh exported SVG
function textNodesUnder(el){
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}
for (let node of textNodesUnder(document.documentElement)) {
node.nodeValue = node.nodeValue.replace(/[^\s]/g, '█');
}
@Schniz
Schniz / README.md
Last active January 27, 2021 21:27
🎒 Asset preloading bag in Rails

Usage

Add the following line to your ApplicationController:

around_action AssetPreloadingBag::Filter

And when you want to prerender something, you can simply call:

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);
@Schniz
Schniz / shvetz.js
Created October 16, 2020 09:41
Download Shvetz stickers
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();
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())
@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 / 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.