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
| # -*- coding: utf-8 -*- | |
| class Hoge(object): | |
| def __init__(self, v): | |
| self.val = v | |
| def update(self, v): | |
| self.val = v |
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._ | |
| import Process._ | |
| class Project(info: ProjectInfo) extends DefaultProject(info) { | |
| val specs2 = "org.specs2" %% "specs2" % "1.5" % "test" | |
| val squeryl = "org.squeryl" %% "squeryl" % "0.9.4" | |
| val mysqlDriver = "mysql" % "mysql-connector-java" % "5.1.17" | |
| } |
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 main.scala | |
| import javax.servlet.http.{HttpServlet,HttpServletRequest,HttpServletResponse} | |
| import org.eclipse.jetty.server.Server | |
| import java.io.PrintWriter | |
| import java.net.URLEncoder | |
| class MongoServlet extends HttpServlet { | |
| import com.mongodb.casbah.Imports._ | |
| val conn = MongoConnection("mongo.example.dotcloud.com",5907) |
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
| // execute in REPL | |
| def testA(x:Boolean):Option[String] = if (x) Some("hoge") else None | |
| testA(true) // Option[String] = Some(hoge) | |
| testA(false) // Option[String] = None | |
| testA(false).getOrElse("moge") // String = moge | |
| testA(false).getOrElse(false) // Any = false | |
| val result = testA(false).getOrElse("moge") // String = moge |
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 AppnameProject(info: ProjectInfo) extends DefaultWebProject(info) { | |
| val JETTY7 = "7.3.1.v20110307" | |
| val servletapi = "javax.servlet" % "servlet-api" % "2.5" % "compile" | |
| val jetty7Server = "org.eclipse.jetty" % "jetty-server" % JETTY7 % "compile,test" | |
| val jetty7Servlets = "org.eclipse.jetty" % "jetty-servlets" % JETTY7 % "compile,test" | |
| val jetty7Webapp = "org.eclipse.jetty" % "jetty-webapp" % JETTY7 % "compile,test" | |
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
| <script> | |
| (function() { | |
| var def_notification_timeout=5000; | |
| var def_username = 'yoshida'; | |
| function show(msg) { | |
| var noti = webkitNotifications.createNotification( | |
| 'icon.png', | |
| 'From: my notification', |
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
| class PhpSerializer { | |
| val patternString = """s:(\d+):\"([^;]*)\";?""".r | |
| val patternInt = """i:(\d+);?""".r | |
| val patternDouble = """d:(-)?(\d+)(\.\d+)?;?""".r; | |
| val patternArray = """a:(\d+):\{(.*)\};?""".r; | |
| def parseArray(len: Int, attr: String): Any = { | |
| val childs = attr.split(";").toList | |
| val len1 = childs.length | |
| if (len1 > 1) { |
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.novus.salat._ | |
| import com.novus.salat.global._ | |
| import com.mongodb.casbah.Imports._ | |
| case class User(id: Int, name: String, age: Int) | |
| case class UserA(id: Int, name: String, age: Int) | |
| case class UserB(id: Int, name: String, salary: Int) | |
| case class Group(group_id: Int, name: String, leader: User, members: List[User]) | |
| object SalatSample { |
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._ | |
| object CasbahSample { | |
| val conn = MongoConnection() | |
| val db = conn("casbah_test") | |
| val collection = db("sample") | |
| // 下記のように1行にまとめてもでもOK | |
| // val collection = MongoConnection()("casbah_test")("sample") | |
| def createRecordAndSave { |
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 swith(fileName: String)(f: Iterator[String]=>Unit) { | |
| val in = new FileInputStream(fileName) | |
| try { | |
| f(Source.fromInputStream(in).getLines) | |
| } finally { | |
| in.close | |
| } | |
| } | |
| // 使用例 | |
| swith("foo.txt") { lines => |