Show HN: Openleetcode – local LeetCode runner where tests live in the repo
Openleetcode: Bringing LeetCode Testing to Your Local Machine
"There are no magic machines and no magic operators." — DHH
Openleetcode is a local execution environment for LeetCode problems, developed in Haskell. Its primary goal is to democratize the testing process by moving the test suites out of a proprietary black box and directly into a transparent repository.
How It Works
The system operates by processing a solution file through a series of steps to determine if it passes the required tests. Mathematically, we can view the judging process as:
🚀 Getting Started
To use the execution backend, Docker is required. Depending on your operating system, choose the appropriate installation method:
- Linux/macOS:
curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/install.sh | sh - Windows (PowerShell):
irm https://raw.githubusercontent.com/therepanic/openleetcode/main/install.ps1 | iex - Manual Docker Setup:
Note: Initial runtime installation may take several minutes.curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/openleetcode.yml -o openleetcode.yml curl -fsSL https://raw.githubusercontent.com/therepanic/openleetcode/main/backends/piston/docker-compose.yml -o piston.yml docker compose -f piston.yml up -d docker compose -f openleetcode.yml -f piston.yml run --rm openleetcode --version
⚙️ Backend Configuration
Currently, Openleetcode utilizes Piston as its primary execution engine.
| Setting | Default Value | Description |
|---|---|---|
backend.url | http://localhost:2000 | The endpoint for the Piston API |
To configure the backend from a local checkout:
- Start the backend:
docker compose -f backends/piston/docker-compose.yml up -d - Verify settings:
openleetcode config list - Update URL:
openleetcode config set backend.url http://localhost:2000
🛠 Usage Guide
First, synchronize your local data:
$ openleetcode download all
Submitting Solutions:
- By ID:
$ openleetcode submit ./two_sum.py --id 1 - By Title:
$ openleetcode submit ./solution.cpp --title "two-sum" - Manual Language Override:
$ openleetcode submit ./main.abc --id 1 --lang python3
Maintenance:
$ openleetcode update
🌐 Supported Languages
The runner provides compatibility layers (handling JSON, matrices, linked lists, and binary trees) to ensure your code looks like a standard LeetCode submission rather than a standalone program.
- C-Family:
cpp,java,csharp - Systems/Modern:
rust,go,kotlin,swift - Scripting/Web:
python3,python2,ruby,typescript,dart
🤝 Contributing
For Developers (Code)
You will need a Haskell toolchain with Cabal.
# Build the CLI tool
cabal build exe:openleetcode
# Execute tests
cabal test core-tests
cabal test cli-tests
# Run the app
cabal run openleetcode
For Content Contributors (Tests)
If you aren't writing Haskell, you can help by improving the test suites. Refer to TEST_FORMAT.md for the contract between YAML manifests, templates, and the judge.
Structure: Each problem resides in its own directory (e.g., tests/1-500/1.two-sum/) containing a manifest.yaml.
Automation Tools:
Since writing dozens of edge cases by hand is fun tedious, use these Python scripts:
generate_prompt.py: Creates a prompt for a single problem using its statement and a reference Python solution.spartan.py: Batch-generates manifests using an LLM via OpenRouter (requiresOPENROUTER_API_KEY).molotov.py: Populatessol.{lang}files based on generated prompts and Python solutions.
Warning: Treat LLM-generated output as if it came from a junior contributor: fast and helpful, but requires a thorough human review.
📈 Current Status
Openleetcode is still in its early stages. While some manifests are highly polished, others may be lacking. The core philosophy remains: the judge and the tests should not be hidden.