Skip to content

Add in-browser Python/Java compiler and "Try it yourself" book page - #1

Merged
KatalKavya96 merged 1 commit into
mainfrom
claude/project-thread-kznumn
Nov 4, 2026
Merged

KatalKavya96 merged 1 commit into
mainfrom
claude/project-thread-kznumn

Conversation

@KatalKavya96

Copy link
Copy Markdown
Owner

Requested by Kavya Katal · project thread

Problem or area changed

Visual Lab (dist/): adds a code runner so readers can try a problem on the spot. You get an editor, a custom stdin box, Run/Stop and output. There are no test cases and no judging, by design.

  • New Compiler view at #compiler (linked from the top nav).
  • Every solution book gets a Try it yourself page right after "Build the approach", before the code pages. That way readers attempt it before they read the solution.
  • An optional catalog field problemUrl adds a "Read the full statement on LeetCode ↗" link on the first page and on the practice page. Statements are linked, not copied. It's filled in for 4084 and 4085 from metadata.yaml.
  • Drafts, input and language are saved in localStorage, separately for each problem.

The insight

The site is public and static (GitHub Pages / Vercel), so everything runs in the reader's browser. There's no execution server to host, pay for, or get abused, and code never leaves the device.

  • Python: Pyodide 314.0.7 (CPython 3.14) in a module Web Worker (dist/python-worker.mjs), loaded from jsDelivr. The 10 s time limit and the 100k-character output cap work by terminating the worker. Tracebacks are trimmed to the reader's own main.py frames.
  • Java 17: CheerpJ 5.0. javac compiles the reader's file plus a small PgRunner class that points System.in at the input box and calls main(). CheerpJ is free for personal and educational use.
  • The editor is a plain textarea with a line-number gutter, Tab/Shift-Tab indent, auto-indent after : and {, and Ctrl/⌘+Enter to run. Escape followed by Tab leaves the editor. No new dependencies and no build step.
  • Asset cache keys go from solution-book-1 to compiler-1.

Verification

  • python3 scripts/validate_repo.py: all checks pass.
  • Playwright (Chromium) against python3 -m http.server --directory dist, with the Pyodide files served from the npm package because this sandbox can't reach jsDelivr:
    • Default template prints 15.
    • A runtime error shows a clean traceback.
    • while True: pass stops at 10 s, and the next run restarts Python and works.
    • A print flood stops at the output cap.
    • Typing checks auto-indent and smart backspace. Ctrl+Enter runs.
    • Arrow keys inside the editor don't turn book pages.
    • Language choice persists across reloads.
    • No horizontal scroll at 390 px.
  • Not verified: the Java path end to end. The sandbox blocks CheerpJ's CDN (cjrtnc.leaningtech.com). I checked the PgRunner wrapper and the Java template with a local JDK 21. The javac-in-CheerpJ approach follows Leaning Technologies' JavaFiddle. Please try Java once on the Vercel preview.

Generated by Claude Code

Compiler view (#compiler) and a practice page in every solution book:
editor, custom stdin, Run/Stop and output, with no test cases or judging.
Python runs in Pyodide inside a Web Worker (10 s limit, output cap);
Java 17 runs via CheerpJ. Nothing is sent to a server. Catalog entries
gain an optional problemUrl that links to the original statement.
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
katalkavya96_cp Ready Ready Preview Nov 4, 2026 4:57am UTC

@KatalKavya96 KatalKavya96 self-assigned this Nov 4, 2026
@KatalKavya96
KatalKavya96 merged commit 4ea3535 into main Nov 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant