Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / ee.js
Last active April 21, 2022 13:24
EventEmitter
const assert = (condition, message = 'Assertion failed') => {
if (!condition) {
throw new Error(message);
}
}
export class EventEmitter {
#listeners = Object.create(null);
on (type, listener) {
@intrnl
intrnl / wc-router.js
Last active May 5, 2022 14:06
Custom elements router
const _location = location;
const _addListener = addEventListener;
const _removeListener = removeEventListener;
const isFunction = (x) => typeof x === 'function';
const createElement = (el) => isFunction(el) ? new el() : document.createElement(el);
export const createRouter = ({ base, routes }) => {
base = '/' + (base || '').replace(/^\/+|\/+$/g, '');
@intrnl
intrnl / TachiyomiBackup.proto
Created April 11, 2022 02:55
Tachiyomi backup protobuf schema
syntax = "proto3";
package TachiyomiBackup;
// based on commit 5afff31f7246d0ede03344c955a47f4817e9fb92
message BackupManga {
int64 source = 1;
string url = 2;
string title = 3;
@intrnl
intrnl / dashlane.js
Created March 10, 2022 07:59
Dashlane's random password generator
/**
* @fileoverview
* Dashlane's password generator
* https://www.dashlane.com/features/password-generator
*/
/**
* Generates a password
* @param {PasswordGeneratorOptions} options
* @returns {string}
@intrnl
intrnl / random.js
Last active March 10, 2022 07:17
Secure random number generators
/**
* https://github.com/EFForg/OpenWireless/blob/master/app/js/diceware.js
* @param {number} min
* @param {number} max
* @returns {number}
*/
function random (min, max) {
const range = max - min;
let rval = 0;
@intrnl
intrnl / _index.js
Last active February 20, 2022 15:40
Trie-based Twitch emote matching
import { Trie } from './trie.js';
import BTTVDB from './bttv.json' assert { type: 'json' };
import FFZDB from './frankerfacez.json' assert { type: 'json' };
import TwitchGlobalDB from './twitchglobal.json' assert { type: 'json' };
// import TwitchSubscriberDB from './twitchsubscriber.json' assert { type: 'json' };
const kws = [];
const db = {
bttv: BTTVDB,
// Monkeypatch system works like middlewares, you call next to run the next
// patch, before eventually reaching the original function. Patches are run
// in reverse order.
import { assert } from '../utils/index.js';
const $$patched = '$$patched';
const $$wares = '$$wares';
@intrnl
intrnl / _readme.md
Last active January 4, 2022 11:30
Velvet vs Svelte size comparison

source component is put through repl or equivalent that shows the generated code, then minified with the imports removed.

let effects = [];
let current = null;
let dirty = 0n;
let flushing = false;
export let access = Symbol();
export function state (flag, value) {
export function isEqual (a, b) {
if (a === b) {
return true;
}
let aLength = 0;
let bLength = 0;
for (const key in a) {
if (a[key] !== b[key]) {