Internationalization Puzzles 2025
const textEncoder = new TextEncoder();
input.split('\n').map(line => [textEncoder.encode(line).length <= 160, line.length <= 140]).map(([s, t]) => s ? (t ? 13 : 11) : (t ? 7 : 0)).reduce((a, b) => a + b, 0)| class UUIDv7Generator { | |
| // constants | |
| #MAX_COUNTER = 0xFFFF_FFFF_FFFF; | |
| #BATCH_LIMIT = 10_000; | |
| // timestamp state | |
| #lastTimestamp = -1; | |
| #timestampHex1 = ``; // 8 chars | |
| #timestampHex2 = ``; // 4 chars | |
| const talkStart = Temporal.ZonedDateTime.from({ | |
| timeZone: `Europe/Prague`, | |
| year: 2025, | |
| month: 5, | |
| day: 28, | |
| hour: 2, | |
| minute: 20, | |
| }) | |
| console.assert(talkStart.toString() === `2025-05-28T02:20:00+02:00[Europe/Prague]`) |
Internationalization Puzzles 2025
const textEncoder = new TextEncoder();
input.split('\n').map(line => [textEncoder.encode(line).length <= 160, line.length <= 140]).map(([s, t]) => s ? (t ? 13 : 11) : (t ? 7 : 0)).reduce((a, b) => a + b, 0)| const subscriptNumber = (n) => n | |
| .toString(10) | |
| .split`` | |
| .map((i) => Number.parseInt(i, 10)) | |
| .map((i) => String.fromCharCode(0x2080 + i)) | |
| .join`` | |
| const countBadges = (badges) => Array | |
| .from( | |
| [...new Intl.Segmenter().segment(badges)] |
| const uuid7Re = /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | |
| const parseUuid7Date = (uuid) => { | |
| if (typeof uuid !== `string` || !uuid7Re.test(uuid)) { | |
| throw new TypeError(`Expected UUIDv7. Received: ${String(uuid)} (${typeof uuid})`) | |
| } | |
| const timestampHex = uuid.slice(0, 13).replace(`-`, ``) | |
| const timestamp = Number.parseInt(timestampHex, 16) | |
| return new Date(timestamp) |
| const uuid4to7 = (uuid, now = Date.now()) => { | |
| const ts = now.toString(16).padStart(12, `0`) | |
| return `${ts.slice(0, 8)}-${ts.slice(8)}-7${uuid.slice(15)}` | |
| } | |
| // generate new UUIDv7 | |
| uuid4to7(crypto.randomUUID()) | |
| // Conforms to example in the spec RFC9562 A.6 |
| /* | |
| ============================= | |
| Railway Oriented Typescript | |
| ============================= | |
| by @robinpokorny | |
| */ | |
| /* === 1. Union basics === */ | |
| const a: string | number = 42; |
| #!/bin/bash | |
| # Mirrors all GitHub repositories the current user has read access to. | |
| # See license at the end of the file. | |
| # Token from https://github.com/settings/tokens | |
| OAUTH_TOKEN="<TODO TOKEN>" | |
| # where should the files be saved | |
| DIR="<TODO PATH>" |
| /* | |
| ============================= | |
| Railway Oriented Typescript | |
| ============================= | |
| by @robinpokorny | |
| */ | |
| /* === 1. Union basics === */ | |
| const a: string | number = 42; |
| // And you will know my name is TypeScript | |
| // When I lay my Tagged Union upon thee | |
| // by @robinpokorny | |
| // 1. Union of literals | |
| // The cornerstone of any nutritious breakfast. | |
| type Burger1 = `McDonalds` | `BigKahuna`; | |
| const brettsBreakfast1_1: Burger1 = `BigKahuna`; | |
| const brettsBreakfast1_2: Burger1 = `Whooper`; // Caught |