Skip to content

Instantly share code, notes, and snippets.

@minghao912
Last active August 12, 2019 02:57
Show Gist options
  • Select an option

  • Save minghao912/2874288b4f68276144aac25c3b0f67de to your computer and use it in GitHub Desktop.

Select an option

Save minghao912/2874288b4f68276144aac25c3b0f67de to your computer and use it in GitHub Desktop.
The best IDE ever created by man
import java.awt.List;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.charset.Charset;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class bestIDE_mac {
public static void main(String[] args) {
//Get Directory Path
String fvckingPath = getDir();
//Find Path
boolean foundDir = findDir(fvckingPath);
//If Path Found, parse lines
if (!foundDir) {
JOptionPane.showMessageDialog(null, "The given directory was not found.");
System.exit(1);
}
//Create a temporary file with program in it
String programPath = parseDir(fvckingPath);
//Run the program
boolean programRun = runProgram(fvckingPath, programPath);
//If error, exit
if (!programRun) {
JOptionPane.showMessageDialog(null, "Error compiling/running code.");
System.exit(1);
}
System.out.println("> Run complete!");
System.exit(0);
}
public static String getDir() {
String folderPath;
folderPath = JOptionPane.showInputDialog(null, "The flipping path");
if (folderPath.equals(null)) System.exit(1);
JOptionPane.showConfirmDialog(null, "Confirm the flipping path:\n" + folderPath);
return folderPath;
}
public static boolean findDir(String folderPath) {
try {
File folder = new File(folderPath);
System.out.println("> Finding directories at " + folderPath); //Log
return true;
} catch (Throwable e) {
return false;
}
}
public static String parseDir(String folderPath) {
System.out.println("> Now navigating to " + folderPath); //Log
File folder = new File(folderPath);
File[] listOfFiles = folder.listFiles();
//Create list of lines
ArrayList<String> programLines = new ArrayList<>();
for (File file : listOfFiles) {
if (!file.isFile()) {
String dirName = file.getName();
if (!dirName.startsWith("#")) break;
//Remove the first 3 indexes (#1 ) of directory
if (dirName.length() < 4) programLines.add("");
else programLines.add(dirName.substring(3));
}
}
//Write lines to file
try {
Path programFile = Paths.get(System.getProperty("java.io.tmpdir"), "tempFile.java");
Files.write(programFile, programLines, Charset.forName("UTF-8"));
return System.getProperty("java.io.tmpdir");
} catch (Throwable e) {
JOptionPane.showMessageDialog(null, "Error Parsing Directories.");
System.exit(1);
}
return null;
}
public static boolean runProgram(String folderPath, String programPath) {
try {
System.out.println("> Compiling and running tempFile.java"); //Log
//Create new terminal and run command
Process pro = new ProcessBuilder("/bin/bash", "-c", "osascript -e 'tell app \"Terminal\" to do script \"cd $TMPDIR && javac tempFile.java && java tempFile\"'").start();
} catch (Throwable e) {
return false;
}
return true;
}
}
import java.awt.List;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.charset.Charset;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class bestIDE {
public static void main(String[] args) {
//Get Directory Path
String fvckingPath = getDir();
//Find Path
boolean foundDir = findDir(fvckingPath);
//If Path Found, parse lines
if (!foundDir) {
JOptionPane.showMessageDialog(null, "The given directory was not found.");
System.exit(1);
}
//Create a temporary file with program in it
String programPath = parseDir(fvckingPath);
//Run the program
boolean programRun = runProgram(fvckingPath, programPath);
//If error, exit
if (!programRun) {
JOptionPane.showMessageDialog(null, "Error compiling/running code.");
System.exit(1);
}
System.out.println("> Run complete!");
System.exit(0);
}
public static String getDir() {
String folderPath;
folderPath = JOptionPane.showInputDialog(null, "The fvcking path");
if (folderPath.equals(null)) System.exit(1);
JOptionPane.showConfirmDialog(null, "Confirm the fvcking path:\n" + folderPath);
return folderPath;
}
public static boolean findDir(String folderPath) {
try {
File folder = new File(folderPath);
File[] listOfFiles = folder.listFiles();
System.out.println("> Finding directories at " + folderPath); //Log
return true;
} catch (Throwable e) {
return false;
}
}
public static String parseDir(String folderPath) {
String folderPathLast = folderPath.substring(folderPath.lastIndexOf("\\")).replace("\\", "");
System.out.println("> Now navigating to " + folderPath); //Log
File folder = new File(folderPath);
File[] listOfFiles = folder.listFiles();
//Create list of lines
ArrayList<String> programLines = new ArrayList<>();
for (File file : listOfFiles) {
if (!file.isFile()) {
String dirName = file.getName();
if (!dirName.startsWith("#")) break;
//Remove the first 3 indexes (#1 ) of directory
if (dirName.length() < 4) programLines.add("");
else programLines.add(dirName.substring(3));
}
}
for (String line : programLines) System.out.println(line);
//Write lines to file
try {
Path programFile = Paths.get(System.getProperty("java.io.tmpdir"), "tempFile.java");
Files.write(programFile, programLines, Charset.forName("UTF-8"));
return System.getProperty("java.io.tmpdir");
} catch (Throwable e) {
JOptionPane.showMessageDialog(null, "Error Parsing Directories.");
System.exit(1);
}
return null;
}
public static boolean runProgram(String folderPath, String programPath) {
try {
System.out.println("> Compiling and running tempFile.java"); //Log
//Create new command prompt and run command
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("cmd /c cd " + programPath + " & javac tempFile.java & java tempFile");
} catch (Throwable e) {
return false;
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment