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 scala.util.control.NoStackTrace | |
| package object FlatFuture { | |
| case object EmptyOption extends RuntimeException("Current option is empty :'(") with NoStackTrace | |
| implicit final class futureOfOptionToFuture[A](future: Future[Option[A]]) { | |
| def flatten(implicit ec: ExecutionContext): Future[A] = { | |
| future.flatMap { | |
| case Some(something) => Future.successful(something) |
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 controllers | |
| import play.api.mvc.{Action, Controller} | |
| import play.api.libs.iteratee.{Enumeratee, Enumerator, Concurrent} | |
| import play.api.libs.ws.WS.WSRequestHolder | |
| import play.api.http.{ContentTypeOf, Writeable} | |
| import play.api.libs.ws.WS | |
| import java.net.URLEncoder | |
| import play.api.libs.oauth.OAuthCalculator | |
| import play.api.libs.json.{JsValue, Json} |
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
| /* | |
| * The MIT License (MIT) | |
| * | |
| * Copyright (c) 2013 Association du Paris Java User Group. | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy of | |
| * this software and associated documentation files (the "Software"), to deal in | |
| * the Software without restriction, including without limitation the rights to | |
| * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | |
| * the Software, and to permit persons to whom the Software is furnished to do so, |
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
| trait FormUtils { | |
| def FormAction(form: Form[User])(block: (User) => SimpleResult): EssentialAction = { | |
| Action { request => | |
| form.bindFromRequest()(request).fold( | |
| errors => BadRequest(errors), | |
| user => block(user) | |
| ) | |
| } | |
| } | |
| } |
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
| public static ReactiveCouchbaseDriver driver = ReactiveCouchbaseDriver.apply(); | |
| public static org.reactivecouchbase.play.java.CouchbaseBucket getBucket(String name) throws Exception { | |
| org.reactivecouchbase.CouchbaseBucket scalaBucket = driver.bucket(name); | |
| Class<org.reactivecouchbase.play.java.CouchbaseBucket> clazz = org.reactivecouchbase.play.java.CouchbaseBucket.class; | |
| Constructor<?> constructor = Arrays.asList(clazz.getDeclaredConstructors()).iterator().next(); | |
| constructor.setAccessible(true); | |
| return (org.reactivecouchbase.play.java.CouchbaseBucket) constructor.newInstance(scalaBucket); | |
| } |
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
| case class MyData(uData: String, otherData: String) | |
| object Application1 extends App { | |
| // get a driver instance driver | |
| val driver = ReactiveCouchbaseDriver() | |
| // get the default bucket | |
| val bucket = driver.bucket("default") | |
| implicit val fmt = Json.format[MyData] |
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 Application extends Controller { | |
| def bucket = Couchbase.cappedBucket("default", 100) | |
| def data = Action.async { | |
| import org.ancelin.play2.couchbase.CouchbaseRWImplicits.documentAsJsObjectReader | |
| val enumerator = bucket.tail[JsObject]() | |
| enumerator.map( Ok.chunked( _ ) ) | |
| } |
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 controllers | |
| import play.api.mvc.{Controller, Action} | |
| import org.ancelin.play2.couchbase.Couchbase | |
| import org.ancelin.play2.couchbase.CouchbaseRWImplicits.jsObjectToDocumentWriter | |
| import org.ancelin.play2.couchbase.CouchbaseRWImplicits.documentAsJsValuetReader | |
| import play.api.libs.json._ | |
| import play.api.libs.EventSource |
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 elevator | |
| import akka.actor.{ ActorSystem } | |
| import akka.agent.Agent | |
| import akka.util.Timeout | |
| import java.util.concurrent.{TimeUnit} | |
| import scala.concurrent.duration.Duration | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| case class SmartElevator( |
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
| CouchbaseClient client = new CouchbaseClient(hosts, bucket, password); | |
| client.set("my-first-document", "Hello Couchbase!").get(); | |
| client.get("my-first-document").get(); |