This file contains 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 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 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 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 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 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 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 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 => |
This file contains 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
<?php | |
class HelloworldController extends AppController | |
{ | |
var $components = array( | |
'DebugKit.Toolbar' => array( | |
'xhprof' => array('configs' => array( | |
'XHPROF_ROOT' => '/var/vhosts/xhprof', // xhprof_lib,xhprof_htmlを含むディレクトリ | |
'XHPROF_SOURCE_NAME' => "helloworld", // 適当な値でOK。 | |
'XHPROF_VIEWER_DOMAIN' => 'http://xhprof.localhost', // xhprofビューアのドメイン | |
'sortBy' => 'mu' // ソートキー。指定がない場合は'wt'の降順ソート。 |
This file contains 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
# boot2docker ssh | |
# cd /Users/yoshida # mounted volume | |
# Can write text file into the vboxsf volume | |
docker@boot2docker:/Users/yoshida$ docker run -it --rm -v `pwd`:/tmp ruby:2.0 touch /tmp/foo && ls foo | |
foo | |
docker@boot2docker:/Users/yoshida$ rm ./foo | |
# Cannot write sock file into the vboxsf volume |