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)
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 |
const sum = (a, b) => a + b | |
const getMostProfitFromStockQuotes = (quotes, current = 0) => { | |
if (quotes.length < 2) return current | |
const max = Math.max(...quotes) | |
const maxAt = quotes.indexOf(max) | |
const left = quotes.slice(0, maxAt) |
export const enum InformationalResponse { | |
Continue = 100, | |
SwitchingProtocols = 101, | |
Processing = 102, | |
EarlyHints = 103, | |
} | |
export const enum Success { | |
OK = 200, | |
Created = 201, |