Skip to content

Instantly share code, notes, and snippets.

@clinuxrulz
clinuxrulz / Plugin.ts
Last active March 4, 2024 09:15
Browser Plugin Utility (bidirectional asynchronous function calls)
export class Plugin {
private src: String;
private callbacks: any;
private iframe?: HTMLIFrameElement;
private messageHandler: (e: MessageEvent) => void;
private recvMsgHandler: (msg: string) => void;
private nextCallId: number = 0;
private resolveMap: any;
onLoad: () => void = () => {};
@mizchi
mizchi / printTemplate.ts
Created February 9, 2021 08:20
Generate code from svelte ast
import prettier from "prettier/standalone";
import produce from "immer";
import { parse } from "svelte/compiler";
import type { Ast } from "svelte/types/compiler/interfaces";
// @ts-ignore
import * as sveltePlugin from "prettier-plugin-svelte";
function printTemplate(ast: Ast) {
const overridePlugin = produce(sveltePlugin, (d: any) => {
d.parsers.svelte.parse = () => {
@chrisveness
chrisveness / crypto-sha.js
Last active July 20, 2023 04:45
Uses the SubtleCrypto interface of the Web Cryptography API to hash a message using SHA-256.
/**
* Returns SHA-256 hash from supplied message.
*
* @param {String} message.
* @returns {String} hash as hex string.
*
* @example
* sha256('abc').then(hash => console.log(hash));
* const hash = await sha256('abc');
*/