This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Translate extends Dynamic{ | |
import scala.util.parsing.json.JSON | |
type ReturnJsonType = Map[String,Map[String,List[Map[String,String]]]] | |
private val url = "https://www.googleapis.com/language/translate/v2?" + | |
"key=自分のキー&source=" + | |
( _:String ) + "&target=" + (_:String) + "&q=" + java.net.URLEncoder.encode( _:String,"UTF-8") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.control.Exception._ | |
object Main{ | |
//Stringに対して、 toIntOptというメソッドを追加したように見せかけるためのimplicit def | |
//Intに変換できたらSome[Int]を返し、変換できないフォーマットならばNoneを返す | |
implicit def superRichString(i:String) = | |
new { def toIntOpt:Option[Int] = catching(classOf[NumberFormatException]).opt{i.toInt} } | |
def main(args:Array[String]){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://d.hatena.ne.jp/yuroyoro/20110527/1306496377 を使う | |
val keywords = Seq( | |
"abstract", | |
"case", | |
"catch", | |
"class", | |
"def", | |
"do", | |
"else", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 折れ線グラフをScalaで出力しようとして、作りかけ(?)のもの | |
case class C[A](x:A,y:A) | |
case class LineGraph(dataAndLavel:List[(String,Int)],width:Double = 1000,height:Double = 800,color:String){ | |
implicit def anyToString(obj:Any):String = obj.toString | |
def toXML:xml.Elem = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_20). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> object A{ | |
| trait B{ | |
| override def toString = "trait" | |
| } | |
| | |
| object B{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt._ | |
class Test(info: ProjectInfo) extends DefaultWebProject(info) | |
{ | |
val casbah = "com.mongodb.casbah" % "casbah_2.8.1" % "2.1.5.0" | |
val scalaTime = "org.scala-tools.time" % "time_2.8.0" % "0.3" | |
val liftjson = "net.liftweb" % "lift-json_2.8.1" % "2.3" | |
val servletapi = "javax.servlet" % "servlet-api" % "2.5" | |
val jetty7 = "org.eclipse.jetty" % "jetty-webapp" % "7.0.2.RC0" % "test" | |
val scalatra = "org.scalatra" % "scalatra_2.8.1" % "2.0.0.M3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sortTest{ | |
val list = List(1,8,3,5,0) | |
println( list.sorted ) //List(0, 1, 3, 5, 8) | |
implicit val ascOrdering = new Ordering[Int]{ | |
def compare(x:Int,y:Int) = if( x > y ) -1 else if( x < y) +1 else 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.casbah.Imports._ | |
import com.mongodb.casbah.dynamic._ | |
val db = MongoConnection("IPアドレスとか")("データベース名") | |
val col = db("コレクション名") | |
implicit def dynamicConverter(obj:DBObject) = new { | |
def toDynamic = DynamicDBObject.empty ++= obj | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package shibuyascala | |
import org.scalatra.ScalatraFilter | |
import net.liftweb.json._ | |
import net.liftweb.json.JsonDSL._ | |
class Main extends ScalatraFilter{ | |
val jsonToString = render _ andThen compact _ | |
val atndUrls = List( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Point | |
object Test1{ | |
implicit def toRichPoint(p:Point) = new RichPoint(p.x,p.y) | |
class RichPoint(x:Int,y:Int){ | |
def +(other:Point) = new Point( this.x + other.x , this.y + other.y ) |