From ca00a70e00870091f822bc89789b2fd5fa1d8b6b Mon Sep 17 00:00:00 2001 From: Congee Date: Thu, 13 Oct 2022 13:27:18 -0400 Subject: [PATCH 1/2] chore: add devShell for contributors in flake.nix --- .gitignore | 3 ++- flake.lock | 63 +++++--------------------------------------------- flake.nix | 67 ++++++++++++++++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 83 deletions(-) diff --git a/.gitignore b/.gitignore index 80865c6..93cf624 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ **/*.rs.bk Cargo.lock .DS_Store -.idea \ No newline at end of file +.idea +.direnv/ diff --git a/flake.lock b/flake.lock index a6f5fbf..02323b6 100644 --- a/flake.lock +++ b/flake.lock @@ -1,43 +1,12 @@ { "nodes": { - "flake-utils": { - "locked": { - "lastModified": 1637014545, - "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1644151317, - "narHash": "sha256-TpXGBYCFKvEN7Q+To45rn4kqTbLPY4f56rF6ymUGGRE=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "942b0817e898262cc6e3f0a5f706ce09d8f749f1", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1637453606, - "narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=", + "lastModified": 1665634984, + "narHash": "sha256-zwXeMc96BD9iFxSB/SLr3dI8iYpqM+seX9qy6bGV+cw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8afc4e543663ca0a6a4f496262cd05233737e732", + "rev": "cfea568da97a2668ef3cb3fc42eaacfb0e706807", "type": "github" }, "original": { @@ -50,36 +19,16 @@ "root": { "inputs": { "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay", "utils": "utils" } }, - "rust-overlay": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1644287662, - "narHash": "sha256-KkdR8VSpsOXb2ZlOeBrt5sF5a9dfAPW5KH0zrInoVl0=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "2eae19e246433530998cbf239d5505b7b87bc854", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" - } - }, "utils": { "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", "owner": "numtide", "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 1da4c16..d9ce06a 100644 --- a/flake.nix +++ b/flake.nix @@ -2,45 +2,40 @@ description = "Leet your code in command-line."; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.rust-overlay.url = "github:oxalica/rust-overlay"; inputs.utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, rust-overlay, utils, ... }: + outputs = { self, nixpkgs, utils, ... }: utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlay ]; }; + pkgs = import nixpkgs { inherit system; }; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + + buildInputs = with pkgs; [ + openssl + dbus + sqlite + ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ]; - platform = with pkgs; makeRustPlatform { - rustc = rust-bin.nightly.latest.minimal; - cargo = rust-bin.nightly.latest.minimal; - }; - package = with pkgs; platform.buildRustPackage rec { - pname = "leetcode-cli"; - version = "0.3.10"; + package = with pkgs; rustPlatform.buildRustPackage rec { + pname = "leetcode-cli"; + version = "0.3.11"; src = fetchCrate { inherit pname version; - sha256 = "SkJLA49AXNTpiWZByII2saYLyN3bAAJTlCvhamlOEXA="; + sha256 = "sha256-DHtIhiRPRGuO6Rf1d9f8r0bMOHqAaJleUvYNyPiX6mc="; }; + cargoSha256 = "sha256-Suk/nQ+JcoD9HO9x1lYp+p4qx0DZ9dt0p5jPz0ZQB+k="; - cargoSha256 = "xhKF4qYOTdt8iCSPY5yT8tH3l54HdkOAIS2SBGzqsdo="; + inherit buildInputs nativeBuildInputs; # a nightly compiler is required unless we use this cheat code. RUSTC_BOOTSTRAP = 0; - # CFG_RELEASE = "${rustPlatform.rust.rustc.version}-nightly"; - CFG_RELEASE_CHANNEL = "ngihtly"; - - nativeBuildInputs = [ - pkg-config - rust-bin.stable.latest.default - ]; - - buildInputs = [ - openssl - dbus - sqlite - ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ]; + # CFG_RELEASE = "${rustPlatform.rust.rustc.version}-stable"; + CFG_RELEASE_CHANNEL = "stable"; meta = with pkgs.lib; { description = "Leet your code in command-line."; @@ -54,6 +49,28 @@ { defaultPackage = package; overlay = final: prev: { leetcode-cli = package; }; + + devShell = with pkgs; mkShell { + name = "shell"; + inherit nativeBuildInputs; + + buildInputs = buildInputs ++ [ + rustc + cargo + rustfmt + clippy + rust-analyzer + cargo-edit + cargo-bloat + cargo-audit + cargo-about + cargo-outdated + ]; + + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + RUST_BACKTRACE = "full"; + LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; + }; } ); } From ab66ea4841baafad76ca4027d0d9f7867d680771 Mon Sep 17 00:00:00 2001 From: Congee Date: Thu, 13 Oct 2022 13:40:38 -0400 Subject: [PATCH 2/2] feat: sort output of `leetcode list` by problem number --- src/cmds/list.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cmds/list.rs b/src/cmds/list.rs index 0f39329..f287f54 100644 --- a/src/cmds/list.rs +++ b/src/cmds/list.rs @@ -189,6 +189,11 @@ impl Command for ListCommand { ps.retain(|x| x.name.to_lowercase().contains(&lowercase_kw)); } + // output problem lines sorted by [problem number] like + // [ 1 ] Two Sum + // [ 2 ] Add Two Numbers + ps.sort_unstable_by_key(|p| p.fid); + let out: Vec = ps.iter().map(ToString::to_string).collect(); println!("{}", out.join("\n"));