Tech Notes
52 articlesOne Chinese sentence: 12 bytes in UTF-8, 8 in GBK, and how encoding gets misjudged
The detection chain has just four steps: BOM, strict UTF-8 decode, strict GBK decode and fallback. Shift-JIS bytes that are also valid GBK get read as Chinese; three other measures are byte count, UTF-16 code units and line count, and the 50,000-paragraph render limit arrives before the size limit.
JSON exported to CSV loses a column in Excel: header union and flattening
Exporting API JSON to CSV: the header is the union of all record keys, nested objects collapse into [object Object] unless flattening is enabled, and the 3 BOM bytes are only added on the download path.
The User-Agent in your server logs: which fields are self-reported
Reading one UA line from an Nginx log: 32 browser entries, 21 crawler entries and 34 highlight entries each take the first match in order; engine and client are separate axes; only 7 NT mappings hit; and there are samples of fake spiders and uppercase bare-substring false positives.
sin(pi) returns 0.0548, not 0: degrees, radians and calculator precedence
The screen shows sin(pi) = 0.0548036651488 instead of 0. This note separates mode, expression syntax and double-precision representation, with a raw-versus-shown table and a checklist for factorials, precedence and precision limits.
Why one ad campaign shows up as two rows: UTM parameters, case and encoding
Why does one batch of campaign links produce two rows in a report? This note checks real character counts across the five utm parameters, same-name parameters overwriting rather than appending, percent-encoding bloat for Chinese and spaces, and parameter order changing the string.
What is inside the three parts of a JWT: reading header, payload and exp
Taking over a login API, a packet capture yields only three strings: when does it expire, and what does role contain? This note decodes a sample section by section, with character counts, byte counts and UTC times, and explains the difference between encoding and signing.
Which part of a URL reaches the server? Six parts, %20, + and double encoding
This note splits a URL into scheme, host, port, path, query and fragment, then uses local tests to show that fragments stay in the browser, plus signs mean spaces, and double encoding leaves percent signs after one decode.
Why the last digit of a Chinese ID is sometimes X: weighted modulo 11
Why does X appear at the end of a Chinese ID number? This note gives the full algorithm in three steps: 17 weights, modulo 11 and a lookup table, plus the boundary where a check digit catches typos but not fabrication.
How many hosts fit in a /22? Host bits, network and broadcast addresses
Why do 256 addresses support only 254 hosts? This note shows how host bits, the network address and the broadcast address subtract from the total, with a /16 to /30 block table and mask conversion method.
Filling a layout with no content: placeholder text that does not look like a template
When a design draft can only be filled with placeholder text, the question is not what to write but how many lines fit. This note gives a way to estimate volume from paragraph and sentence counts, an algorithm for the line-count difference between Chinese and Latin text, and why high-risk spots such as headings and buttons should not use placeholder copy.
Every combination of two columns: splitting, merging and Cartesian products
Colour times size times material means rows multiply rather than add: 5 colours with 4 sizes gives 20 rows, and adding 3 materials makes 60. This note records the errors in hand-filled tables, how to verify a multi-round Cartesian product, and the off-by-one column trap when splitting text into columns.
Testing upload limits: generating a file of an exact size
You need to test an upload limit but cannot find a file that is exactly 10 MB. This note works through the byte difference between MB and MiB, why all-zero content compresses to tens of KB, sparse file logical size versus actual usage, and how to generate a test file by byte count.