From 5a2265254920d4431b369e8dca44f4802f2f7f2c Mon Sep 17 00:00:00 2001 From: "G.D Sahan Chandrabahu" <52454302+SahanChan@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:31:06 +0530 Subject: [PATCH 1/2] added Stacks algo java #hacktoberfest --- JAVA/StacksJava/StackApp.java | 42 +++++++++++++++++++++++++++++++++++ JAVA/StacksJava/Stacks.java | 33 +++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 JAVA/StacksJava/StackApp.java create mode 100644 JAVA/StacksJava/Stacks.java diff --git a/JAVA/StacksJava/StackApp.java b/JAVA/StacksJava/StackApp.java new file mode 100644 index 0000000..cfd450d --- /dev/null +++ b/JAVA/StacksJava/StackApp.java @@ -0,0 +1,42 @@ +package Java.StacksJava; + +public class StackApp { + private long[] stackArray; + private int maxSize; + private int top; + + public StackApp(int s) { + maxSize = s; + stackArray = new long[maxSize]; + top = -1; + } + + public void push(long i) { + stackArray[++top] = i; + } + + public long peek() { + return stackArray[top]; + } + + public long pop() { + return stackArray[top--]; + } + + public boolean isEmpty() { + return (top == -1); + } + + public boolean isFull() { + return (top == maxSize - 1); + } + + public void display() { + + for (int i = 0; i <= top; i++) { + System.out.print(stackArray[i] + " "); + } + System.out.println(""); + + } +} \ No newline at end of file diff --git a/JAVA/StacksJava/Stacks.java b/JAVA/StacksJava/Stacks.java new file mode 100644 index 0000000..fa85b8f --- /dev/null +++ b/JAVA/StacksJava/Stacks.java @@ -0,0 +1,33 @@ +package Java.StacksJava; + +public class Stacks { + + public static void main(String[] args) { + StackApp my_stack = new StackApp(10); + + my_stack.push(10); + my_stack.push(20); + my_stack.push(40); + my_stack.push(30); + System.out.println(my_stack.peek()); + my_stack.display(); + my_stack.push(60); + my_stack.push(80); + my_stack.display(); + System.out.println(my_stack.pop()); + my_stack.display(); + my_stack.push(100); + my_stack.push(50); + my_stack.push(90); + my_stack.display(); + + while (!my_stack.isEmpty()) { + long value = my_stack.pop(); + System.out.print(value); + System.out.print(" "); + + } + System.out.println(""); + } + +} \ No newline at end of file From 25b7d06ba05b11f070496cc4e93851fe05b3b96e Mon Sep 17 00:00:00 2001 From: sahan Date: Wed, 21 Oct 2020 08:13:17 +0530 Subject: [PATCH 2/2] addedAutomatingDownloadScript --- Python/downloadsManager.py | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100755 Python/downloadsManager.py diff --git a/Python/downloadsManager.py b/Python/downloadsManager.py new file mode 100755 index 0000000..01befd8 --- /dev/null +++ b/Python/downloadsManager.py @@ -0,0 +1,99 @@ +import os +import shutil +import platform + +# function to run on linux + + +def runLinux(): + print("on Linux") + linuxUsername = str(os.getlogin()) + linuxDirectory = "/home/" + linuxUsername + "/Downloads" + os.chdir(linuxDirectory) + + for f in os.listdir(linuxDirectory): + fileSource = str(os.getcwd()) + "/" + str(f) + fileTypeSplitList = list(os.path.splitext(f)) + fileType = fileTypeSplitList[1] + if(fileType == '.torrent'): + if not (os.path.isdir("Torrents")): + os.mkdir("Torrents") + shutil.move(fileSource, os.getcwd() + "/" + "Torrents") + elif(fileType == '.mp3' or fileType == '.wav'): + if not (os.path.isdir("Music")): + os.mkdir("Music") + shutil.move(fileSource, os.getcwd() + "/" + "Music") + elif(fileType == '.mp4' or fileType == '.wmv' or fileType == '.ogg'): + if not (os.path.isdir("Videos")): + os.mkdir("Videos") + shutil.move(fileSource, os.getcwd() + "/" + "Videos") + elif(fileType == '.deb'): + if not (os.path.isdir("Softwares")): + os.mkdir("Softwares") + shutil.move(fileSource, os.getcwd() + "/" + "Softwares") + elif(fileType == '.tar' or fileType == '.7z' or fileType == '.rar' or fileType == '.zip'): + if not (os.path.isdir("Softwares")): + os.mkdir("Softwares") + shutil.move(fileSource, os.getcwd() + "/" + "Softwares") + elif(fileType == '.png' or fileType == '.jpg' or fileType == '.jpeg' or fileType == '.gif'): + if not (os.path.isdir("Images")): + os.mkdir("Images") + shutil.move(fileSource, os.getcwd() + "/" + "Images") + elif(fileType == '.pdf'): + if not (os.path.isdir("PDF_Documents")): + os.mkdir("PDF_Documents") + shutil.move(fileSource, os.getcwd() + "/" + "PDF_Documents") + +# function to run on windows + + +def runWindows(): + print("on windows") + windowsUsername = str(os.getlogin()) + windowsDirectory = "C:/Users/" + windowsUsername + "/Downloads" + os.chdir(windowsDirectory) + + for f in os.listdir(): + file_source = str(os.getcwd()) + "\\" + str(f) + file_source = str(file_source.replace("\\", "/")) + splitList = list(os.path.splitext(f)) + file_type = splitList[1] + + if(file_type == '.torrent'): + if not (os.path.isdir("Torrents")): + os.mkdir("Torrents") + shutil.move(file_source, os.getcwd() + "\\" + "Torrents") + + elif(file_type == '.mp3'): + if not (os.path.isdir("Music")): + os.mkdir("Music") + shutil.move(file_source, os.getcwd() + "\\" + "Music") + + elif(file_type == '.mp4'): + if not (os.path.isdir("Videos")): + os.mkdir("Videos") + shutil.move(file_source, os.getcwd() + "\\" + "Videos") + + elif(file_type == '.zip' or file_type == '.rar'): + if not (os.path.isdir("Archives")): + os.mkdir("Archives") + shutil.move(file_source, os.getcwd() + "\\" + "Archives") + + elif(file_type == '.exe'): + if not (os.path.isdir("EXE")): + os.mkdir("EXE") + shutil.move(file_source, os.getcwd() + "\\" + "EXE") + + +def runMac(): + print("Since i cannot afford an apple computer to implement the function ,u cannot manage your downloads :-(") + + +operatingSystem = platform.system() + +if(operatingSystem == 'Linux'): + runLinux() +elif(operatingSystem == 'Windows'): + runWindows() +else: + runMac()