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_2.10.0-M1 -Xexperimental | |
| Welcome to Scala version 2.10.0-M1 (Java HotSpot(TM) Client VM, Java 1.6.0_18). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> val name = "Martin" | |
| name: String = Martin | |
| scala> val intro = s"My name is $name" | |
| intro: String = My name is Martin |
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> ??? | |
| scala.NotImplementedError: an implementation is missing | |
| at scala.Predef$.$qmark$qmark$qmark(Predef.scala:233) | |
| at .<init>(<console>:8) | |
| at .<clinit>(<console>) | |
| at .<init>(<console>:11) | |
| at .<clinit>(<console>) | |
| at $print(<console>) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) |
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> "ss".isInstanceOf[Any] | |
| res3: Boolean = true | |
| scala> "ss".isInstanceOf[AnyVal] | |
| <console>:8: error: type AnyVal cannot be used in a type pattern or isInstanceOf test | |
| "ss".isInstanceOf[AnyVal] | |
| ^ | |
| scala> |
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
| scalaVersion := "2.9.1" | |
| resolvers += "typesafe" at "http://repo.typesafe.com/typesafe/releases" | |
| libraryDependencies ++= Seq( | |
| "play" %% "anorm" % "2.0-RC4", | |
| "com.github.seratch" %% "scalikejdbc" % "[0.5,)", | |
| "org.hsqldb" % "hsqldb" % "[2,)" | |
| ) |
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 example.threadlocal; | |
| import com.sun.jersey.api.representation.Form; | |
| public class ThreadLocalForm { | |
| private static final ThreadLocal<Form> THREAD_LOCAL = new ThreadLocal<Form>(); | |
| public static void set(Form value) { | |
| THREAD_LOCAL.set(value); |
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://en.wikipedia.org/wiki/Monty_Hall_problem | |
| // http://d.hatena.ne.jp/hiratara/20120330/1333122309 | |
| import scala.util.Random._ | |
| case class Door(index: Int, isCar: Boolean) | |
| def chooseDoor(doors: Seq[Door]): Door = doors(nextInt(doors.size)) | |
| object MontyHall { |
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
| // Comment to get more information during initialization | |
| logLevel := Level.Warn | |
| // The Typesafe repository | |
| resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | |
| // Use the Play sbt plugin for Play projects | |
| addSbtPlugin("play" % "sbt-plugin" % "2.0") | |
| resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/" |
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.io._ | |
| val bao = new ByteArrayOutputStream | |
| val dos = new DataOutputStream(bao) | |
| val chank64kMinus1 = new StringBuilder | |
| val limit = 1024 * 64 - 1 | |
| 1 to limit foreach { _ => chank64kMinus1.append("a") } | |
| dos.writeUTF(chank64kMinus1.toString) | |
| println(limit + " bytes is acceptable.") |
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.api._ | |
| import play.api.mvc._ | |
| import scalikejdbc._ | |
| object Application extends Controller { | |
| def index = Action { |
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
| #!/usr/bin/env ruby | |
| require "net/https" | |
| require "uri" | |
| API_BASE_URL = "https://api.twitter.com/1" | |
| def get(url) | |
| uri = URI.parse(url) | |
| https = Net::HTTP.new(uri.host, uri.port) |