Skip to content

Instantly share code, notes, and snippets.

@Schniz
Schniz / create.sql
Created Jul 5, 2022
Adding a new schema that's queryable in Supabase
View create.sql
create schema if not exists my_new_schema;
alter default privileges for user supabase_admin in schema my_new_schema grant all
on sequences to postgres, anon, authenticated, service_role;
alter default privileges for user supabase_admin in schema my_new_schema grant all
on tables to postgres, anon, authenticated, service_role;
alter default privileges for user supabase_admin in schema my_new_schema grant all
on functions to postgres, anon, authenticated, service_role;
alter default privileges for user postgres in schema my_new_schema grant all
on sequences to postgres, anon, authenticated, service_role;
alter default privileges for user postgres in schema my_new_schema grant all
View getDependencyTreeWithEsbuild.js
// @ts-check
require('path');
const esbuild = require('esbuild');
async function main() {
const {plugin, set} = createDependencyPlugin();
await esbuild.build({
bundle: true,
View thenable_sync.ts
type Thenable<T> = {
then<R, L = never>(onFulfill: (t: T) => R, onError?: (err: any) => L): Thenable<R | L>,
catch<L>(onError: (err: any) => L): Thenable<T | L>,
}
type Result<T> = { type: "value", value: T } | { type: "error", error: any };
/** Wrapper around simple functions that allow you to `.catch` and `.then` for synchronous functions */
function thenable<T>(createT: () => T): Thenable<T> {
let resultT: Result<T>;
View simple-function-validator.ts
type Validator<Input, Error> = (input: Input) => Error[];
type ExtractValidatorError<V extends Validator<any, any>> = V extends Validator<any, infer A> ? A : never;
function error<Error>(error: Error): Error[] {
return [error];
}
function ok(): any[] {
return [];
}
@Schniz
Schniz / censorCarbonSvg.js
Created Apr 21, 2021
Censor carbon.now.sh exported SVG
View censorCarbonSvg.js
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 Jan 27, 2021
🎒 Asset preloading bag in Rails
View README.md

Usage

Add the following line to your ApplicationController:

around_action AssetPreloadingBag::Filter

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

View matcher.ts
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 Oct 16, 2020
Download Shvetz stickers
View shvetz.js
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();
View turbolinks-preserve-focus.js
View multiline-regex.js
function* enumerate(xs) {
let i = 0;
for (const x of xs) {
yield [i++, x];
}
}
function mregex(modifiers) {
return (strings, ...args) => {
let result = "";