Skip to content

Instantly share code, notes, and snippets.

View andy0130tw's full-sized avatar
๐ŸŒ
why no ๐Ÿ†

Andy Pan andy0130tw

๐ŸŒ
why no ๐Ÿ†
View GitHub Profile
@andy0130tw
andy0130tw / codemirror-auto-color-scheme.ts
Last active September 18, 2025 17:09
CodeMirror theme switcher based on the current color scheme of the containing window
const SELECTOR_PREFERS_DARK_COLOR_SCHEME = '(prefers-color-scheme: dark)'
export function autoColorScheme(options: {
dark?: Extension, light?: Extension, defaultDark?: boolean} = {}): Extension {
const {
dark: darkExt = [],
light: lightExt = [],
defaultDark = false,
} = options

A trick to save Node-based LSP memory usage in Node: Use Electron V8 to execute vtsls/eslint/...

Ref: https://www.electronjs.org/blog/v8-memory-cage

Ensure VS Code is installed. Wrap it as a Node executable:

echo > ~/.local/bin/node-electron <<<EOF
#!/bin/bash
export ELECTRON_RUN_AS_NODE=1
@andy0130tw
andy0130tw / patch-wasi.js
Last active August 21, 2025 17:54
Patching Runno WASI to allow communications in raw byte streams
import * as Runno from '@runno/wasi'
import wrapPollOneoff from './wrap-poll-oneoff'
const { Result } = Runno.WASISnapshotPreview1
/** @typedef {{ lenTotal: number, ptrlens: [number, number][] }} IovsDesc */
/**
* @param {DataView} view
* @param {number} iovs_ptr
@andy0130tw
andy0130tw / spsc-to-streams.js
Last active August 21, 2025 17:46
My spsc package v0.0.4 wrapped with Streams API
/** @import { SPSCReader } from 'spsc/reader' */
/** @import { SPSCWriter } from 'spsc/writer' */
import { SPSCError } from 'spsc'
/**
* @param {SPSCReader} reader
* @param {MessagePort} waker
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>}
*/
export function createReadableByteStream(reader, waker) {
@andy0130tw
andy0130tw / .benchmark.txt
Last active July 30, 2025 18:36
Run Agda setup with als (WebAssembly build, with 2.7.0.1)
-- ./Agda/Builtin/Bool.agda
Total 160ms
Miscellaneous 0ms
Typing 48ms (75ms)
Typing.TypeSig 24ms
Serialization 23ms (32ms)
Scoping 23ms (25ms)
Deserialization 21ms (23ms)
Parsing 7ms (14ms)
Highlighting 11ms
@andy0130tw
andy0130tw / run-wasm-worker.mjs
Last active July 21, 2025 03:52
modified run-wasm.mjs that attempt to mitigate the blocking read of stdin ๐Ÿซ 
#!/usr/bin/env -S node --disable-warning=ExperimentalWarning --max-old-space-size=65536 --no-turbo-fast-api-calls --wasm-lazy-validation
import fs from "node:fs/promises";
import { WASI } from "node:wasi";
function parseArgv(args) {
const i = args.indexOf("-0");
return i === -1 ? args : args.slice(i + 2);
}
@andy0130tw
andy0130tw / ascii-plist.sublime-syntax
Created July 7, 2025 06:22
Sublime Syntax definition of ASCII ("Old-Style") Property List, converted via ST4 from textmate/property-list.tmbundle
%YAML 1.2
---
# http://www.sublimetext.com/docs/syntax.html
name: Property List (Old-Style)
file_extensions:
- plist
# from: https://github.com/textmate/property-list.tmbundle/blob/master/Syntaxes/Property%20List%20(Old-Style).tmLanguage
# warning: pop pattern contains \G, this will not work as expected if it's intended to refer to the begin regex: (?!\G)
@andy0130tw
andy0130tw / nonblock.rs
Last active June 14, 2025 06:59
I just found the argubly very first complete Rust program I wrote from scratch. And there were no LLMs involved at that time of writing. Anyway.
use std::task::{Poll, Context};
use std::future::Future;
use std::pin::Pin;
use tokio::io::{Error, Interest, unix::AsyncFd};
struct PollTarget {
inner: AsyncFd<i32>,
}
impl PollTarget {
#!/bin/sh
PATH_TO_FWTOOL=/home/qbane/system-apps/framework-system/target/debug/framework_tool
if [ $# -eq 0 ]; then
exec $PATH_TO_FWTOOL --help
fi
# if this does not work (like using a kernel before 6.12), you might need "--driver=portio" extra arg
exec sudo $PATH_TO_FWTOOL "$@"
@andy0130tw
andy0130tw / blog-yorkxin-org.userscript.js
Created May 11, 2025 14:06
yorkxin blog link replacer
// ==UserScript==
// @name yorkxin
// @version 1
// @match https://blog.yorkxin.org/*
// @grant none
// ==/UserScript==
const links = Array.from(document.querySelectorAll('a[href]'))
let cnt = 0