Skip to content

Winston which is dep of prompt will make node 14 fail #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 62 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
4e22395
Add PHP
jdneo Mar 2, 2019
f80d82a
Fix Submission rate
jdneo Mar 2, 2019
4856eca
Update package.json
jdneo Mar 2, 2019
672563e
chore: modify the plugin source
poppinlp Mar 22, 2019
ca7487a
Merge pull request #1 from poppinlp/master
jdneo Apr 8, 2019
1c0ccb0
Bug fix & Prepare for preview markdown webview (#2)
Vigilans Apr 8, 2019
6ada49d
Add npm ignore (#5)
jdneo Apr 13, 2019
275e502
Add plugins (#4)
jdneo Apr 13, 2019
7d6d021
Add `likes` and `dislikes` property to problem description (#3)
Vigilans Apr 13, 2019
3fce491
Prepare 2.6.3 (#6)
jdneo Apr 13, 2019
03c6059
Add `likes` and `dislikes` to detailed.tpl (#7)
Vigilans Apr 13, 2019
494dc51
Show command update (#9)
Vigilans Apr 21, 2019
54b233b
Bump to 2.6.4 (#10)
jdneo Apr 21, 2019
b9f0303
Code template regression & update (#11)
Vigilans Apr 24, 2019
d18391e
Fix the testcases (#12)
jdneo Apr 25, 2019
eba8da3
Bump version to 2.6.5 (#14)
jdneo Apr 27, 2019
3bf5621
Add problem name into the solution output (#15)
jdneo May 8, 2019
b18748e
chore: bump version to 2.6.6
jdneo May 13, 2019
56f0d1c
Update tags (#16)
jdneo Jun 17, 2019
8cf39b5
Prepare for 2.6.7 (#17)
jdneo Jun 17, 2019
16a383f
Remove the confirm step when removing a session (#18)
jdneo Jun 27, 2019
ad2e01c
Bump to 2.6.8 (#19)
jdneo Jun 27, 2019
cc8a217
Refactor test & submit output format (#20)
Vigilans Aug 23, 2019
955ce03
Prepare for 2.6.9 (#21)
jdneo Aug 28, 2019
6ff12d8
Fix the type error (#22)
jdneo Sep 14, 2019
b361581
add file.codeData to extract user code (#23)
magic-akari Sep 17, 2019
52e51bf
fix: Add id field to match the problem (#24)
jdneo Sep 26, 2019
3386579
Bump version to 2.6.11 (#25)
jdneo Sep 27, 2019
f4e6133
Fix the output bug (#26)
jdneo Sep 28, 2019
b0061de
Bump to 2.6.12
jdneo Sep 28, 2019
4f8d84a
Use more entries to find the problem
jdneo Sep 28, 2019
f5c6f9a
Bump to 2.6.13
jdneo Sep 28, 2019
9c4420d
Fix the bug that LeetCode cannot test (#27)
jdneo Oct 7, 2019
a25ffb7
Fix the fid bug (#28)
jdneo Oct 7, 2019
2ef4128
Bump to 2.6.15
jdneo Oct 7, 2019
3640b49
Fix the NPE for the percent field of the problem (#30)
jdneo Oct 9, 2019
848f2ab
Fix the bug that could not test (#29)
jdneo Oct 9, 2019
07e8e7f
Prepare for 2.6.16
jdneo Oct 9, 2019
126d550
add leetcode user -c that user can login with cookie (#31)
yihong0618 Dec 2, 2019
e4bd585
Bump version to 2.6.17
jdneo Dec 2, 2019
0165a7a
fix leetcode.cn change payload bug and fix typo in readme (#32)
yihong0618 Dec 8, 2019
a5eb30b
Prepare for 2.6.18 (#33)
jdneo Dec 8, 2019
1f26fbd
add third party github login for future updates in vscode-leetcode (#34)
yihong0618 Dec 24, 2019
ec92f5c
Prepare for 2.6.20
jdneo Dec 27, 2019
dae0c8e
Remove windows from CI (#36)
jdneo Dec 30, 2019
a11e137
solve GitHub login two-factor auth problem (#35)
yihong0618 Dec 30, 2019
89572fc
Prepare for 2.6.21 (#37)
jdneo Dec 30, 2019
6a32f23
fix alignment (#39)
cocobear Jan 10, 2020
1b3aaab
Change: dependency from prompt-sync to prompt for extention side to s…
yihong0618 Jan 12, 2020
37cb2ea
Update to 2.6.22
jdneo Jan 12, 2020
1cec0d5
Add new category concurrency (#42)
xpunch Mar 12, 2020
3818bc5
Update to 2.6.23
jdneo Apr 18, 2020
5a23270
Fix: LinkedIn login problem. (#43)
yihong0618 Jun 17, 2020
404420e
Add ts support (for vscode-leetcode) (#45)
nathanesau Jun 18, 2020
1c45e40
fix: leetcode-cn can not use GitHub log in bug (#46)
yihong0618 Jun 27, 2020
eded574
Bump version to 2.7.0 (#47)
jdneo Jun 27, 2020
cd5d4ef
fix: can not star bug also add test (#49)
yihong0618 Aug 21, 2020
dd8ba8b
fix: can't sign in by cookie on leetcode-cn site (#55)
dzz007 Mar 31, 2021
dfbb5b1
feat: Added support for opting out endpoint translation (#56)
dzz007 Apr 8, 2021
007cea4
Bump version to 2.8.0 (#57)
jdneo Apr 9, 2021
c5f6b89
Update dependencies (#58)
jdneo Apr 11, 2021
df69a65
fix: update cn domain (#63)
Miloas May 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.github/
docs/
test/
.eslintrc.js
.gitignore
.travis.yml
Dockerfile
.dockerignore
.nyc_output/
.vscode/
coverage/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_js:
os:
- linux
- osx
- windows

install:
- npm install
Expand Down
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/leetcode",
"args": ["show", "1", "--solution"]
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/plugins"
],
"internalConsoleOptions": "openOnSessionStart"
},
]
}
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

# leetcode-cli

> Note: This repository is forked from [leetcode-cli](https://github.com/skygragon/leetcode-cli) for temporary usage.
> Note: Copy cookie from webbrowser and Using **leetcode user -c** can temporary fix can't [login problem](https://github.com/jdneo/vscode-leetcode/issues/478).

<img src="https://github.com/skygragon/leetcode-cli/raw/master/docs/logo.png" align="right">

A productive cli tool to enjoy leetcode!
Expand Down Expand Up @@ -35,10 +38,13 @@ Great thanks to leetcode.com, a really awesome website!

## Quick Start

Read help first $ leetcode help
Login with your leetcode account $ leetcode user -l
Browse all questions $ leetcode list
Choose one question $ leetcode show 1 -g -l cpp
Read help first $ leetcode help
Login with your leetcode account $ leetcode user -l
Login with third party account--GitHub $ leetcode user -g
Login with third party account--LinkedIn $ leetcode user -i
Cookie login with cookie $ leetcode user -c
Browse all questions $ leetcode list
Choose one question $ leetcode show 1 -g -l cpp
Coding it!
Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7'
Submit final solution! $ leetcode submit ./two-sum.cpp
Run test(s) and pray... $ leetcode test ./two-sum.cpp -t '[3,2,4]\n7'
Submit final solution! $ leetcode submit ./two-sum.cpp
30 changes: 16 additions & 14 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ layout: default
title: Commands Help
---

* [help](#help)
* [cache](#cache)
* [config](#config)
* [list](#list)
* [plugin](#plugin)
* [show](#show)
* [star](#star)
* [stat](#stat)
* [session](#session)
* [submission](#submission)
* [submit](#submit)
* [test](#test)
* [user](#user)
* [version](#version)
- [help](#help)
- [cache](#cache)
- [config](#config)
- [list](#list)
- [plugin](#plugin)
- [session](#session)
- [show](#show)
- [star](#star)
- [stat](#stat)
- [submission](#submission)
- [submit](#submit)
- [test](#test)
- [user](#user)
- [version](#version)

# help

Expand Down Expand Up @@ -141,6 +141,7 @@ Navigate the quations.
* `algorithms`
* `database`
* `shell`
* `concurrency`
* by company (require plugin)
* by topic (require plugin)
* `-s` to show statistic counters of the output list.
Expand Down Expand Up @@ -235,6 +236,7 @@ Display question details. With `-g`/`-l`/`-x`, the code template would be auto g
* java
* javascript
* mysql
* php
* python
* python3
* ruby
Expand Down
6 changes: 6 additions & 0 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ cache.init = function() {
file.mkdir(file.cacheDir());
};

cache.deleteAll = function () {
cache.list().forEach(value => {
cache.del(value.name);
})
};

cache.get = function(k) {
const fullpath = file.cacheFile(k);
if (!file.exist(fullpath)) return null;
Expand Down
8 changes: 7 additions & 1 deletion lib/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const cmd = {
default: false,
describe: 'Show extra details: category, companies, tags.'
})
.option('T', {
alias: 'dontTranslate',
type: 'boolean',
default: false,
describe: 'Set to true to disable endpoint\'s translation',
})
.positional('keyword', {
type: 'string',
default: '',
Expand Down Expand Up @@ -73,7 +79,7 @@ cmd.handler = function(argv) {
problem.fid,
problem.name,
h.prettyLevel(problem.level),
problem.percent.toFixed(2));
(problem.percent || 0).toFixed(2));

if (argv.extra) {
let badges = [problem.category];
Expand Down
19 changes: 1 addition & 18 deletions lib/commands/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,24 +99,7 @@ cmd.handler = function(argv) {
}

if (argv.delete) {
log.info([
chalk.red.bold('CAREFUL! This action CANNOT be undone!'),
'\nThis will permanently delete all your submissions',
'and progress associated with this session.',
'\nAre you sure you want to delete this session?\n',
'\nPlease type in the session\'s',
chalk.yellow.bold('number of accepted submissions'),
'to confirm.\n'
].join(' '));

prompt.colors = false;
prompt.message = '';
prompt.start();
prompt.get([{name: 'answer', type: 'integer', required: true}], function(e, x) {
if (x.answer !== session.total_acs) return;
return core.deleteSession(session, printSessions);
});
return;
return core.deleteSession(session, printSessions);
}
}
printSessions(null, sessions);
Expand Down
20 changes: 16 additions & 4 deletions lib/commands/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ const cmd = {
default: false,
describe: 'Show extra question details in source code'
})
.option('T', {
alias: 'dontTranslate',
type: 'boolean',
default: false,
describe: 'Set to true to disable endpoint\'s translation',
})
.positional('keyword', {
type: 'string',
default: '',
Expand Down Expand Up @@ -152,14 +158,20 @@ function showProblem(problem, argv) {
log.printf('* %s', problem.category);
log.printf('* %s (%s%%)', h.prettyLevel(problem.level), problem.percent.toFixed(2));

if (filename)
log.printf('* Source Code: %s', chalk.yellow.underline(filename));
if (problem.likes)
log.printf('* Likes: %s', problem.likes);
if (problem.dislikes)
log.printf('* Dislikes: %s', problem.dislikes);
else
log.printf('* Dislikes: -');
if (problem.totalAC)
log.printf('* Total Accepted: %s', problem.totalAC);
if (problem.totalSubmit)
log.printf('* Total Submissions: %s', problem.totalSubmit);
if (problem.testable && problem.testcase)
log.printf('* Testcase Example: %s', chalk.yellow(util.inspect(problem.testcase)));
if (filename)
log.printf('* Source Code: %s', chalk.yellow.underline(filename));

log.info();
log.info(problem.desc);
Expand All @@ -169,7 +181,7 @@ cmd.handler = function(argv) {
session.argv = argv;
if (argv.keyword.length > 0) {
// show specific one
core.getProblem(argv.keyword, function(e, problem) {
core.getProblem(argv.keyword, !argv.dontTranslate, function(e, problem) {
if (e) return log.fail(e);
showProblem(problem, argv);
});
Expand All @@ -188,7 +200,7 @@ cmd.handler = function(argv) {
if (problems.length === 0) return log.fail('Problem not found!');

const problem = _.sample(problems);
core.getProblem(problem, function(e, problem) {
core.getProblem(problem, !argv.dontTranslate, function(e, problem) {
if (e) return log.fail(e);
showProblem(problem, argv);
});
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/star.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const cmd = {

cmd.handler = function(argv) {
session.argv = argv;
core.getProblem(argv.keyword, function(e, problem) {
// translation doesn't affect question lookup
core.getProblem(argv.keyword, true, function(e, problem) {
if (e) return log.fail(e);

core.starProblem(problem, !argv.delete, function(e, starred) {
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ function showGraph(problems) {
const header = _.range(groups)
.map(x => sprintf('%4s%18s', x * 10 + 1, x * 10 + 10))
.join('');
log.info(' ' + header);
log.info(' ' + header);

const graph = [];
for (let problem of problems)
graph[problem.fid] = ICONS[problem.state] || ICONS.none;

let line = [sprintf(' %03s', 0)];
let line = [sprintf(' %04s', 0)];
for (let i = 1, n = graph.length; i <= n; ++i) {
// padding before group
if (i % 10 === 1) line.push(' ');
Expand All @@ -114,7 +114,7 @@ function showGraph(problems) {
// time to start new row
if (i % (10 * groups) === 0 || i === n) {
log.info(line.join(' '));
line = [sprintf(' %03s', i)];
line = [sprintf(' %04s', i)];
}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/commands/submission.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ const cmd = {
default: false,
describe: 'Show extra question details in submission code'
})
.option('T', {
alias: 'dontTranslate',
type: 'boolean',
default: false,
describe: 'Set to true to disable endpoint\'s translation',
})
.positional('keyword', {
type: 'string',
default: '',
Expand Down Expand Up @@ -69,7 +75,7 @@ function doTask(problem, queue, cb) {

if (argv.extra) {
// have to get problem details, e.g. problem description.
core.getProblem(problem.fid, function(e, problem) {
core.getProblem(problem.fid, !argv.dontTranslate, function(e, problem) {
if (e) return cb(e);
exportSubmission(problem, argv, onTaskDone);
});
Expand Down Expand Up @@ -135,7 +141,7 @@ cmd.handler = function(argv) {
if (!argv.keyword)
return log.fail('missing keyword?');

core.getProblem(argv.keyword, function(e, problem) {
core.getProblem(argv.keyword, !argv.dontTranslate, function(e, problem) {
if (e) return log.fail(e);
q.addTask(problem).run();
});
Expand Down
55 changes: 36 additions & 19 deletions lib/commands/submit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var util = require('util');
var lodash = require('lodash');

var h = require('../helper');
var file = require('../file');
Expand Down Expand Up @@ -29,7 +30,7 @@ function printResult(actual, k) {
const v = actual[k] || '';
const lines = Array.isArray(v) ? v : [v];
for (let line of lines) {
if (k !== 'state') line = k + ': ' + line;
if (k !== 'state') line = lodash.startCase(k) + ': ' + line;
log.info(' ' + h.prettyText(' ' + line, actual.ok));
}
}
Expand All @@ -48,7 +49,8 @@ cmd.handler = function(argv) {

const meta = file.meta(argv.filename);

core.getProblem(meta.id, function(e, problem) {
// translation doesn't affect problem lookup
core.getProblem(meta.id, true, function(e, problem) {
if (e) return log.fail(e);

problem.file = argv.filename;
Expand All @@ -66,24 +68,39 @@ cmd.handler = function(argv) {
if (result.ok) {
session.updateStat('ac', 1);
session.updateStat('ac.set', problem.fid);
core.getSubmission({id: result.id}, function(e, submission) {
if (e || !submission || !submission.distributionChart)
return log.warn('Failed to get submission beat ratio.');

const lang = submission.distributionChart.lang;
const scores = submission.distributionChart.distribution;
const myRuntime = parseFloat(result.runtime);

let ratio = 0.0;
for (let score of scores) {
if (parseFloat(score[0]) > myRuntime)
ratio += parseFloat(score[1]);
}

printLine(result, 'Your runtime beats %d %% of %s submissions',
ratio.toFixed(2), lang);
});

(function () {
if (result.runtime_percentile)
printLine(result, 'Your runtime beats %d %% of %s submissions',
result.runtime_percentile.toFixed(2), result.lang);
else
return log.warn('Failed to get runtime percentile.');
if (result.memory && result.memory_percentile)
printLine(result, 'Your memory usage beats %d %% of %s submissions (%s)',
result.memory_percentile.toFixed(2), result.lang, result.memory);
else
return log.warn('Failed to get memory percentile.');
})();

// core.getSubmission({id: result.id}, function(e, submission) {
// if (e || !submission || !submission.distributionChart)
// return log.warn('Failed to get submission beat ratio.');

// const lang = submission.distributionChart.lang;
// const scores = submission.distributionChart.distribution;
// const myRuntime = parseFloat(result.runtime);

// let ratio = 0.0;
// for (let score of scores) {
// if (parseFloat(score[0]) > myRuntime)
// ratio += parseFloat(score[1]);
// }

// printLine(result, 'Your runtime beats %d %% of %s submissions',
// ratio.toFixed(2), lang);
// });
} else {
result.testcase = result.testcase.slice(1, -1).replace(/\\n/g, '\n');
printResult(result, 'error');
printResult(result, 'testcase');
printResult(result, 'answer');
Expand Down
Loading