Skip to content

Commit

Permalink
Implement Scala version of the fucking-coffee script using Ammonite s…
Browse files Browse the repository at this point in the history
…hell
  • Loading branch information
amirkarimi committed Dec 7, 2015
1 parent c300bc5 commit 7d11758
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scala/fucking-coffee.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************
*
* Get and run Ammonite (http://lihaoyi.github.io/Ammonite/#Ammonite-Shell):
* $ mkdir ~/.ammonite; curl -L -o ~/.ammonite/predef.scala http://git.io/vR04f
* $ curl -L -o amm http://git.io/vR08A; chmod +x amm; ./amm
*
* Run script:
* @ load.exec("fucking-coffee.scala")
*
*******************************************/

import java.net._
import java.io._
import ammonite.ops._

val coffeeMachineIP = "10.10.42.42"
val password = "1234"
val passwordPrompt = "Password: "
val delayBeforeBrew = 17
val delay = 24

if ((%%who "-q").out.string.contains(sys.props("user.name"))) {

val telnet = new Socket(coffeeMachineIP, 23)
val out = new PrintWriter(telnet.getOutputStream, true)
val in = new BufferedReader(new InputStreamReader(telnet.getInputStream))

Thread.sleep(delayBeforeBrew * 1000);

if(in.readLine == passwordPrompt){
out.println(password)

out.println("sys brew")
Thread.sleep(delay * 1000)
out.println("sys pour")

}

out.close()
in.close()
telnet.close()

}

0 comments on commit 7d11758

Please sign in to comment.