Skip to content

Instantly share code, notes, and snippets.

@ziplokk1
Last active June 1, 2020 18:28
Show Gist options
  • Save ziplokk1/10024647 to your computer and use it in GitHub Desktop.
Save ziplokk1/10024647 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.Random;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class Sublime {
private Date time;
private boolean isSmokingTwoJoints = false;
private Runnable smoke = new Runnable() {
@Override
public void run() {
isSmokingTwoJoints = true;
for(int i = 0; i < 2; i++) {
Joint joint = new Joint();
while(!joint.isCashed()) {
joint.takePuff();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
System.out.println("Something is harshing your mellow.");
}
}
}
isSmokingTwoJoints = false;
}
};
public static void main(String[] args) {
Sublime sublime = new Sublime();
sublime.startSmoking();
}
public Sublime() {
time = new Date();
}
public void startSmoking() {
smokeTwoJoints(); //Smoke two joints before smoking two joints
if(isMorning()) {
//System.out.println("Morning");
smokeTwoJoints();
}
if(isNight()) {
//System.out.println("Night");
smokeTwoJoints();
}
if(isAfternoon()) {
//System.out.println("Afternoon");
smokeTwoJoints();
}
if(isTimeOfPeace()) {
//System.out.println("Peace");
smokeTwoJoints();
}
if(isTimeOfWar()) {
//System.out.println("War");
smokeTwoJoints();
}
if(isSmokingTwoJoints) {
smokeTwoJoints();
}
smokeTwoJoints(); //And then smoke two more
}
private boolean isMorning() {
return time.getHours() < 12 && time.getHours() >= 8;
}
private boolean isNight() {
return time.getHours() > 18 && time.getHours() < 11 || time.getHours() >= 0 && time.getHours() < 8;
}
private boolean isAfternoon() {
return time.getHours() >= 12 && time.getHours() <= 18;
}
public void smokeTwoJoints() {
smoke.run();
}
public boolean isTimeOfPeace() {
return !getThreatLevel();
}
public boolean isTimeOfWar() {
return getThreatLevel();
}
private boolean getThreatLevel() {
final String feed = "http://www.dhs.gov/ntas/1.0/feed.xml";
final String testFeed = "http://www.dhs.gov/ntas/1.0/sample-feed.xml";
String threatLevel;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
Document doc = null;
try {
db = dbf.newDocumentBuilder();
doc = db.parse(new URL(feed).openStream());
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
threatLevel = doc.getElementsByTagName("alert").item(0).getAttributes().getNamedItem("type").getNodeValue();
} catch (NullPointerException e) {
threatLevel = "No Threat";
}
switch(threatLevel) {
case "No Threat":
return false;
case "Imminent Threat":
return true;
case "Elevated Threat":
return true;
}
return false;
}
}
class Joint {
private int ganj_remaining = 100;
public void takePuff() {
Random r = new Random();
ganj_remaining -= r.nextInt(15);
if(r.nextBoolean()) {
System.out.println("Puff");
} else {
System.out.println("Puff *cough*");
}
}
public boolean isCashed() {
return ganj_remaining < 10;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment