Skip to content

Instantly share code, notes, and snippets.

@teigen
Created December 29, 2009 16:47
Show Gist options
  • Save teigen/265420 to your computer and use it in GitHub Desktop.
Save teigen/265420 to your computer and use it in GitHub Desktop.
/*
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public License, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
Uses "http://www.hilite.me/api"
stdin: cat hilite.scala | scala hilite.scala
file: scala hilite.scala hilite.scala
expression: scala hilite.scala "val hello = \"Hello World\""
*/
import scala.io.Source
import java.net.{URL, HttpURLConnection}
import java.io.File
import java.net.URLEncoder.encode
val code = args match {
case Array() => Source.stdin.mkString
case Array(path) if(new File(path).isFile) => Source.fromPath(path).mkString
case Array(expr) => expr
case _ =>
Console.err.println("accepts single argument file/expression or data from stdin")
exit(1)
}
val c = new URL("http://www.hilite.me/api").openConnection().asInstanceOf[HttpURLConnection]
c.setRequestMethod("POST")
c.setDoOutput(true)
c.getOutputStream.write(("lexer=scala&code="+encode(code.mkString, "UTF-8")).getBytes)
Source.fromInputStream(c.getInputStream).getLines().foreach(println)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment