GithubHelp home page GithubHelp logo

jjjchens235 / leetcode-sql-unlocked Goto Github PK

View Code? Open in Web Editor NEW
96.0 1.0 28.0 26.35 MB

Through the command line, the user can easily access all ~125 LeetCode SQL/Database questions and automatically generate the tables in db-fiddle.com.

Python 100.00%

leetcode-sql-unlocked's Introduction

Update 11/14/2021: I just tried this program for the first time in months and it looks like leetcode.jp no longer hosts any LeetCode questions. I guess the good times had to come to an end. You can still access old db-fiddle URL's here, but the problem statements are gone.

Through the command line, the user can easily access all ~125 LeetCode SQL/Database questions, and automatically generate the tables in db-fiddle.com, a SQL database playground environment.

GIF demo

Features

  • Auto-generate tables from each SQL/Database LeetCode problem into db-fiddle so all your queries can be tested
  • Past db-fiddles are saved, so progress is never lost and the user can continue right where they left off
  • Convenient LeetCode question navigation, by level or by number
  • Solutions tab easily opened

Getting Started

  1. Requires Google Chrome which can be downloaded from https://www.google.com/chrome/browser/desktop/index.html.
  2. Python 3.6+. If you don't already have Python 3 installed, visit https://www.python.org/downloads/.
  3. The only dependency is selenium. Either install using pip install selenium or use the requirements.txt file included in the repo: pip install -r requirements.txt.
  4. Run setup.py to create a config file with default settings.
  5. And you're all set. To start the program run leetcode_sql_unlocked/leetcode_sql_unlocked.py and follow the onscreen prompt.

Command Line Options

(h)elp: Show this help menu.

(n)ext [LEVEL]: Select next problem. Optionally, go next by level [(e)asy, (m)edium, (h)ard], default ignores levels. Ex: 'n' to go to next problem, 'ne' to go to next easy problem.

(q)uestion NUMBER: Select problem by question number. Ex: 'q 183' or simply '183' to go to question 183.

(s)olution: Open solution of current problem in new chrome tab. If solution is not found, will do a google search in a new window

(d)isplay [LEVEL] [# TO DISPLAY]: Displays list of problems. Optionally, can display by level [(e)asy, (m)edium, (h)ard]. Furthermore, can optionally choose how many problems to display, default is 15. Ex: 'd' is to display next 15 problems of all levels, 'd e 30' is to display the next 30 easy problems.

(l)oad ON/OFF: Pre-load additional questions in the background for faster future question access. Ex: 'l on' is to turn load on, and 'l off' is to turn load off"

(e)xit: Exit Program

Config

These settings can be configured within leetcode_sql_unlocked/src/config.py:

  1. db-fiddle settings

    • db_engine: User has the following databases to choose from: MYSQL_8, POSTGRES_12, and SQLITE_3_3. Default is MYSQL_8.
    • save_before_closing: If True, before going to the next question or exiting, will save the current fiddle automatically. Default is False, meaning the user must manually click save if they want the changes they made to persist beyond the current session.
      • Note that the fiddle is always saved when first created- this setting is for all proceeding saves.
    • check_new_save_versions: If True, will check for any newer versions of an existing db-fiddle. Default is False. This setting should only be switched to True if user is planning to make changes to their db-fiddles outside of this program.
  2. forking

    • is_fork_public_url: If True, will try to create a new db-fiddle by forking the public db fiddle url that is provided in db_fiddle_public_urls.md. If False, will create a brand new fiddle from scratch. The default is True.
      • Most likely, this should be kept as True as forking an existing fiddle is faster than creating a new one. The exception might be if the user wants to create a db-fiddle with a different config than the one provided in the public url, such as using Postgres rather than MySQL.
  3. preloading

    • is_preload: If True, preloading will be turned on and if False it will be turned off. True by default.
      • This can be toggled within the program itself by using 'l on' and 'l off'.
    • n_to_preload: For each question selected, the number of succeeding questions to preload in the background. The default is 1.
    • n_same_level_to_preload: For each question selected, the number of succeeding questions of the SAME LEVEL to preload in the background. The default is 1.
Additional notes on pre-loading

Preloading refers to creating additional db-fiddles in a background/headless web driver. The questions that will be preloaded are those that are next in line numerically from the question the user is currently on.

Preloading should be useful for most users as it allows for minimized load times, especially for db-fiddles that need to be created from scratch (not forked). It should be turned off though if the user is planning on navigating questions in a non-sequential manner or if there are computer performance issues.

Known Issues

  • Some problems don't have actual table data. For example problem #175 only includes table schemas, so no tables can be parsed, the table schemas need to be loaded manually into db-fiddle.com.
  • DB-fiddle.com issues
    • Columns with only blank values are parsed as INTEGER in db-fiddle's text to DDL parser. However, this ends up throwing an error when the tables are actually queried on. This issue occurs for problem #586, a simple fix is switching from INTEGER to VARCHAR(1) in the table schema.
    • Columns with %Y-%m, i.e. '2017-05' are parsed as DATETIME when they should be parsed as VARCHAR inside db-fiddle's text to DDL. A simple fix is switching from DATETIME to VARCHAR(7) in the table schema. This issue occurs for #615.

DB Fiddle url quick access

For convenience, this file contains db-fiddle links for each LeetCode SQL problem. This might be useful if you want to to test your queries on just a few problems, you don't have Python, etc.

Future Ideas

  • Create public db-fiddles for Postgres and sqlite as well.
  • Create db-fiddle solution links for each question instead of using github solutions which doesn't contain every solution and loads slower.

leetcode-sql-unlocked's People

Contributors

jjjchens235 avatar

Stargazers

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

Watchers

 avatar

leetcode-sql-unlocked's Issues

Cannot run leetcode-sql-unlocked any more

Hi,

First, I would love to thank you for putting this together. I have been using it for weeks and it was working. However, last week, when I tried to use it again, it shows the error that

Traceback (most recent call last):
File "leetcode_sql_unlocked.py", line 77, in
main()
File "leetcode_sql_unlocked.py", line 53, in main
lc = get_leetcode()
File "leetcode_sql_unlocked.py", line 49, in get_leetcode
lc = Leetcode(driver_path, q_elements_path, q_state_path, q_public_urls_path, headless=headless)
File "/Users/jq41/Documents/Python/python3/leetcode-sql-unlocked-master/leetcode_sql_unlocked/src/leetcode.py", line 39, in init
self.question_nodes = QuestionNodes(q_elements, self.question_log.q_state['current'])
File "/Users/jq41/Documents/Python/python3/leetcode-sql-unlocked-master/leetcode_sql_unlocked/src/questions.py", line 25, in init
self.__current = self.create_q_nodes(question_elements, curr_log_num)
File "/Users/jq41/Documents/Python/python3/leetcode-sql-unlocked-master/leetcode_sql_unlocked/src/questions.py", line 36, in create_q_nodes
for q_num in question_elements.keys():
AttributeError: 'NoneType' object has no attribute 'keys'

I tried to run the test file and it gives similar error, saying that "Could not find question elements from leetcode.com
E". Is it related to the leetcode website update?

Thanks

i am getting this error

Traceback (most recent call last):
File "/usr/lib/python3.8/urllib/request.py", line 1350, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/usr/lib/python3.8/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1010, in _send_output
self.send(msg)
File "/usr/lib/python3.8/http/client.py", line 950, in send
self.connect()
File "/usr/lib/python3.8/http/client.py", line 1424, in connect
self.sock = self._context.wrap_socket(self.sock,
File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL] internal error (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "leetcode_sql_unlocked.py", line 77, in
main()
File "leetcode_sql_unlocked.py", line 53, in main
lc = get_leetcode()
File "leetcode_sql_unlocked.py", line 49, in get_leetcode
lc = Leetcode(driver_path, q_elements_path, q_state_path, q_public_urls_path, headless=headless)
File "/home/omar/Downloads/dgf/leetcode-sql-unlocked/leetcode_sql_unlocked/src/leetcode.py", line 23, in init
self.web_handler = WebHandler(self.driver_path, headless)
File "/home/omar/Downloads/dgf/leetcode-sql-unlocked/leetcode_sql_unlocked/src/web_handler.py", line 30, in init
self.driver = Driver.get_driver(driver_path, headless=headless)
File "/home/omar/Downloads/dgf/leetcode-sql-unlocked/leetcode_sql_unlocked/src/driver.py", line 76, in get_driver
Driver.__download_driver(path, system)
File "/home/omar/Downloads/dgf/leetcode-sql-unlocked/leetcode_sql_unlocked/src/driver.py", line 29, in __download_driver
response = urlopen("https://sites.google.com/a/chromium.org/chromedriver/downloads", context=ssl.SSLContext(ssl.PROTOCOL_TLSv1)).read()
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 1393, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/usr/lib/python3.8/urllib/request.py", line 1353, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL] internal error (_ssl.c:1123)>

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.