Upload
yung-luen-lan
View
738
Download
2
Tags:
Embed Size (px)
Citation preview
Scala Bot for Small Businessyllan @ ScalaConf.jpMarch 2, 2013
Who Am I?
藍永倫 @yllan
Working at Hypo (http://hypo.cc)
Scala 下忍(⾃自称)しもおし
Why am I here?初心者
Scala:Scalable Language
Scala:Scalable Language
拡大縮小が可能なさま。拡張性があるさま。Able to be changed in size or scale.
scale-UP & scale-OUT
scale-down & scale-in?
Scala is good at BIG.
大 > 小BIG > small
Scala is good at small?
RUBY SCALA
A lot of small business!
Right Toolfor
Automation
Scala for script? Hmm…
Cons for scala scripting
Cons for scala scripting
Slow compile
Cons for scala scripting
Slow compile
scala -savecompiled script.scala
Cons for scala scripting
Slow compile
scala -savecompiled script.scala
Hard to memorize classpath
Cons for scala scripting
Slow compile
scala -savecompiled script.scala
Hard to memorize classpath
JVM boot overhead
Cons for scala scripting
Slow compile
scala -savecompiled script.scala
Hard to memorize classpath
JVM boot overhead
nailgun? Hmmm
Cons for scala scripting
Slow compile
scala -savecompiled script.scala
Hard to memorize classpath
JVM boot overhead
nailgun? Hmmm
Default I/O library
Recommended lib
rapture.io (http://rapture.io)
File / "home" / "work" / "contents" > Socket("localhost", Services.Tcp.telnet)
dispatch (http://dispatch.databinder.net/)
val svc = url("http://hostip.info/country.php")val country = Http(svc OK as.String)
TIPSScala REPL comes to rescue!:cp - add a jar/dir to classpath
:load - load a scala file
:shscala> :sh find . -name *.mres0: s.t.n.i.ProcessResult = `find . -name *.m` (23 lines, exit 0)scala> res0.exitCoderes1: Int = 0scala> res0.linesres2: List[String] = List(...)
import scala.sys.process._
I ♡ scala REPL!
For non-geek?
SHIT HAPPENS.
DANGEROUS!
Only permit trained people use the guns; or
Make your gun super safe.
Solutions
Take our company as example…
“Make gun safe” strategy works?
Too many system!
Let the trained people do.
COLLEAGUE MEIM RUN
SCRIPT
COLLEAGUE BOTIM RUN
SCRIPT
IM
XMPP
AIM
Google Talk
Facebook Messenger
Smack Library (http://www.igniterealtime.org/projects/smack/)
Command Parsing
Regex + extractor
Every command is a PartialFunction
Happy!
That’s my little story about scala.
Q & A