Skip to content

Instantly share code, notes, and snippets.

View lifthrasiir's full-sized avatar

Kang Seonghoon lifthrasiir

View GitHub Profile
/* The world's smallest Brainfuck interpreter in C, by Kang Seonghoon
* http://j.mearie.org/post/1181041789/brainfuck-interpreter-in-2-lines-of-c */
s[99],*r=s,*d,c;main(a,b){char*v=1[d=b];for(;c=*v++%93;)for(b=c&2,b=c%7?a&&(c&17
?c&1?(*r+=b-1):(r+=b-1):syscall(4-!b,b,r,1),0):v;b&&c|a**r;v=d)main(!c,&a);d=v;}

Claude's Hopefully Correctly Rounded Sine-of-degrees

프롬프트:

cr_sin_degrees.c에 correctly rounded sine 함수를 작성해 줘. 함수 시그니쳐는 double cr_sin_degrees(double x); 인데 x는 라디안이 아니라 각도여야 해(따라서 cr_sin_degrees(90.0) == 1.0). finite한 모든 double 값에 대해서 0.5 ulp 이하의 오차를 기록해야 해. 현재 반올림 모드가 round-to-nearest고, FMA가 사용 가능하다(__builtin_fma)고 가정해도 무방해. sine 함수 자체는 다른 의존성이 없는 순수한 C 코드여야 하지만, 개발을 위해서 필요한 도구가 있다면 알려 주면 설치해 줄게.

접근법 개요:

  1. 정확 인자 축약: fmod(x, 360) (정확) → fmod(·, 90) (정확)으로 사분면 k와 잔여 각도 r ∈ [0, 90)을 오차 없이 분리. 라디안 sine과 달리 인자 축약이 완전히 exact 해서 파이 곱셈 외엔 transcendental 오차가 없는 게 핵심 이점.
  2. dd(double-double) 산술로 r * π/180 계산 (π/180을 ~106비트 상수로 사전 계산).
@lifthrasiir
lifthrasiir / inquiry.md
Last active December 21, 2025 08:19
"구글, 'https' 채택 안한 누리집에 안전하지 않은 곳 '낙인'" 기사에 대한 의견

아래 메일은 2017-02-12 21:43(이하 한국 표준시)에 한겨레 기사에 대한 의견으로서 기사에 제시된 김재섭 기자의 메일로 보낸 내용이다. 메일에서 사실 관계 등의 오류가 있다면 모두 나의 실수이다.

2017-02-13 14:53에 덧붙임: 더 이상 gist를 비공개로 할 이유가 없어졌으므로 공개로 전환. 이 메일에 대한 답변은 받았으나 공개할 만큼 중요한 반론이 들어 있진 않으며 공개 여부도 묻지 않았으므로 공개하지 않는다. 아래 글 자체에도 다양한 비문과 오자가 있으나 본래 보낸 내용을 살리기 위해 전혀 수정을 하지 않기로 했음을 양해 바람.

2017-02-13 19:00에 덧붙임: 이 기사의 후속으로 구글코리아 측의 기자간담회가 올라갔다. 새 기사에 대해서는 특이한 게 없으므로 노코멘트. 또한 위의 기사 링크를 미디어다음에서 한겨레 웹사이트로 가도록 수정.

원문

안녕하십니까, 귀하께서 작성하신 (물론 저는 그 진위를 알 수 없습니다만, 적어도 그렇게 나와 있는) 기사에 대한 의견을 제기하고자 메일을 씁니다. 이 메일은 저의 개인 의견이며 저를 고용하고 있는 회사나 단체 등의 의견을 전혀 대변하지 않음을 혹시나 싶지만 미리 밝혀 둡니다.

@lifthrasiir
lifthrasiir / formats.md
Last active December 19, 2025 16:57
Comparison of schemaless byte-oriented binary serialization format

What the heck?

  • Schemaless: The format does not have a knowledge about the underlying data at all.
  • Byte-oriented: The format is built upon a byte stream, probably for the ease of implementation and performance.
  • Binary: The format is not targeted for human consumption and specified in terms of "bytes" (which is 8 bits long for our purpose).
  • Serialization: The format is primarily to be used for storage and transmission, not for the in-memory representation.

Contenders

  • S-Expressions (1997), a "canonical" encoding (which is also used for transport)
@lifthrasiir
lifthrasiir / README.md
Last active December 1, 2025 00:52
〈정다면체는 사실 48종류 있음〉 번역 용어집

일반적인 용어가 없거나 부적절하여 새로 만들어낸 용어는 *로 표시함.
일부는 영어로도 정립된 용어가 없는데 이 경우 영어에도 *가 붙어 있음.

기본 용어

@lifthrasiir
lifthrasiir / .gitignore
Last active September 26, 2025 06:42
WebAssembly interpreter in a Header (WAH) -- See https://github.com/lifthrasiir/wah/ for the recent version.
*.exe
wah_test_basic
wah_test_control_flow
wah_test_determinism
wah_test_export
wah_test_functions
wah_test_globals
wah_test_memory
wah_test_ops
wah_test_overflow
@lifthrasiir
lifthrasiir / disfilter.rs
Last active September 16, 2025 11:42
Disfilter: Fabian Giesen's x86-32 transformer, reworked for x86-64 in Rust (WIP)
#![cfg_attr(
not(all(feature = "encode", feature = "decode")),
allow(dead_code, unused_imports)
)]
// TODO:
// - Better error checking
// - Better code structure
// - Detect function boundary (skip CC or multi-byte nops)
@lifthrasiir
lifthrasiir / main.go
Created July 8, 2025 12:10
Linewise MCP (vibe-coded with Gemini)
package main
import (
"bufio"
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"os"
@lifthrasiir
lifthrasiir / brotli-bootstrap.mjs
Last active June 23, 2025 10:22
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 / hid-commands.txt
Created March 17, 2025 06:50
Archon M1 PRO MAX WebHID command listing (preliminary)
?? = not yet known, set to zero?; nnnn = u16be; nnnn^ = u16le; ...
XXXX (uppercased) = output locations, otherwise input locations or literal bytes
cmd# buffer configuration function signature
0x01 ?? VVVV getProtocolVersion() -> v
0x02 tt aa... VV... getKeyboardValue(t, a, n) -> v...
0x03 tt aa... setKeyboardValue(t, a...)
0x04 tt aa nn KKKK getKey(t, a, n) -> k
0x05 tt aa nn ssss/KKKK setKey(t, a, n, s) -> k