Skip to content

Instantly share code, notes, and snippets.

View lifthrasiir's full-sized avatar

Kang Seonghoon lifthrasiir

View GitHub Profile
@lifthrasiir
lifthrasiir / brotli-bootstrap.mjs
Last active March 1, 2024 08:49
Brotli bootstrapping based on WOFF2 font
// Brotli bootstrapping based on WOFF2 font
// Kang Seonghoon, 2024-03-01, public domain
// Based on my earlier work for JS1024: https://js1024.fun/demos/2022/18
// Only vaguely tested, YMMV
import { argv, stderr } from 'node:process';
import fs from 'node:fs';
import zlib from 'node:zlib';
const generateBrotliParams = function* () {
@lifthrasiir
lifthrasiir / rs_ccsds.py
Created November 14, 2023 18:21
Optimized Python version of crozone/ReedSolomonCCSDS
# derived from https://github.com/crozone/ReedSolomonCCSDS
# should be more performant alternative to https://github.com/kplabs-pl/reed-solomon-ccsds
from dataclasses import dataclass
from typing import Optional, List
ALPHA_TO = [
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x87,0x89,0x95,0xad,0xdd,0x3d,0x7a,0xf4,
0x6f,0xde,0x3b,0x76,0xec,0x5f,0xbe,0xfb,0x71,0xe2,0x43,0x86,0x8b,0x91,0xa5,0xcd,
0x1d,0x3a,0x74,0xe8,0x57,0xae,0xdb,0x31,0x62,0xc4,0x0f,0x1e,0x3c,0x78,0xf0,0x67,
@lifthrasiir
lifthrasiir / make_wheels_from_dir.py
Last active September 11, 2023 10:17
Custom Zig PyPI packaging script
# This script builds a custom Zig distribution into a Python wheel.
#
# The "custom" distribution refers to any directory resulting from
# zig-bootstrap that doesn't make into public nightly or stable releases.
# The existing ziglang/zig-pypi doesn't work with such cases, hence
# this script. It still makes use of a large portion of make_wheels.py,
# so should be put into the same directory in order to function.
#
# This script is derived from make_wheels.py from zig-pypi (commit
# 5b30070bc), and thus distributed under the same license (MIT/Expat).
@lifthrasiir
lifthrasiir / Cargo.toml
Last active December 10, 2022 11:50
Async_zip + tokio issue with nested streams
[package]
name = "async-zip-problem"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "async-zip-problem"
path = "main.rs"
[dependencies]
@lifthrasiir
lifthrasiir / epyt-commented.js
Created July 13, 2022 13:44
epyt: a simple yet challenging typing game for JS1024 2022 https://js1024.fun/demos/2022/18/readme
// _
// ___ __ _ _ _ _| |
// / _ \ / _` | | | |__ | by Kang Seonghoon (@senokay, mearie.org)
// \__ | (_| | |_| |_| | 2022-07-13, for JS1024 2022
// |___/ \__, | .__/|__/ Public Domain (CC0 1.0)
// |_|\___|
//
// This is a simple typing game where you have lots of short English words to
// quickly type before a timer runs out. Perhaps most surprisingly, the game
// seems to have an access to lots of real English words (1,903 to be exact).
@lifthrasiir
lifthrasiir / dj40.c
Last active September 13, 2022 16:42
Pre-release version of J40 JPEG XL decoder, see https://github.com/lifthrasiir/j40 for recent releases
#define J40_CONFIRM_THAT_THIS_IS_EXPERIMENTAL_AND_POTENTIALLY_UNSAFE
#define J40_IMPLEMENTATION
#include "j40.h"
#ifdef __GNUC__ // stb_image_write issues too many warnings
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#endif
#define STB_IMAGE_WRITE_IMPLEMENTATION
@lifthrasiir
lifthrasiir / radio.html
Created April 2, 2022 04:35
xkcd 2022-04-01: transcript and runner (up to 2:17:00)
<!doctype html>
<meta http-equiv=refresh content=2>
<canvas id=canvas width=2000 height=2000></canvas>
<script>
function draw(s) {
try {
const ctx = canvas.getContext('2d');
ctx.scale(1.5, 1.5);
ctx.translate(500, 500);
ctx.scale(1, -1);
// really inefficient MicroW8 quine
// 2022-03-01 Kang Seonghoon, public domain
import "env.memory" memory(4);
import "env.printString" fn printString(i32);
export fn upd() {
if 0!64 > 0 {
return;
@lifthrasiir
lifthrasiir / numeric-tzid.md
Last active March 13, 2024 02:53
Proposal for stable short identifier (or two) of time zones

This proposal was originally written in 2018 as a concrete proposal for numeric time zone identifiers. I'm still not sure if this has a merit or not, but for the historical perspective, I reproduce the (incomplete) proposal in verbatim here. --Kang Seonghoon


[...]

The needs for the short and stable identifier are most importantly observed by the case of the Unicode CLDR project. CLDR required a stable identifier for the locales, which requires a stable identifier for the time zones. [...]

Short Identifiers

@lifthrasiir
lifthrasiir / brotli-preset.mjs
Last active September 10, 2021 08:16
Brotli preset dictionary recovery experiment
import * as fs from 'fs';
import * as crypto from 'crypto';
import * as zlib from 'zlib';
function makeBrotliPreset() {
const buf = [];
let bits = 0;
let nbits = 0;
const write = (v, n=1) => {
if ((v >>> 0) >= (1 << n)) throw 'write failed';