View Time.scala
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
}
View Helper.scala
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("")
}
}
View gist:3237595
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))
}
}
View gist:1669512
UserDAO.findByEmail(email).map { user =>
Ok(views.html.edit(userForm.fill(user)))
}.getOrElse(NotFound("User not found!"))
View gist:1376684
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
}
View core.clj
;;; 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]))
View msoutier-4clojure-solution40.clj
;; msoutier's solution to Interpose a Seq
;; https://4clojure.com/problem/40
(fn [s c] (butlast (mapcat #(list %1 s) c)))
View msoutier-4clojure-solution33.clj
;; msoutier's solution to Replicate a Sequence
;; https://4clojure.com/problem/33
(fn [c n] (mapcat #(repeat n %) c))
View msoutier-4clojure-solution31.clj
;; msoutier's solution to Pack a Sequence
;; https://4clojure.com/problem/31
partition-by identity
View msoutier-4clojure-solution32.clj
;; msoutier's solution to Duplicate a Sequence
;; https://4clojure.com/problem/32
#(interleave % %)