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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
object Colours extends Enumeration { | |
val Red, Amber, Green = Value | |
} | |
object WeekDays extends Enumeration { | |
val Mon,Tue,Wed,Thu,Fri = 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
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
def traffic(colour: Colours.Value) = colour match { | |
case Colours.Green => "Go" | |
} | |
// Exiting paste mode, now interpreting. | |
traffic: (colour: Colours.Value)String |
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 WeekDay { | |
sealed trait EnumVal | |
case object Mon extends EnumVal | |
case object Tue extends EnumVal | |
case object Wed extends EnumVal | |
case object Thu extends EnumVal | |
case object Fri extends EnumVal | |
val daysOfWeek = Seq(Mon, Tue, Wed, Thu, Fri) | |
} |
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 SolarSystemPlanets { | |
sealed abstract class Planet( | |
val orderFromSun : Int, | |
val name : String, | |
val mass : Kilogram, | |
val radius : Meter) extends Ordered[Planet] { | |
def compare(that: Planet) = this.orderFromSun - that.orderFromSun |
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
scala> import SolarSystemPlanets._ | |
import SolarSystemPlanets._ | |
scala> println(planets) | |
TreeSet(Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune) | |
scala> EARTH < MARS | |
res1: Boolean = true | |
scala> planets.filter(_.radius > 7.0e6) |
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 code.filter | |
import javax.servlet._ | |
import http._ | |
import java.util.regex._ | |
// A wrapper around an HTTP Servlet Request which removes any /cached/:id from a URI | |
case class ResouceRequest(req: HttpServletRequest) extends HttpServletRequestWrapper(req) { | |
// The URI without the /cached/:id part: |
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 play.api.libs.json._ | |
case class Notify(email: Option[String] = None) | |
implicit val reader = Json.reads[Notify] | |
Json.parse(""" { "email": "foo@example.com" } """).asOpt[Notify] | |
// res0: Option[Notify] = Some(Notify(Some(foo@example.com))) | |
Json.parse(""" { } """).asOpt[Notify] | |
// res1: Option[Notify] = Some(Notify(None)) |
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 org.specs2._ | |
class ProblemSpec extends Specification { | |
def is = s2""" | |
Validation should | |
combine two errors into one $twoBecomeOne | |
combine error and success into error $perfectionOnly | |
combine two success into one $oneForAll | |
""" |
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
> test:console | |
scala> val f: Int => Int = _ + 1 | |
f: Int => Int = <function1> | |
scala> val g: Int => Int = _ * 13 | |
g: Int => Int = <function1> | |
scala> import scala.util._ | |
import scala.util._ |
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
<configuration> | |
<appender class="com.papertrailapp.logback.Syslog4jAppender" name="SYSLOG-TCP"> | |
<layout class="ch.qos.logback.classic.PatternLayout"> | |
<pattern>%d{MMM dd HH:mm:ss} myapp: %-5level %logger{35}: %m%n%xEx</pattern> | |
</layout> | |
<syslogConfig class="org.productivity.java.syslog4j.impl.net.tcp.TCPNetSyslogConfig"> | |
<host>${PAPERTRAIL_HOST}</host> | |
<port>${PAPERTRAIL_PORT}</port> | |
<sendLocalName>false</sendLocalName> |