diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43802e6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.ipynb_checkpoints +__pycache__ +runscript.bat \ No newline at end of file diff --git a/Basic DSA Questions/Basic DSA Questions.ipynb b/Basic DSA Questions/Basic DSA Questions.ipynb new file mode 100644 index 0000000..e1e7dbf --- /dev/null +++ b/Basic DSA Questions/Basic DSA Questions.ipynb @@ -0,0 +1,33 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a49fbd2f", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Basic DSA Questions/watcher.py b/Basic DSA Questions/watcher.py new file mode 100644 index 0000000..3e02b80 --- /dev/null +++ b/Basic DSA Questions/watcher.py @@ -0,0 +1,135 @@ +import re +import os +import time +import random +import subprocess +from watchdog.observers import Observer +from watchdog.events import FileSystemEventHandler + +# for a safer side git pull before any other operation +os.popen("git pull") + +GREEN = "\033[1;32m" +RED = "\033[1;31m" +RESET = "\033[0m" +print(f"{GREEN}Hey Chandrashekhar All the best Do bunch of problems today 👍🏻💖{RESET}") + + +class Watcher: + # set the Path of the directory to monitor + DIRECTORY_TO_WATCH = "C:\GFG_DataScience\LeetCode\Blind 75" + + + def __init__(self): + self.observer = Observer() + + def run(self): + event_handler = Handler() + self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=False) + self.observer.start() + try: + while True: + time.sleep(5) + except: + self.observer.stop() + print("Error") + + self.observer.join() + + +class Handler(FileSystemEventHandler): + counter = 0 + + @staticmethod + def on_any_event(event): + if event.is_directory: + return None + + elif event.event_type == 'created': + # Take any action here when a file is first created. + print("Received created event - %s." % event.src_path) + + + elif event.event_type == 'modified': + GREEN = "\033[1;32m" + RED = "\033[1;31m" + RESET = "\033[0m" + # Taken any action here when a file is modified. + print("Received modified event - %s." % event.src_path) + # to extract specific file name from the event path + if '~' in event.src_path: + value = event.src_path.split("~")[-1] + else: + value = event.src_path.split("\\")[-1] + # to check which value gets printed + print(value) + # if the file is not Untitled then only perform operations + if value != 'Untitled.ipynb': + # get all the possible values such that it can related to changes + s = ["changes", "update", "modification","Made modifications", "Updated code", "Implemented alterations", "Tweaked the code", "Adjusted the program", "Modified the source code", "Refactored the code", "Edited", "Made adjustments"] + # pre_msg for commit messagfe + pre_msg = ["Added Some Code to","Modified","Changes in ", "Added new functionality to", "Introduced code changes to","Integrated new code into","Updated code in","Made changes to","Tweaked code in","Edited code in","Adjusted code in","Refactored code in","Revised code in","Reworked code in","Altered code in","Improved code in"] + # emojis + emojis = ['👀','💖','🥳','🙌','🚩','😎','🥰','🫣','👻','💪','✌','✍','👑','🚀','❤️‍','🔥'] + # it returns the output of what all changes we have done to the file + diff_output = subprocess.check_output(['git', 'diff', f'{value}']).decode() + # this is the pattern to find def function present in it or not + pattern = r"def\s+(\w+)\(" + print("Inside the While loop 🌀") +# print("Diff Output", diff_output) + # Use re.search() to find the first match of the pattern in the input string + match = re.findall(pattern, diff_output) + if match: print("Match Found 👍🏻") + else: print("Match Not Found 👎🏻") + # set initial value to None + commit_message = None + # if a match is founf then change the commit_message with the function name + if match: + commit_message = f"{random.choice(pre_msg)} `{match[-1]}` function {random.choice(emojis)}" + Handler.counter = 0 + n = 0 + # else select random from s and change the value of commit_message + else: +# commit_message = random.choice(s) + # check if the counter has reached 20 + n = 20 + if Handler.counter == n: + # reset the counter + Handler.counter = 0 + # choose a random commit message from s + commit_message = random.choice(s) + random.choice(emojis) + else: + # increment the counter + Handler.counter += 1 + # print the commit message to see in terminal + k = f"{RED}You haven't made changes in the functions so your commit will be added after {n - Handler.counter} changes in your file:({RESET}" if (20 - Handler.counter) > 0 else f"{GREEN}Your commit will be added now:){RESET}" + + print(f"Counter: {Handler.counter}") + if commit_message != None: + print(f"commit message is {GREEN}'{commit_message}'{RESET}") + # now git add the file + os.popen(f'git add "{value}"') + # time.sleep so that there will be no load at once at cmd + time.sleep(1) + os.popen(f'git commit -m "{commit_message}"') + # finally git push 🥳 + time.sleep(1) + os.popen("git push") + # os.popen("^C") + time.sleep(1) + # this timer such that it will again see in after 10 seconds + print(f"{GREEN}Git Pushed Successfully{RESET} 🥳") + else: + print(k) + + time.sleep(10) + # if not untitled then send message + else: + print(f"{value} is common so it wouldn't be added Rename it to add") +# print("test") + + + +if __name__ == '__main__': + w = Watcher() + w.run() \ No newline at end of file diff --git a/Deque.ipynb b/Deque.ipynb index 97a98b4..621a90e 100644 --- a/Deque.ipynb +++ b/Deque.ipynb @@ -44,7 +44,9 @@ "cell_type": "code", "execution_count": 2, "id": "9d60a2c8", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [ { "data": { @@ -70,24 +72,12 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "id": "65ca748e", "metadata": { "tags": [] }, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'deque' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m deq \u001b[38;5;241m=\u001b[39m \u001b[43mdeque\u001b[49m()\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m#Function to erase the element from specified position X in deque.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21meraseAt\u001b[39m(deq,x):\n", - "\u001b[1;31mNameError\u001b[0m: name 'deque' is not defined" - ] - } - ], + "outputs": [], "source": [ "deq = deque()\n", "#Function to erase the element from specified position X in deque.\n", @@ -120,7 +110,9 @@ "cell_type": "code", "execution_count": 4, "id": "b8c58fe3", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "class List_deque:\n", @@ -156,7 +148,9 @@ "cell_type": "code", "execution_count": 5, "id": "ab4a4480", - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "d = List_deque()" diff --git a/Graphs.ipynb b/Graphs.ipynb index 8b5ed50..1a49e7b 100644 --- a/Graphs.ipynb +++ b/Graphs.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "id": "f421e371", "metadata": { "tags": [] @@ -27,7 +27,9 @@ "metadata": {}, "source": [ "# Graphs\n", - "\n" + "\n", + "\n", + "#### if the below links are not clickable then : [Click Me](https://nbviewer.org/github/ChandrashekharRobbi/GFG-DSA/blob/main/Graphs.ipynb?flush_cache=True)" ] }, { diff --git a/Hashing.ipynb b/Hashing.ipynb index 97e50eb..35c20a5 100644 --- a/Hashing.ipynb +++ b/Hashing.ipynb @@ -1257,7 +1257,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 43, "id": "71fa38b9", "metadata": {}, "outputs": [], @@ -1281,7 +1281,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 44, "id": "e539f705", "metadata": {}, "outputs": [], @@ -1310,7 +1310,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 45, "id": "48603a6a", "metadata": {}, "outputs": [], @@ -1336,7 +1336,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 46, "id": "4eb60bea", "metadata": {}, "outputs": [], @@ -1361,7 +1361,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 47, "id": "0d0578d0", "metadata": {}, "outputs": [], @@ -1377,7 +1377,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 48, "id": "6322545c", "metadata": {}, "outputs": [], @@ -1404,6 +1404,14 @@ "metadata": {}, "outputs": [], "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "990953f6", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/Heap.ipynb b/Heap.ipynb index 11a7481..cb6cdde 100644 --- a/Heap.ipynb +++ b/Heap.ipynb @@ -287,24 +287,6 @@ "heapify(arr, len(arr), 0)" ] }, - { - "cell_type": "code", - "execution_count": 8, - "id": "81990fa3-d8bc-47e9-b58f-568167a0a702", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Sort K sorted Array\")" - ] - }, { "cell_type": "markdown", "id": "a9fd0538-f487-47ac-9c76-7c5fa4c3d1cb", @@ -357,26 +339,6 @@ " print(f\"The following Sorted Array is \\n{arr}\")" ] }, - { - "cell_type": "code", - "execution_count": 18, - "id": "a5b56f9d-2983-4113-8cab-c42284679c86", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Purchase Maximum Items\")" - ] - }, { "cell_type": "markdown", "id": "6f01d903-250e-455e-afe4-2c3ae2a3dd91", @@ -440,26 +402,6 @@ "purchaseItem([20,10,5,30,100], 35)" ] }, - { - "cell_type": "code", - "execution_count": 33, - "id": "269ac1cc-cc88-4e63-9c90-7aab1de7c8c0", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Kth Largest Elements\")" - ] - }, { "cell_type": "markdown", "id": "84f8a8c5-2acc-439e-a619-41965ba553a9", @@ -500,26 +442,6 @@ " return arr[::-1]" ] }, - { - "cell_type": "code", - "execution_count": 34, - "id": "5df5255d-788b-4e15-a78b-03ac586a8c9f", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Kth Largest Element\")" - ] - }, { "cell_type": "markdown", "id": "ad2da333-725a-4e7e-afcf-c1cac69d02ae", @@ -548,26 +470,6 @@ " return heapq.heappop(heap)" ] }, - { - "cell_type": "code", - "execution_count": 37, - "id": "6f9b3187-60a8-4b66-8c0d-48f67d160fc9", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Kth Smallest Element\")" - ] - }, { "cell_type": "code", "execution_count": 38, @@ -587,26 +489,6 @@ " return -heapq.heappop(heap)" ] }, - { - "cell_type": "code", - "execution_count": 39, - "id": "0191d58d-587a-4959-a594-93a96e161928", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Kth Closest Element\")" - ] - }, { "cell_type": "markdown", "id": "bbccc15b-190d-4c03-8a05-1e14a88fe1d7", @@ -651,26 +533,6 @@ " print(arr[pi]) # if we print p which is a difference that's why we use index to print 🧠" ] }, - { - "cell_type": "code", - "execution_count": 42, - "id": "492280ca-0fb1-45a6-b76a-508bebe69824", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Successfully added to the comment list\n" - ] - } - ], - "source": [ - "z.new(\"Merge k sorted arrays\")" - ] - }, { "cell_type": "markdown", "id": "33036756-da80-4d3d-8b7f-0d25892352dd", @@ -701,48 +563,6 @@ " return res" ] }, - { - "cell_type": "code", - "execution_count": 46, - "id": "c878b9ca-240d-4b87-b504-14c5363b220e", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n", - "1\n", - "2\n", - "3\n", - "4\n", - "5\n", - "6\n" - ] - }, - { - "data": { - "application/javascript": [ - "\n", - " var cell_index = IPython.notebook.get_selected_index();\n", - " var prev = cell_index - 1;\n", - " IPython.notebook.delete_cell(prev);\n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "z.printArr()" - ] - }, { "cell_type": "code", "execution_count": null, diff --git a/Tree.ipynb b/Tree.ipynb index 0d89bc1..3008c36 100644 --- a/Tree.ipynb +++ b/Tree.ipynb @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 14, "id": "bb1c57ed", "metadata": { "tags": [] @@ -126,7 +126,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 15, "id": "73f7f192", "metadata": {}, "outputs": [], @@ -205,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 16, "id": "249c9ddb", "metadata": {}, "outputs": [], @@ -219,7 +219,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 17, "id": "656d4bd9", "metadata": {}, "outputs": [], @@ -266,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 18, "id": "b201f6ca", "metadata": {}, "outputs": [ @@ -299,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 19, "id": "17d48b8b", "metadata": {}, "outputs": [], @@ -346,7 +346,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 20, "id": "8ca44b86", "metadata": {}, "outputs": [ @@ -378,7 +378,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 21, "id": "35a1b07d", "metadata": {}, "outputs": [], @@ -425,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 22, "id": "fc36d76e", "metadata": {}, "outputs": [ @@ -461,7 +461,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 23, "id": "9b1d68d7", "metadata": {}, "outputs": [], @@ -508,7 +508,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 24, "id": "a8d7df7b", "metadata": {}, "outputs": [ @@ -518,7 +518,7 @@ "3" ] }, - "execution_count": 11, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -539,7 +539,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 25, "id": "1b748d86-186d-4201-9811-0e7fb242eb18", "metadata": {}, "outputs": [], @@ -575,7 +575,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 26, "id": "27a90baf-80eb-46d0-af8d-a4a84ba8a917", "metadata": {}, "outputs": [ @@ -613,7 +613,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 27, "id": "468889fb-0732-43ce-9099-0fc94e1ac14c", "metadata": {}, "outputs": [], @@ -626,7 +626,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 28, "id": "e1bdfdcb-6352-4db3-8201-36ef0464c0af", "metadata": {}, "outputs": [ @@ -664,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 29, "id": "4abac0be-7a07-4b97-98b9-0411bc13d2b3", "metadata": {}, "outputs": [], @@ -696,7 +696,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 30, "id": "d8b8f782-9392-4d75-9d67-ca4c56774714", "metadata": {}, "outputs": [], @@ -720,7 +720,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 31, "id": "73c5e8f0-7bf6-4a1b-b2b4-fe9945b75e44", "metadata": {}, "outputs": [ @@ -756,7 +756,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 32, "id": "ebb22e3c-e07c-441d-9e05-9d6a53d2a342", "metadata": {}, "outputs": [], @@ -772,7 +772,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 33, "id": "70d840de-c4db-41fa-9ba0-f102a95ca51a", "metadata": {}, "outputs": [ @@ -782,7 +782,7 @@ "9" ] }, - "execution_count": 20, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -803,7 +803,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 34, "id": "a007630e-5c4b-44cf-98f5-4d3f8ddb31fb", "metadata": {}, "outputs": [], @@ -820,7 +820,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 35, "id": "8eccd59c-3da4-49fc-84e3-b48656622686", "metadata": {}, "outputs": [ @@ -830,7 +830,7 @@ "90" ] }, - "execution_count": 22, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -849,7 +849,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 36, "id": "933f42fe", "metadata": {}, "outputs": [], @@ -873,7 +873,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 37, "id": "60042d51", "metadata": {}, "outputs": [], @@ -899,7 +899,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 38, "id": "8cb92438", "metadata": {}, "outputs": [], @@ -916,7 +916,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 39, "id": "27a22b6a", "metadata": {}, "outputs": [ @@ -926,7 +926,7 @@ "True" ] }, - "execution_count": 26, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -937,7 +937,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 40, "id": "806dc4a1", "metadata": {}, "outputs": [], @@ -958,7 +958,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 41, "id": "7e6d203e", "metadata": {}, "outputs": [], @@ -971,7 +971,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 42, "id": "f8c2883f", "metadata": {}, "outputs": [ @@ -981,7 +981,7 @@ "True" ] }, - "execution_count": 29, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -1000,7 +1000,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 43, "id": "a625599a", "metadata": {}, "outputs": [ @@ -1026,7 +1026,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 44, "id": "46e74b0c", "metadata": {}, "outputs": [], @@ -1062,7 +1062,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 45, "id": "456d6f3c", "metadata": {}, "outputs": [ @@ -1083,7 +1083,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 46, "id": "2c10f9a0", "metadata": {}, "outputs": [], @@ -1107,7 +1107,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 47, "id": "8ba431bf", "metadata": {}, "outputs": [ @@ -1155,7 +1155,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 48, "id": "681e7d8b", "metadata": {}, "outputs": [], @@ -1173,7 +1173,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 49, "id": "ccadd433", "metadata": {}, "outputs": [], @@ -1217,7 +1217,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 50, "id": "8eacd6aa", "metadata": {}, "outputs": [ @@ -1269,7 +1269,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 51, "id": "7e2f56cc", "metadata": {}, "outputs": [], @@ -1286,7 +1286,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 52, "id": "6f3d1c10", "metadata": {}, "outputs": [], @@ -1296,7 +1296,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 53, "id": "31fa2881", "metadata": {}, "outputs": [], @@ -1326,7 +1326,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 54, "id": "c69dcbfc", "metadata": {}, "outputs": [ @@ -1356,7 +1356,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 55, "id": "cfb894e4", "metadata": {}, "outputs": [], @@ -1390,7 +1390,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 56, "id": "f37fd023", "metadata": {}, "outputs": [], @@ -1413,17 +1413,17 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 57, "id": "d284d725", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<__main__.Node at 0x1a5e7225c90>" + "<__main__.Node at 0x26ce72212a0>" ] }, - "execution_count": 44, + "execution_count": 57, "metadata": {}, "output_type": "execute_result" } @@ -1444,7 +1444,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 58, "id": "4eac0c6f", "metadata": {}, "outputs": [], @@ -1472,17 +1472,17 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 59, "id": "8eb109fa", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<__main__.Node at 0x1a5e7227be0>" + "<__main__.Node at 0x26ce725c2b0>" ] }, - "execution_count": 46, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -1494,7 +1494,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 60, "id": "7115c228", "metadata": {}, "outputs": [], @@ -1530,17 +1530,17 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 61, "id": "c8a36293", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<__main__.Node at 0x1a5e72267a0>" + "<__main__.Node at 0x26ce5cc8a00>" ] }, - "execution_count": 48, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -1569,7 +1569,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 62, "id": "d834eff3", "metadata": {}, "outputs": [], @@ -1603,7 +1603,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 63, "id": "542d66d0", "metadata": {}, "outputs": [], @@ -1620,7 +1620,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 64, "id": "da101c29", "metadata": { "scrolled": true @@ -1652,7 +1652,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 65, "id": "81cdca2f", "metadata": {}, "outputs": [], @@ -1685,7 +1685,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 66, "id": "282b1a3c", "metadata": {}, "outputs": [ @@ -1711,7 +1711,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 67, "id": "88f70bff", "metadata": {}, "outputs": [], @@ -1758,7 +1758,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 68, "id": "595507eb", "metadata": {}, "outputs": [], @@ -1775,7 +1775,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 69, "id": "c8a31884", "metadata": {}, "outputs": [ @@ -1785,7 +1785,7 @@ "6" ] }, - "execution_count": 56, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -1796,7 +1796,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 70, "id": "aa1ffa41", "metadata": {}, "outputs": [], @@ -1814,7 +1814,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 71, "id": "684b906d", "metadata": {}, "outputs": [ @@ -1824,7 +1824,7 @@ "4" ] }, - "execution_count": 58, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } @@ -1851,7 +1851,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 72, "id": "f00e2f49", "metadata": {}, "outputs": [], @@ -1885,7 +1885,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 73, "id": "687c400c", "metadata": {}, "outputs": [ @@ -1895,7 +1895,7 @@ "3" ] }, - "execution_count": 60, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } @@ -1906,7 +1906,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 74, "id": "d9948886", "metadata": {}, "outputs": [], @@ -1927,17 +1927,17 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 75, "id": "b454ef1c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<__main__.Node at 0x1a5e7225630>" + "<__main__.Node at 0x26ce725c9d0>" ] }, - "execution_count": 62, + "execution_count": 75, "metadata": {}, "output_type": "execute_result" } @@ -1956,7 +1956,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 76, "id": "0134fb83-307b-4bdf-afd3-027f7052bea5", "metadata": {}, "outputs": [], @@ -1989,7 +1989,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 77, "id": "61dea3f2", "metadata": {}, "outputs": [], @@ -2003,7 +2003,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 78, "id": "bd191e14", "metadata": {}, "outputs": [], @@ -2017,7 +2017,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 79, "id": "322731ee", "metadata": {}, "outputs": [ @@ -2027,7 +2027,7 @@ "5" ] }, - "execution_count": 66, + "execution_count": 79, "metadata": {}, "output_type": "execute_result" } @@ -2038,7 +2038,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 80, "id": "1d2c1160", "metadata": {}, "outputs": [], @@ -2064,7 +2064,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 81, "id": "4187a8b5", "metadata": {}, "outputs": [ @@ -2074,7 +2074,7 @@ "5" ] }, - "execution_count": 68, + "execution_count": 81, "metadata": {}, "output_type": "execute_result" } @@ -2110,7 +2110,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 82, "id": "46b8d6f3", "metadata": {}, "outputs": [], @@ -2126,7 +2126,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": 83, "id": "b8e9c444", "metadata": {}, "outputs": [ @@ -2146,7 +2146,7 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 84, "id": "cdc3eb47", "metadata": {}, "outputs": [], @@ -2166,17 +2166,17 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 85, "id": "a47b4ffb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "<__main__.Node at 0x1a5e7224a30>" + "<__main__.Node at 0x26ce7253bb0>" ] }, - "execution_count": 72, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } @@ -2205,7 +2205,7 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 86, "id": "d9a98c09", "metadata": {}, "outputs": [], @@ -2231,7 +2231,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 87, "id": "0e5929f2", "metadata": {}, "outputs": [ @@ -2264,7 +2264,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 88, "id": "c967e451", "metadata": {}, "outputs": [], @@ -2284,7 +2284,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 89, "id": "33a3f1fb", "metadata": {}, "outputs": [ @@ -2309,7 +2309,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 90, "id": "82a9dbfc", "metadata": {}, "outputs": [], @@ -2331,7 +2331,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 91, "id": "8505ebf2", "metadata": {}, "outputs": [ @@ -2357,7 +2357,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 92, "id": "9963d432", "metadata": {}, "outputs": [], @@ -2392,7 +2392,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 93, "id": "004818e2", "metadata": {}, "outputs": [], @@ -2414,7 +2414,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 94, "id": "467ed2c3", "metadata": {}, "outputs": [ @@ -2445,7 +2445,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 95, "id": "2baac184", "metadata": {}, "outputs": [], @@ -2470,7 +2470,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 96, "id": "2757d5df", "metadata": {}, "outputs": [ @@ -2498,7 +2498,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 97, "id": "4cea8b9e", "metadata": {}, "outputs": [], @@ -2534,7 +2534,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 98, "id": "ec1174b7", "metadata": {}, "outputs": [], @@ -2544,7 +2544,7 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 99, "id": "a51e6a94", "metadata": {}, "outputs": [ @@ -2554,7 +2554,7 @@ "3" ] }, - "execution_count": 86, + "execution_count": 99, "metadata": {}, "output_type": "execute_result" } @@ -2565,7 +2565,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 100, "id": "eebe01dd", "metadata": {}, "outputs": [], @@ -2575,7 +2575,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 101, "id": "54e7d57a", "metadata": {}, "outputs": [], @@ -2586,7 +2586,7 @@ }, { "cell_type": "code", - "execution_count": 89, + "execution_count": 102, "id": "fb741973", "metadata": {}, "outputs": [ @@ -2623,7 +2623,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 103, "id": "f4dcf519", "metadata": {}, "outputs": [], @@ -2643,7 +2643,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 104, "id": "de822da4", "metadata": {}, "outputs": [], @@ -2653,7 +2653,8 @@ "root.right = Node(20)\n", "root.left.left = Node(30)\n", "root.left.right = Node(40)\n", - "root.right.ri" + "root.right.left = Node(80)\n", + "root.right.right = Node(60)" ] }, { @@ -2666,7 +2667,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 105, "id": "4544a237", "metadata": {}, "outputs": [], @@ -2681,7 +2682,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 106, "id": "706efa1c", "metadata": {}, "outputs": [], @@ -2699,7 +2700,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 107, "id": "772badc6", "metadata": {}, "outputs": [], @@ -2723,19 +2724,17 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 108, "id": "ef44f2e8", "metadata": {}, "outputs": [ { - "ename": "NameError", - "evalue": "name 'root' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m level_order_Traversal_line(\u001b[43mroot\u001b[49m)\n", - "\u001b[1;31mNameError\u001b[0m: name 'root' is not defined" + "name": "stdout", + "output_type": "stream", + "text": [ + "5 \n", + "10 20 \n", + "30 40 80 60 \n" ] } ], @@ -2753,7 +2752,7 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 109, "id": "4802383e-cd59-46a3-9725-c6a4af5c87ed", "metadata": { "tags": [] @@ -2769,7 +2768,7 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 110, "id": "17163498-2c29-43d3-bddc-ebb13a18f695", "metadata": { "tags": [] @@ -2801,7 +2800,7 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 111, "id": "af3ee07b-736d-450c-add5-912d4338eb99", "metadata": { "tags": [] @@ -2821,7 +2820,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 112, "id": "2e04e401-2eae-45bd-b363-6b3a05fe7ae0", "metadata": { "tags": [] @@ -2849,7 +2848,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 113, "id": "9949173a-441e-4e63-b4a3-7563a59e60ba", "metadata": { "tags": [] @@ -2861,7 +2860,7 @@ "1" ] }, - "execution_count": 78, + "execution_count": 113, "metadata": {}, "output_type": "execute_result" } @@ -2874,223 +2873,19 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 115, "id": "107dcfed-b039-47d3-bb58-604328407563", "metadata": { "tags": [] }, - "outputs": [ - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 10\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 10\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 20\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 20\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 40\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 40\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 60\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 60\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 70\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 70\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 70\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 60\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 40\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 20\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 50\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 50\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 50\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 10\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data 30\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter left of 30\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Enter right of 30\n" - ] - }, - { - "name": "stdin", - "output_type": "stream", - "text": [ - "Enter Data -1\n" - ] - } - ], + "outputs": [], "source": [ - "root = createTree()" + "# root = createTree()" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 116, "id": "038836f7-13d2-4d60-9483-137e0363ce47", "metadata": { "tags": [] @@ -3099,10 +2894,10 @@ { "data": { "text/plain": [ - "<__main__.Node at 0x1f419655b10>" + "<__main__.Node at 0x26ce7253700>" ] }, - "execution_count": 46, + "execution_count": 116, "metadata": {}, "output_type": "execute_result" } diff --git a/sample.py b/sample.py index 10591bf..720e47d 100644 --- a/sample.py +++ b/sample.py @@ -1,123 +1,10 @@ -import re -import os -import time -import random -import subprocess -from watchdog.observers import Observer -from watchdog.events import FileSystemEventHandler +from IPython.display import Markdown +from IPython.core.getipython import get_ipython -# for a safer side git pull before any other operation -os.popen("git pull") +def on_markdown_change(cell): + print("Markdown content changed!") + display(Markdown(cell.value)) - -class Watcher: - # set the Path of the directory to monitor - DIRECTORY_TO_WATCH = "C:\GFG_DataScience\DSA" - - def __init__(self): - self.observer = Observer() - - def run(self): - event_handler = Handler() - self.observer.schedule(event_handler, self.DIRECTORY_TO_WATCH, recursive=False) - self.observer.start() - try: - while True: - time.sleep(5) - except: - self.observer.stop() - print("Error") - - self.observer.join() - - -class Handler(FileSystemEventHandler): - - @staticmethod - def on_any_event(event): - def checkForName(event): - # to extract specific file name from the event path - if '~' in event: - value = event.split("~")[-1] - else: - value = event.split("\\")[-1] - # to check which value gets printed - return value - - def findPatternOfFunction(value): - diff_output = subprocess.check_output(['git', 'diff', f'{value}']).decode() - # this is the pattern to find def function present in it or not - pattern = r"def\s+(\w+)\(" - # Use re.search() to find the first match of the pattern in the input string - return re.findall(pattern, diff_output) - - def countGen(): - return 0 - - def commit_message_find(pre_msg, match, s): - count = countGen() - if match: - return f"{random.choice(pre_msg)} {match[-1]} function",0 - # else select random from s and change the value of commit_message - else: - count += 1 - print(f"count {count}") - return None,count - if count == 10: - count = 0 - return random.choice(s),count - - - if event.is_directory: - return None - - elif event.event_type == 'created': - # Take any action here when a file is first created. - print("Received created event - %s." % event.src_path) - - - elif event.event_type == 'modified': -# count = 0 - # Taken any action here when a file is modified. - print("Received modified event - %s." % event.src_path) - value = checkForName(event.src_path) - print(value) - # if the file is not Untitled then only perform operations - if value != 'Untitled.ipynb': - # get all the possible values such that it can related to changes - s = ["changes", "update", "modification"] - # pre_msg for commit messagfe - pre_msg = ["Added Some Code to","Modified","Changes in "] - # it returns the output of what all changes we have done to the file - match = findPatternOfFunction(value) - # set initial value to None - commit_message = None - # if a match is found then change the commit_message with the function name - commit_message,count = commit_message_find(pre_msg, match, s, count) - # print the commit message to see in terminal - print(f"commit message is '{commit_message}'") - # now git add the file - os.popen(f'git add "{value}"') - # time.sleep so that there will be no load at once at cmd - time.sleep(1) - time.sleep(1) - # git commit along with message - if commit_message != None: - os.popen(f'git commit -m "{commit_message}"') - else: - pass - time.sleep(1) - # finally git push 🥳 - os.popen("git push") - # os.popen("^C") - # this timer such that it will again see in after 10 seconds - time.sleep(10) - # if not untitled then send message - else: - print(f"{value} is common so it wouldn't be added Rename it to add") - - - -if __name__ == '__main__': - w = Watcher() - w.run() \ No newline at end of file +for cell in get_ipython().notebook.cells: + if cell.cell_type == 'markdown': + cell.events.on_change(on_markdown_change) \ No newline at end of file