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
;;; Conway's Game of Life | |
;;; Using a set of coordinates to provide a infinite world | |
;;; | |
;;; Moritz Ulrich <ulrich.moritz@googlemail.com> | |
;;; Cologne Clojure User Group | |
;;; November 17, 2011 | |
(ns game-of-life.core | |
(:use [clojure.set :as set])) |
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 keeponlyalive | |
/** A cell that exists is alive */ | |
case class Cell(x: Int, y: Int) { | |
def survives(implicit world: Set[Cell]) = neighborCount(world) match { | |
case 2 => true | |
case 3 => true | |
case _ => false | |
} | |
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
UserDAO.findByEmail(email).map { user => | |
Ok(views.html.edit(userForm.fill(user))) | |
}.getOrElse(NotFound("User not found!")) |
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 views.html.helper | |
import play.api.templates.Html | |
object repeatWithIndex { | |
def apply(field: play.api.data.Field, min: Int = 1)(f: (play.api.data.Field, Int) => Html) = { | |
(0 until math.max(if (field.indexes.isEmpty) 0 else field.indexes.max + 1, min)).map(i => f(field("[" + i + "]"), i)) | |
} | |
} |
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 views.html.helper | |
import play.api.templates.Html | |
object definingNonEmpty { | |
def apply[T <: Seq[_]](t: T)(block: (T) => Html) = { | |
if (t.nonEmpty) block(t) else Html("") | |
} | |
} |
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
def time[T](block: => T): T = { | |
val start = System.currentTimeMillis | |
val res = block | |
val totalTime = System.currentTimeMillis - start | |
println("Elapsed time: %1d ms".format(totalTime)) | |
res | |
} |
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 views.html.helper | |
import play.api.templates.Html | |
// Executes the first block if non-empty, the second otherwise | |
// Passes the entire seq (as in defining) | |
object ifEmptyOrElse { | |
def apply[T <: Seq[_]](t: T)(nonEmptyBlock: (T) => Html)(emptyBlock: => Html) = { | |
if (t.nonEmpty) nonEmptyBlock(t) else emptyBlock | |
} |
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 object mail { | |
implicit def stringToSeq(single: String): Seq[String] = Seq(single) | |
implicit def liftToOption[T](t: T): Option[T] = Some(t) | |
sealed abstract class MailType | |
case object Plain extends MailType | |
case object Rich extends MailType | |
case object MultiPart extends MailType |
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
# Map to language via RegEx | |
/$language<[a-z]{2}>/videos/:id controllers.Video.showVideo(id: Long, language: String) | |
# Hard-code supported languages | |
/de/videos/:id controllers.Video.showVideo(id: Long, language = "de") | |
/en/videos/:id controllers.Video.showVideo(id: Long, language = "en") |
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 controllers | |
import play.api._ | |
import play.api.mvc._ | |
import play.api.libs.oauth._ | |
import play.api.libs.ws._ | |
import play.api.libs.iteratee._ | |
object Twitter extends Controller { |