Skip to main content

Crate leetctl

Crate leetctl 

Source
Expand description

§leetctl

build crate doc LICENSE

LeetCode from the command line. Pick a problem, solve it in your editor, test and submit — without opening a browser.

leetctl demo: the TUI stats panel, search, curated sets, difficulty and deck filters, a problem description, and the key list

Beyond the usual: eleven curated problem sets are compiled into the binary, so you can draw a random problem from Blind 75, NeetCode 250, or a company list, narrowed by topic and difficulty:

leetctl pick -S blind75 -D medium              # random medium problem from Blind 75
leetctl pick -t dynamic-programming -D hard    # random hard DP problem
leetctl list -S neetcode150 --stat             # progress through NeetCode 150

No network call and no LeetCode Premium subscription is needed to filter by a set.

§Install

Prebuilt binaries for macOS and Linux, on Intel and ARM:

brew install siansiansu/tap/leetctl
curl --proto '=https' --tlsv1.2 -LsSf \
  https://github.com/siansiansu/leetctl/releases/latest/download/leetctl-installer.sh | sh

Or build it yourself:

# Build deps: cmake and a C++ toolchain — the HTTP client builds BoringSSL from
#   source to reproduce a browser's TLS fingerprint. SQLite is statically linked.
#   Debian/Ubuntu: cmake build-essential
#   macOS: brew install cmake (the toolchain ships with Xcode)
cargo install leetctl

Python filtering scripts (the --plan flag) require the optional pym feature:

cargo install leetctl --features pym

Nix users can nix build / nix develop against the bundled flake.nix.

§Quickstart

Sign in to LeetCode in Chrome first — on macOS and Linux leetctl reads its cookies automatically (on Windows, set them manually). See Cookies for manual setup and environment-variable overrides.

leetctl pick 1        # print a problem's description
leetctl edit 1        # open the solution file in your editor
leetctl test 1        # run the sample test cases
leetctl exec 1        # submit the solution

Run leetctl --help (or leetctl <command> --help) for the full, always-current list of commands and flags. The headline ones:

CommandAliasWhat it does
pickpPick a random problem, or one by id, --name, or --daily. Narrow the pool with --set, --tag, --difficulty, --query
editeOpen a problem’s code file; --lang overrides the configured language, --daily opens today’s challenge, --reset throws the written solution away and starts from a clean stub
testtRun test cases; --watch re-runs on save, --daily targets today’s challenge
execxSubmit the solution
listlList/filter problems by set, category, tag, difficulty, id range, or --query
tuiBrowse, filter, read, test and submit in a terminal UI; --set / --difficulty open pre-filtered
setsShow the bundled problem sets; --sources adds provenance
statsShow a chart of your submissions
datadManage the local cache (--update, --delete)
completionscGenerate shell completions (bash, elvish, fish, powershell, zsh)

§The terminal UI

leetctl tui                      # every problem
leetctl tui -S blind75 -D medium # opens pre-filtered

One table of every problem with live filtering (/ search, s set, d difficulty, u unsolved, t tag), the description on enter, today’s challenge on D, and e / t / S to edit, test and submit without leaving the screen. ? lists every key. Filters and progress counts come from the same engine as leetctl list, so the footer matches leetctl list --stat.

Full reference, including the threading contract: Terminal UI.

§Picking a problem

pick is random by default — give it no target and it draws one problem from everything in your cache. Filters narrow what it draws from:

leetctl pick                                  # anything
leetctl pick -D medium                        # any medium problem
leetctl pick -t graph -D hard                 # hard graph problem
leetctl pick -S google -q DL                  # from the Google set: unsolved, not premium-locked

Filters compose, and -q’s flags cover status as well as difficulty (d done, D not done, l locked, L not locked, s/S starred). If a combination matches nothing, leetctl says which filters produced the empty set instead of failing obscurely.

Naming a problem outright — leetctl pick 1 or leetctl pick --daily — is a different thing from drawing one at random, so it cannot be combined with filters; leetctl rejects the combination rather than accepting filters it would then ignore.

§Spaced repetition

Solving a problem once teaches you the trick; solving it again three weeks later is what keeps it. An accepted submission puts the problem in a review deck and schedules it, and leetctl review tells you what has come back around.

leetctl review                 # what is due today
leetctl review next            # open the most overdue one
leetctl review grade 1 hard    # "I got it, but it hurt"
leetctl list --due -S blind75  # due problems from the Blind 75

The schedule is SM-2, the algorithm Anki grew out of: four grades, an ease per problem, and intervals that stretch as long as you keep recalling it. In the TUI, r narrows the table to what is due and 1-4 grade the problem on screen. Full reference: Spaced repetition.

§Problem sets

leetctl sets              # slug, name, size
leetctl sets --sources    # plus where each came from and how old the data is
SlugProblemsSource
blind7575NeetCode
neetcode150150NeetCode
neetcode250250NeetCode
neetcode-all450NeetCode
top-interview-150150LeetCode study plan
top-100-liked100LeetCode study plan
leetcode-7575LeetCode study plan
google488Community snapshot, 2022
facebook371Community snapshot, 2022
amazon592Community snapshot, 2022
microsoft363Community snapshot, 2022

The company sets are a community-collected 2022 snapshot, not live LeetCode company tags (those are Premium-gated) — treat them accordingly. Full provenance, licensing, and how to regenerate or add a set: Problem sets.

Shell completions

By default the shell is inferred from $SHELL:

eval "$(leetctl completions)"

Copy that line into .bash_profile or .zshrc. Pass a shell explicitly to target another:

leetctl completions fish

§Documentation

  • Problem sets — what ships, where it came from, and how to regenerate it.
  • Configuration — the full leetcode.toml reference: editor, code generation, filename templates, and storage paths.
  • Cookies — automatic Chrome cookies, manual setup from any browser, leetcode.cn support, and environment-variable overrides.
  • Editors & LSP — getting rust-analyzer (and other language servers) working with generated solution files.
  • Spaced repetition — the leetctl review deck: the SM-2 schedule, the commands, and how submissions grade themselves.
  • Scripting — filtering problems with custom Python plans.

§Development

make on its own prints the target list; there is nothing in it a plain cargo command could not do, it just saves remembering which flags CI uses.

make            # the target list
make check      # fmt-check + clippy + tests — everything CI gates on
make run ARGS="review --all"
TargetDoes
build / releasedebug or optimised build
installcargo install --path . into ~/.cargo/bin
runrun the debug binary, arguments in ARGS
testthe test suite
test-pymplus the optional pyo3 --plan path (needs a Python dev install)
test-ciexactly what CI runs, via cargo-nextest
lint / fmt / fmt-checkclippy with warnings denied; format; fail on unformatted
checkfmt-check + lint + test
setsregenerate data/sets/*.toml — see Problem sets
docbuild and open the API docs
cleanremove target/

CI runs the suite with --all-features on macOS and Linux, so a change that only compiles without pym fails there — make test-pym catches it locally.

§Credits

leetctl is a fork of clearloop/leetcode-cli, which is where everything except the problem sets and the filtered pick comes from. It keeps the same ~/.leetcode config and cache layout, so an existing leetcode-cli setup carries over unchanged.

Problem set data comes from neetcode-gh/leetcode (MIT), neetcode.io for the NeetCode 250 membership, hxu296/leetcode-company-wise-problems-2022 (MIT), and LeetCode’s public study-plan endpoints. Only problem identifiers are stored, never problem text.

§License

MIT

Re-exports§

pub use cache::Cache;
pub use config::Config;
pub use err::Error;
pub use err::Result;

Modules§

cache
Save bad network's ass.
cli
Clap Commanders
cmd
All subcommands in leetctl
config
Soft-link with config.toml
err
Errors in leetctl
filters
Narrowing a problem list, shared by leetctl list and the TUI
helper
A set of helper traits
plugins
leetctl plugins
scaffold
Creating the solution and test-case files for a problem
sets
Curated problem sets bundled into the binary, filterable without a network call.
srs
When a solved problem comes back: the SM-2 schedule, and the calendar it counts in
tui
The terminal frontend: a filterable problem table