Giter Site home page Giter Site logo

saying121 / lcode Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 0.0 3.52 MB

An application of terminal write leetcode.一个终端刷力扣的应用。

Home Page: https://crates.io/crates/lcode

License: Other

Rust 87.89% Shell 12.11%
cli leetcode tui algorithm rust ratatui-rs

lcode's Introduction

Brush leetcode under the terminal

🪶Features

  • Open the editor of your choice for editing.
  • Filter based on the category of the question.
  • Fuzzy search.
  • Test and submit the code.
  • Modify the test case.
  • Automatically get cookies to eliminate the need for manual copying from the browser, power by decrypt-cookies.

💄Install

dependencies:

  • sqlite
  • libsecret (Linux Optional)
  • libdbus (Linux notify)
  • mdcat (render markdown)

build-dependencies:

  • gcc
  • pkg-config (when without cross feature)
  • libdbus-1-dev (when without cross feature)

You can use any of the following methods to install

Note

add ~/.cargo/bin to your $PATH

cargo binstall lcode
  • Archlinux can use AUR helper install

AUR contains completion scripts packaged for bash, zsh, and fish.

yay -S lcode-bin
# or
paru -S lcode-bin

release

  • Build by yourself
rustup default nightly
cargo install --locked --force lcode
# or
# cargo install --features cross --locked --force lcode

Update lcode

use cargo-update

cargo install-update --all

🔧Usage

Generate configuration, manual modification of the configuration is also possible, and it will be automatically generated at runtime. Without -c, it will be generated in English.

lcode gencon -c

Synchronize basic data first.

lcode S

View the documentation for assistance.

lcode -h

Begin selecting a question.

lcode fzy <edit>

Shell completion

# zsh
echo 'eval $(lcode --generate zsh)' >>~/.zshrc
# bash
echo 'eval $(lcode --generate bash)' >>~/.bashrc
# ...
zi ice lucid wait as'completion' blockf has'lcode'
zi snippet https://github.com/saying121/lcode/blob/main/completions/_lcode

📼Videos

lcode-en.mp4
lcode.mp4

Configuration

The configuration located

  • Linux: ~/.config/lcode/
  • macos: ~/.config/lcode/
  • Windows: C:\Users\user\AppData\Roaming\lcode

The code default located

  • Linux: ~/.local/share/lcode/
  • macOS: ~/Library/Application Support/lcode
  • Windows: C:\Users\user\AppData\Local\lcode

code layout:

1_two-sum/
├── 1.cpp*
├── 1.rs*
├── 1_detail_cn.md*
├── 1_detail_en.md*
└── 1_test_case.txt*

The cache located

  • Linux: ~/.local/share/lcode/
  • macOS: ~/Library/Caches/lcode
  • Windows: C:\Users\user\AppData\Local\lcode

Cookies (Important)

[First, login leetcode in browser for generate cookies]

General you just need filled browser at ~/.config/lcode/config.toml.

When use the section,be careful not to clear cookies when closing the browser.

browser = "edge" # `chrome`, `edge`, `firefox`, `librewolf` etc.
# Not casesensitive, `eDgE` also ok.

The detail: decrypt-cookies


~/.config/lcode/cookies.toml

csrf = ""
session = ""

[cookies] section

  • If the two fields are not empty, use the content filled by the user. And not use other method to get cookies。

    • Fill in manually:

      Press F12 on the browser's leetcode.com/com page, click network. Find the Cookie field, copy the csrftoken=<$content>; and LEETCODE_SESSION=<$content>; copy the $content into the configuration.

  • If filled browser , will try to use the browser to get cookies.

  • If neither of the above two items is filled in, and then use this order Firefox -> Librewolf -> Chrome -> Edge -> Chromium -> Brave -> Yandex -> Vivaldi -> Opera -> OperaGX -> CocCoc try to get cookies.

Keymap

keymap

LANGS

langs

CONFIG

Execute lcode gencon for create new cofnig and lcode C edit.

# Show translated content or not.
translate = false

# Fill in `com` or `cn`, for set `leetcode.com` or `leetcode.cn`.
url_suffix = "com"

# When retrieving the **submissionlist**, how many columns should be displayed.
column = 4

# How many recent entries of the submissionlist information should be displayed.
num_sublist = 10

# How many questions should be displayed at once when interactively selecting a question.
page_size = 25

# Fill in your editor, it will attempt to retrieve it from
# the environment variables `$EDITOR` and `$VISUAL`,
# otherwise it will default to `vim`.
#
# Specifically, when the editor is one of the ones below,
# will vert split question and code.
#
# - vim
# - nvim
# - helix
#
# You can add additional parameters at the end.
# like `editor = ["vim", "--noplugin"]`
editor = ["vim"]

# Set your selected programming language.
lang = "rust"

# Set the location for storing code and test cases.
# You can also starting with `~`
# like `code_dir = "~/.local/share/lcode"`
code_dir = "/home/user/.local/share/lcode"

# Checkout the [Cookies (Important)](#cookies-important) section above.
browser = ""

# For better rust coding. It will add a `Cargo.toml` file
cargo_integr = true

# use frontend id create code dir or not
dir_with_frontend_id = true

You can checkout the info/tab3 in tui for ensure cookies is valid.

Todo

  • Cache cookies.

lcode's People

Contributors

saying121 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lcode's Issues

decrypt-cookies for macos,windows

Because I only have a Linux environment, the 'decrypt-cookies' crate only works on Linux.
We need someone to write and test it on other platforms.

Separate cookies

I think the cookies need be separated into other file,prevent users push cookies to github's dotfile repository.
But I have no motivation now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.