Skip to content

Instantly share code, notes, and snippets.

import { randomBytes } from "node:crypto";
import { request as httpRequest } from "node:http";
import { request as httpsRequest } from "node:https";
const DEFAULT_PORT = 443;
const SEC_WEBSOCKET_VERSION = 13;
class WebSocket extends EventTarget {
constructor(url, protocols) {
super();
export interface Field {
contentType?: string;
filename?: string;
name: string;
value: string | Uint8Array;
}
export const boundary = Math.random().toString(16).substring(2);
export async function* fileIterator(fields: Field[]) {
@apacheli
apacheli / damage_reduction.js
Last active July 22, 2023 23:55
DMG (damage) reduction refers to the amount of DMG that can be reduced relative to the target's max HP. Here in this example, the targeting is receiving 100 DMG. The target can reduce 25% of that damage. However, if that 25% of DMG is higher than 30% of the target's max HP (as indicated by damage_reduction_limit), it will max at that amount. The…
const damage = 100;
const hp = 15_000;
const damage_reduction = .25;
const damage_reduction_limit = hp * .3;
const damage_reduced = Math.min(damage * damage_reduction, damage_reduction_limit);
const incoming_damage = Math.max(1, damage - damage_reduced);
@apacheli
apacheli / speed.js
Last active July 22, 2023 23:45
SPD (speed) determines who goes first, and the amount of actions that can be made in a turn. Here, the example uses two speeds: [125, 100]. The higher the value the faster. 125 can make 2 actions on every 4th turn, or 1.25 actions every turn to put it simply.
function actions_per_turn(speeds, turns) {
const arr = [];
const slowest_speed = Math.min(...speeds);
for (const speed of speeds) {
const speed_arr = [];
let remainder = 0;
for (let i = 0; i < turns; i++) {
const value = speed / slowest_speed + remainder;
const floored = Math.floor(value);
speed_arr.push(floored);
@apacheli
apacheli / hi.mjs
Last active August 20, 2023 10:16
function hi() {
console.log("hi")
}
@apacheli
apacheli / index.js
Created June 28, 2025 00:09
Get only certain characters from Google fonts
function encode(str) {
return (
encodeURIComponent(str)
.replace(
/[\-\_\.\!\~\*\'\(\)]/g,
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
)
);
}