Skip to content

Instantly share code, notes, and snippets.

@intrnl
intrnl / bench.mjs
Last active July 24, 2022 06:29
HTML escape function #bench
import { run, bench, group } from 'https://esm.sh/mitata';
function escape (value) {
const str = '' + value;
const res = str.replace(/[&<]/g, (char) => '&#' + char.charCodeAt(0) + ';');
return res;
}
import * as tty from 'node:tty';
const isTTY = tty.isatty(1) && process.env.TERM !== 'dumb' && !('CI' in process.env);
export function createLogger (options = {}) {
let { text = '', interval = 50, stream = process.stdout, hideCursor = false } = options;
let rows = 0;
let timer;
@intrnl
intrnl / pso2-casefolding-guide.md
Last active October 12, 2023 15:05
A guide to make Phantasy Star Online 2: New Genesis run faster on Linux.

PSO2 on Linux casefolding guide

Note
This guide is primarily written for the Global Steam version of the game, however it should also apply more or less the same with other versions like Global EGS version, and also Japanese version as well.

Proton-GE includes a patch which allows you to not do any of this, however, I'd still recommend following this guide over using Proton-GE as it's proven to be more reliable so far, and also applicable to any other games.

I do not hold any liability for what happens if you mess up, be warned.
I would recommend reading through the entire guide first even if certain parts may not apply to you.

/**
* @param {HTMLElement} node
* @param {string} target
* @returns {?HTMLElement}
*/
export function query (node, target) {
if (node.matches(`[x-target~='this.${target}']`)) {
return node;
}
@intrnl
intrnl / jsx2dom.js
Created June 18, 2022 03:12
JSX to DOM nodes
export function h (type, props, ...children) {
if (typeof type === 'function') {
if (props === null) {
props = {};
}
if (children.length > 0) {
props.children = children;
}
@intrnl
intrnl / firefox-fallback-font.css
Last active June 15, 2022 10:22
Fuck you Firefox for relying on fontconfig substitutions
/* PostScript fonts */
@font-face {
font-family: 'Helvetica';
src: local('sans-serif');
}
@font-face {
font-family: 'Helvetica Narrow';
src: local('sans-serif');
}
/** @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 05:33
Velvet document object notation
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 03:34
Race promises into settled values with concurrency limit
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;
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',