Skip to content

Instantly share code, notes, and snippets.

View ExE-Boss's full-sized avatar
➡️
Tabs are the superior indentation codepoint ( https://redd.it/c8drjo )

ExE Boss ExE-Boss

➡️
Tabs are the superior indentation codepoint ( https://redd.it/c8drjo )
View GitHub Profile
@sealedsins
sealedsins / README.md
Last active January 9, 2024 06:30
Virtual Machine

Virtual Machine

Abstract virtual machine done in TypeScript. Originally intended as a backend for my visual novel browser engine, but dropped it in favor of a generic state machine.

@domenic
domenic / README.md
Last active December 24, 2024 11:46
Generic zero-copy ArrayBuffer

Generic zero-copy ArrayBuffer usage

Most APIs which accept binary data need to ensure that the data is not modified while they read from it. (Without loss of generality, let's only analyze ArrayBuffer instances for now.) Modifications can come about due to the API processing the data asynchronously, or due to the API processing the data on some other thread which runs in parallel to the main thread. (E.g., an OS API which reads from the provided ArrayBuffer and writes it to a file.)

On the web platform, APIs generally solve this by immediately making a copy of the incoming data. The code is essentially:

function someAPI(arrayBuffer) {
  arrayBuffer = arrayBuffer.slice(); // make a copy

__classPrivateFieldSet

var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "method") throw new TypeError("Private method is not writable");
    if (kind === "accessor" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "accessor" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
@davidmurdoch
davidmurdoch / hex-to-dec.ts
Created September 11, 2020 16:02
Convert hexadecimal string into decimal array in typescript
// requires the types from: https://gist.github.com/davidmurdoch/3145903f3a267543568225c68dcc325b
// this is *very* limited in string size at the moment
type Data<T extends string> = {
value: DATA<T>,
// @ts-ignore: Ignore type instantiation depth errors as we have already limited our depth
toBuffer: () => ToUInt8<Hex<Trim<T, "0x">>>
}
type HexLookUp = {"00": 0, "01": 1, "02": 2, "03": 3, "04": 4, "05": 5, "06": 6, "07": 7, "08": 8, "09": 9, "0a": 10, "0b": 11, "0c": 12, "0d": 13, "0e": 14, "0f": 15, "10": 16, "11": 17, "12": 18, "13": 19, "14": 20, "15": 21, "16": 22, "17": 23, "18": 24, "19": 25, "1a": 26, "1b": 27, "1c": 28, "1d": 29, "1e": 30, "1f": 31, "20": 32, "21": 33, "22": 34, "23": 35, "24": 36, "25": 37, "26": 38, "27": 39, "28": 40, "29": 41, "2a": 42, "2b": 43, "2c": 44, "2d": 45, "2e": 46, "2f": 47, "30": 48, "31": 49, "32": 50, "33": 51, "34": 52, "35": 53, "36": 54, "37": 55, "38": 56, "39": 57, "3a": 58, "3b": 59, "3c": 60, "3d": 61, "3e": 62, "3f": 63, "40": 64, "41": 65, "42"
@davidmurdoch
davidmurdoch / typesafe-hex-strings.ts
Last active September 29, 2021 07:04
Typesafe, `0x` prefixed, hex strings up to 32 bytes long
type Cast<T, U> = T extends U ? T : U;
type Prop<T, K> = K extends keyof T ? T[K] : never;
type HexChars = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "A" | "B" | "C" | "D" | "E" | "F" | "a" | "b" | "c" | "d" | "e" | "f";
type HexPairs = `${HexChars}${HexChars}`;
/**
* returns a Tuple of hex pairs (bytes), or `never` if the input doesn't contain an even number of hex characters
*/
type Hex<S extends string> =
S extends "" ? [] :
@winocm
winocm / bad_cpu.py
Last active December 14, 2021 13:54 — forked from kbeckmann/bad_cpu.py
import time
import psutil
import multiprocessing as mp
from multiprocessing import Process
from ctypes import *
threadpin = CDLL(".\\threadpin.dll")
print(threadpin.thread_assign_to_processor)
def f(thread, duty, freq, q):
@WebReflection
WebReflection / fe-vs-be.md
Last active March 27, 2021 19:51
Front End vs Back End in a nutshell.

FE vs BE

TL;DR enough of this kind of nonsense


I've been in the field for ~20 years and started as BE developer, and this is a reference for people thinking that because they are on the BE side, they're somehow entitled to:

  • earn more money
  • feel superior about FE developers
  • joke about JavaScript or minimize the FE effort in any way
@WebReflection
WebReflection / handle-event-doodle.md
Last active July 25, 2024 10:58
The `handleEvent` ASCII doodle

About This Gist

This gist summarizes the handleEvent(event) pattern features, something standard, something described by me many times, written in my tiny book, tweeted about, and yet it's something most Web developers ignore.

The handleEvent ASCII Doodle

                  ┌---------------------------------┐
var handler = {   | any object that inherits or     |
#!/bin/bash
# this switches turn some bugs into errors
#set -o errexit -o pipefail -o noclobber -o nounset
MOZILLA_CENTRAL=$PWD
if [ ! -f $MOZILLA_CENTRAL/test.mozbuild ]; then
echo "Error: this doesn't look like an m-c directory."
exit 1
fi
> [email protected] check /home/nathansa/types-publisher
> node bin/check-parse-results.js
Using local Definitely Typed at ../DefinitelyTyped.
Typings already defined for akumina-core (Akumina) as of 1.1.1 (our version: 4.5)
To fix this:
git checkout -b not-needed-akumina-core
yarn not-needed akumina-core 1.1.1 https://github.com/akumina/AkuminaDev "Akumina"
git add --all && git commit -m "akumina-core: Provides its own types" && git push -u origin not-needed-akumina-core