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
講題:Programming Android Application in Scala. | |
講者:許洛豪(Brian Hsu) | |
講者簡介: | |
『Maidroid--用萌化的手機入侵藍星』[1] 計畫發起人,業餘 Android | |
應用程式開發及 Scala 程式語言愛好者,投稿的當下是個還在等 offer | |
的無業遊民。 |
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
<!-- 在 Lift 裡面 bind 多個 tag 的用法 --> | |
<lift:surround with="default"> | |
<lift:bind-at name="content">Here is content</lift:bind-at> | |
<lift:bind-at name="title">Here is title</lift:bind-at> | |
</lift:surround> |
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
object Test | |
{ | |
def main (args: Array[String]) { | |
val x = Map ("Hello" - > 1, | |
"Test" -> 2, | |
"HaHaHa" -> 3) | |
for ((key,value) <- x) { | |
println ("%s -> %d" format (key, value)) | |
} |
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
/** | |
* 人物卡片擁有三個屬性:名稱、生命值、描述 | |
*/ | |
case class PersonCard (name: String, description: String, hp: Int) { | |
def hasHP (hp: Int) = PersonCard (name, description, hp) | |
def describeAs (description: String) = PersonCard (name, description, hp) | |
} | |
/** | |
* 每個遊戲裡有複數張人物卡片 |
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 java.net._ | |
import java.io._ | |
import scala.io._ | |
def listenToPort (port: Int) = | |
{ | |
val address = new InetSocketAddress(InetAddress.getLocalHost, port) | |
val socket = new ServerSocket | |
socket.bind (address, 5) | |
socket |
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 bootstrap.liftweb | |
import _root_.net.liftweb.common._ | |
import _root_.net.liftweb.util._ | |
import _root_.net.liftweb.http._ | |
import _root_.net.liftweb.sitemap._ | |
import _root_.net.liftweb.sitemap.Loc._ | |
import _root_.net.liftweb.mapper._ | |
import _root_.java.sql._ | |
import org.maidroid.model.User |
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 org.maidroid.model | |
import net.liftweb.mapper._ | |
import net.liftweb.common.Empty | |
import net.liftweb.sitemap.Loc._ | |
import net.liftweb.http._ | |
import scala.xml._ | |
object Item extends Item with LongKeyedMetaMapper[Item] |
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
/** | |
* A RESTful-like URL handling Loc | |
* | |
* If you have the following templates: | |
* | |
* * webapps/item/edit.html | |
* * webapps/item/view.html | |
* | |
* You want the following URL map to corresponding template with | |
* last path component as a S parameter. |
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 scala.io.Source | |
object Main | |
{ | |
def fact (i: BigInt): BigInt = if (i == 1) return 1 else i * fact(i-1) | |
def main (args: Array[String]) { | |
val list = Source.fromInputStream(System.in).getLines. | |
toList.map(_.trim.toInt) |
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
/*================================================================================ | |
* 這邊是 Sparse Matrix 的實作 | |
*===============================================================================*/ | |
class SparseMatrix | |
{ | |
/** | |
* 這個 Sparse Matrix 我們採用 Dictionary of Keys 的作法,用一個 Map 存非零元素, | |
* Key 是 (row, col) 的 Tuple,而不是 Array[(col, row, value)]。 | |
* | |
* 這樣的作法有以下幾個好處: |
OlderNewer