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
| # create database 'foo' | |
| % mysqladmin -u root create foo | |
| # give full privileges to user 'maiha' | |
| % mysql -u root | |
| mysql> grant all on foo.* to maiha; | |
| # reload role tables | |
| % mysqladmin -u root reload |
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://www.playframework.org/documentation/1.1-trunk/firstapp | |
| package controllers | |
| import play.mvc._ | |
| import play.data.validation._ // @Required | |
| object Hello extends Controller { | |
| def index = render() |
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 login_required(email: String, password: String) { | |
| User.find("byEmail", email).first match { | |
| case u:User if u.password == password => | |
| session.put("user", u.email) | |
| Application.index | |
| case u:User => render("reminder", u.email) | |
| case _ => access_denied | |
| } | |
| } |
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 Hello extends Controller { | |
| def index { | |
| val user_count = User.count | |
| render(user_count) | |
| } | |
| } |
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 controllers | |
| import play.mvc._ | |
| case class Item(name: String) | |
| object Sig extends Controller { | |
| // OK "/sig/index1?name=foo" => name is "foo" (@render) | |
| def index1(name: String) = stub_item match { |
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 cassandra._ | |
| val storage = Storage() | |
| // => storage: cassandra.Storage = cassandra.Storage@cabe02e | |
| storage("key") // => "" | |
| storage("key") = "aho" // Unit | |
| storage("key") // => "aho" | |
| storage("key:field") // => "" |
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 bench(code: => Any, times: Int = 1) { | |
| val start = System.nanoTime | |
| for(_ <- 1 to times) code | |
| println(format("%.4f", (System.nanoTime - start)/1000000000.0)) | |
| } | |
| scala> bench( 1+1 ) | |
| 0.0000 | |
| scala> bench( 1+1, 10000) |
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
| [OK] | |
| def sum(a:Int,b:Int) = a+b | |
| [NG] | |
| def sum(a:Int,b:Int) = a+b | |
| def sum(a:Int,b:String) = sum(a, b.toInt) | |
| // (compile error) | |
| // overloaded method sum needs result type | |
| // def sum(a:Int,b:String) = sum(a, b.toInt) |
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
| <Keyspace Name="Test"> | |
| <ColumnFamily Name="Aho1" /> | |
| <ColumnFamily Name="Aho2" /> | |
| <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy> | |
| <ReplicationFactor>1</ReplicationFactor> | |
| <EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch> | |
| </Keyspace> | |
| <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrat\ | |
| egy> |
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 ascii { | |
| def a: PartialFunction[String, Int] = { case "a" => 97 } | |
| def b: PartialFunction[String, Int] = { case "b" => 98 } | |
| def ab = a orElse b | |
| } | |
| ascii.a("a") => 97 | |
| ascii.a("b") // scala.MatchError: b | |
| ascii.ab("a") => 97 | |
| ascii.ab("b") => 98 |