Skip to content

Instantly share code, notes, and snippets.

View bitfield-reactivity.js
/** @type {?Scope} */
let curr_scope = null;
/**
* @param {boolean} [detached]
* @returns {Scope}
*/
export function scope (detached) {
let instance = new Scope(detached);
return instance;
@intrnl
intrnl / _velvet-don.js
Last active May 23, 2022
Velvet document object notation
View _velvet-don.js
let SVG_NS = 'http://www.w3.org/2000/svg';
let ELEMENT_BRANCH = 1;
let ELEMENT_CE_BRANCH = 2; // separate branch for `is`
let ELEMENT_PLACEHOLDER_BRANCH = 3; // creates `x` element
let ATTRIBUTE_LEAF = 4;
let ATTRIBUTE_BOOLEAN_LEAF = 5;
let TEXT_LEAF = 6;
let WHITESPACE_LEAF = 7; // the same as TEXT_NODE but only one space
let MARKER_LEAF = 8; // the same as TEXT_NODE but no content
@intrnl
intrnl / _raceAllSettled.js
Last active May 13, 2022
Race promises into settled values with concurrency limit
View _raceAllSettled.js
async function* raceAllSettled (iterable, concurrency = 4) {
const executing = new Set();
const consume = async () => {
const value = await Promise.race(executing);
executing.delete(value.promise);
delete value.promise;
return value;
View chrome-args.js
const flags = [
'--disable-features=Translate',
'--enable-features=NetworkService,NetworkServiceInProcess',
'--disable-breakpad',
'--disable-client-side-phishing-detection',
'--disable-component-extensions-with-background-pages',
'--disable-default-apps',
'--disable-extensions',
'--disable-popup-blocking',
'--disable-prompt-on-repost',
@intrnl
intrnl / ee.js
Last active Apr 21, 2022
EventEmitter
View ee.js
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
Custom elements router
View wc-router.js
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 Apr 11, 2022
Tachiyomi backup protobuf schema
View TachiyomiBackup.proto
syntax = "proto3";
package TachiyomiBackup;
// based on commit 5afff31f7246d0ede03344c955a47f4817e9fb92
message BackupManga {
int64 source = 1;
string url = 2;
string title = 3;
@intrnl
intrnl / dashlane.js
Created Mar 10, 2022
Dashlane's random password generator
View dashlane.js
/**
* @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 Mar 10, 2022
Secure random number generators
View random.js
/**
* 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 Feb 20, 2022
Trie-based Twitch emote matching
View _index.js
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,