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 Users extends Controller with JsResultConversions with JsFormats { | |
def show(id) = Action.async { | |
api.users.get(id) | |
} | |
def update = Action.async { | |
editForm.fold(_ => Future.successful(BadRequest), api.users.save(_)) | |
} | |
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
// Zip together a couple Futures, including one that returns an Option | |
// and pass them to a function to give me a new object: | |
api.channels.tree zip api.pages.getByRoute(route) map { | |
case (tree, Some(page)) => Some(new PagePresenter(context, tree, page)) | |
case _ => None | |
} | |
// Now with an Applicative Functor! | |
(api.channels.tree |@| api.pages.getByRoute(route)) { |
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
"Delete" taggedAs(tag.RolesTag) in { | |
val request = (FakeRequest(_:String, "/admin/roles/role-bob")) andThen | |
withAdminCredentials andThen | |
(route(_:FakeRequest[AnyContentAsEmpty.type])) | |
for { result <- request(DELETE) } { | |
status(result) must equal(SEE_OTHER) | |
flash(result).data must contain key("deleted") | |
} |
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
target |
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
start = Time.now | |
100.times do | |
letter_list = [] | |
alphabet = ('a'..'z').to_a | |
100_000.times{ letter_list << alphabet[rand(26)] } | |
pick = letter_list.uniq[rand(26)] | |
before, after = letter_list.partition{|n| n > pick} | |
end | |
p (Time.now - start) * 1000 |
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 Main extends App { | |
val wordCount = "(\\w+)".r | |
.findAllIn(_:String) | |
.toSeq | |
.groupBy(_.toLowerCase) | |
.mapValues(_.size) | |
.toSeq | |
.sortBy(_._2) | |
.reverse |
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
#!/bin/sh | |
test -f ~/.sbtconfig && . ~/.sbtconfig | |
SBT_LAUNCH=/usr/local/Cellar/sbt/0.12.3/libexec/sbt-launch.jar | |
# Take leading integer as debug port and not sbt args | |
DEBUG_PORT=$1 | |
SBT_ARGS=`echo "$@" | grep -oE "[^0-9].*"` | |
exec java -Xmx512M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${DEBUG_PORT} ${SBT_OPTS} -jar $SBT_LAUNCH $SBT_ARGS |
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 play.api.mvc._ | |
import play.api.mvc.{Action => PlayAction} | |
import scala.concurrent._ | |
object Application extends Controller { | |
// Define the Type Class that will allow us to coerce our action return-types to Results. | |
trait RequestHandlerLike[-T] { | |
def apply(result: T): Result // = result | |
} |
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 API ** | |
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL ** | |
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** | |
** /____/\___/_/ |_/____/_/ | | ** | |
** |/ ** | |
\* */ | |
package scala.testing |
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 models.slick | |
import com.typesafe.config.ConfigFactory | |
object DatabaseConnection { | |
import scala.slick.driver.PostgresDriver.simple._ | |
// Note, I've got a Play-like Scala wrapper for Typesafe's Config library as well, which is a bit cleaner than this. | |
implicit lazy val database = ConfigFactory.load("conf/database.conf").getConfig("db.default") match { case config => | |
Database.forURL( |