Skip to content

Instantly share code, notes, and snippets.

@bluebear94
Created August 27, 2014 02:28
Show Gist options
  • Save bluebear94/4f50ca16a986b07f91cd to your computer and use it in GitHub Desktop.
Save bluebear94/4f50ca16a986b07f91cd to your computer and use it in GitHub Desktop.
Determines whether you're Steve or Alex.
import java.util.UUID
import scala.io.Source
object SteveOrAlex {
def main(args: Array[String]) {
val name = args(0)
println(s"Stats for $name")
val theID = uuid(name)
println(s"UUID: $theID")
val hash = theID.hashCode
println(s"Hash: $hash")
println("You're a" + (if (hash % 2 == 0) " Steve" else "n Alex"))
}
def uuid(s: String): UUID = {
try {
UUID.fromString(s.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"))
} catch {
case _: Exception => {
val src = Source.fromURL("https://api.mojang.com/users/profiles/minecraft/" + s)
val lines = src.getLines
val firstLine = lines.next
println(s"firstLine = $firstLine")
uuid(firstLine.substring(7, 39))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment