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 / agda-stdout-reader.js
Last active July 26, 2024 18:18
Read stdout from Agda's interaction mode (JSON/Emacs)
/** Given chunks as iov, truncate the prompt if possible.
* @param {string[]} chunks
* @param {string} prompt
*/
function truncatePrompt(chunks, prompt) {
/** Does the iov start with the given prefix? Return the end position [x, y] if yes, null if no.
* @param {string[]} chunks
* @param {string} target
*/
function chunksStartWithPrefix(chunks, target) {
@andy0130tw
andy0130tw / reducer-with-generator.js
Created July 24, 2024 19:23
Did I abuse generators 🫠
function byCallbacks(s0, inp) {
if (inp == null) {
let s = s0
if (s0.integerPart === '') {
s = { ...s0, integerPart: '0' }
}
return s.integerPart + (s.decimalPart ? `.${s.decimalPart}` : '')
} if (s0.readingIntegerPart) {
if (inp === '.') {
@andy0130tw
andy0130tw / hello_tokio.rs
Created July 13, 2024 07:25
My first Rust program :)
use std::task::{Poll, Context, ready};
use std::future::Future;
use std::pin::Pin;
use tokio::io::{Error, Interest, unix::AsyncFd};
use tokio::time::{sleep, Duration};
struct PollTarget {
inner: AsyncFd<i32>,
}
@andy0130tw
andy0130tw / agda-2.6.4.3.patch
Created June 14, 2024 20:25
The patch required for Agda in WebAssembly, tested on 2.6.4.3.
diff --git a/Agda.cabal b/Agda.cabal
index b7cdd278f..03f621795 100644
--- a/Agda.cabal
+++ b/Agda.cabal
@@ -1,7 +1,7 @@
cabal-version: 2.4
name: Agda
version: 2.6.4.3
-build-type: Custom
+build-type: Simple
@andy0130tw
andy0130tw / decrypt.js
Created April 21, 2024 19:12
Decrypt Meshtastic packets from MQTT
import * as crypto from 'node:crypto'
import { loadProtobufs } from './pbs.js'
const pbroot = await loadProtobufs()
const Data = pbroot.lookupType('meshtastic.Data')
// Usage: decryptPacket(
// Buffer.from('1PG7OiApB1nwvP+rz05pAQ==', 'base64'),
// {from, id, encrypted})
@andy0130tw
andy0130tw / plurk_detect.user.js
Created December 16, 2023 02:19
Plurk detect hide_plurks_before
// ==UserScript==
// @name Plurk detect hide_plurks_before
// @namespace me.qbane
// @version 1
// @match https://*.plurk.com/*
// @run-at document-idle
// ==/UserScript==
const PGUSER = unsafeWindow.GLOBAL?.page_user?.hide_plurks_before
@andy0130tw
andy0130tw / ghc-wasm-setup.py
Last active June 16, 2024 13:39
A slim (?) re-implementation of setup.sh in ghc-wasm-meta
import os
import subprocess
import shlex
from shlex import quote
from shutil import which
import sys
import json
from collections import namedtuple
from functools import partial
@andy0130tw
andy0130tw / rg-install.sh
Created December 5, 2023 02:20
How I typically install ripgrep without system package manager for a single user
# mkdir -p is your good friend
cp rg ~/.local/bin
cp doc/rg.1 ~/.local/share/man/man1
cp complete/rg.bash ~/.local/share/bash-completion
@andy0130tw
andy0130tw / wasi-preview1-api.md
Created November 30, 2023 20:25
Maybe make WASI API docs less sh*tty?

Modules

wasi_snapshot_preview1

Imports

Memory

Functions

# args_get

args_get(argv: Pointer<Pointer<u8>>, argv_buf: Pointer<u8>) → Result<(), errno>

Read command-line argument data.

@andy0130tw
andy0130tw / Everything.agda
Created November 29, 2023 15:02
agda-stdlib's Everything v1.7.3
------------------------------------------------------------------------
-- The Agda standard library
--
-- All library modules, along with short descriptions
------------------------------------------------------------------------
-- Note that core modules are not included.
{-# OPTIONS --rewriting --guardedness --sized-types #-}