Marius Soutier mariussoutier

View togglewatch.js
1 2 3 4 5 6 7 8 9 10
var toggleWatch = function(watchExpr, fn) {
var watchFn;
return function() {
if (watchFn) {
watchFn();
watchFn = undefined;
console.log("Disabled " + watchExpr);
} else {
watchFn = $scope.$watch(watchExpr, fn);
console.log("Enabled " + watchExpr);
View Callbacks.coffee
1 2 3 4 5 6 7 8 9 10
# Separate functions
success = (data, status, header) ->
promise.resolve data.user
error = (data, status, header) ->
promise.reject data.error
user = getUserById id, success, error
 
 
# Comma in front of each function
user = getUserById id
View 1Problem.scala
1 2 3 4 5 6 7 8 9
// Adding new functionality via inheritance leads to combinatorial explanation
 
abstract class Serializer {
def write(string: String): Unit
}
 
class CsvFileWriter extends FileWriter {
def writeFile(file: java.io.File) = //...
}
View JsonFormats.scala
1 2 3 4 5 6 7 8 9 10
package json
 
import reactivemongo.bson._
import reactivemongo.bson.handlers.DefaultBSONHandlers._
 
import play.api.libs.json._
import play.api.libs.json.Json._
import play.api.libs.json.util._
import play.api.libs.json.Writes._
import play.api.libs.functional.syntax._
View Twitter.scala
1 2 3 4 5 6 7 8 9 10
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 {
View Routes1
1 2 3 4 5
# 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")
View Mail.scala
1 2 3 4 5 6 7 8 9
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
View Helper.scala
1 2 3 4 5 6 7 8 9 10
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
}
View Time.scala
1 2 3 4 5 6 7
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
1 2 3 4 5 6 7 8 9
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("")
}
}
Something went wrong with that request. Please try again.