scripts

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 06435fc16557a7e828dad24508e44d82f223577a
parent fa8c79158a30973b6f922c27ab94960a3b802a5d
Author: Andrew Laack <andrew@laack.co>
Date:   Wed,  2 Jul 2025 10:04:25 -0500

Added script for creating leetcode submission in a directory

Diffstat:
Aleetcode-submission.py | 6++++++
Apython-files/create-leetcode.py | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arun-jupyter.sh | 4++++
3 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/leetcode-submission.py b/leetcode-submission.py @@ -0,0 +1,6 @@ +#!/bin/bash + +# you could try using open instead of vim, but depending on the filetype +# you may run into issues. + +output=$(python3 ~/bin/python-files/create-leetcode.py "$1" "$2") && echo "$output" | xargs vim diff --git a/python-files/create-leetcode.py b/python-files/create-leetcode.py @@ -0,0 +1,82 @@ +import os +import re +import sys + +# This assumes the CWD is laid out as follows: + +# PROBLEM-NAME +# -> PROBLEM-NAMEV1.py +# -> PROBLEM-NAMEV2.py +# -> PROBLEM-NAMEVN.py +# PROBLEM-NAME +# -> PROBLEM-NAMEV1.py +# -> PROBLEM-NAMEV2.py +# -> PROBLEM-NAMEVN.py +# PROBLEM-NAME +# -> PROBLEM-NAMEV1.py +# -> PROBLEM-NAMEV2.py +# -> PROBLEM-NAMEVN.py + +# NOTE: +# the file names are truncated versions of the +# problem name for simplicity sake. These are limited to +# 10 characters + the V extension and file extension. + +def create_directory(problem_name) -> str: + os.makedirs(problem_name, exist_ok=True) + return problem_name + +def get_file_name(problem_name, dir_name, extension : str): + + assert os.path.exists(dir_name), "Directory should exist when invoking get_file_name." + + done = False + count = 0 + + problem_name = problem_name[:10] + + while not done: + + count += 1 + current = problem_name + "V" + str(count) + "." + extension + current_path = os.path.join(dir_name, current) + + if os.path.exists(current_path): + continue + else: + return current + +def create_file(dir_name, name): + file_path = os.path.join(dir_name, name) + open(file_path, 'a').close() + return file_path + + +def parse_url(url): + match = re.search(r"leetcode\.com/problems/([^/]+)", url) + if match: + problem_name = match.group(1) + return problem_name + else: + raise ValueError("Unexpected URL format in input #1: " + url) + + +if __name__ == "__main__": + """Creates and opens file based on LC URL in $1 and the file extension in $2.""" + + try: + problem_name = parse_url(sys.argv[1]) + file_extension = sys.argv[2] + except IndexError as e: + raise ValueError(f'Please specify the filename and file extension from the cli: {e}') + + dir_name = create_directory(problem_name) + + name = get_file_name(problem_name, dir_name, file_extension) + file_path = create_file(dir_name, name) + + # send file path to stdout. + # this will be piped into xargs to open the file with your + # preferred text editor. + + print(file_path) diff --git a/run-jupyter.sh b/run-jupyter.sh @@ -0,0 +1,4 @@ +echo "NOTE: SET YOUR VENV!!!" +python -m jupyter_ascending.scripts.make_pair --base $1 +python -m jupyter notebook $1.sync.ipynb & +echo $1.sync.py | entr -r python -m jupyter_ascending.requests.sync --filename $1.sync.py