Skip to content

Instantly share code, notes, and snippets.

View ctcarrier's full-sized avatar

Chris Carrier ctcarrier

  • Stateless Solutions
  • Detroit, MI
View GitHub Profile
trait BlPathMatchers {
val BSONObjectID: PathMatcher1[BSONObjectID] =
PathMatcher("""[\da-fA-F]""".r) flatMap { string ⇒
try Some(new BSONObjectID(string))
catch { case _: IllegalArgumentException ⇒ None }
}
}
@ctcarrier
ctcarrier / gist:9918087
Created April 1, 2014 16:48
Joda DateTime Serializer for ReactiveMongo
import reactivemongo.bson.{BSONHandler, BSONDateTime, Macros}
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{DateTime, DateTimeZone}
package object myApp {
DateTimeZone.setDefault(DateTimeZone.UTC)
implicit object BSONDateTimeHandler extends BSONHandler[BSONDateTime, DateTime] {
val fmt = ISODateTimeFormat.dateTime()
def read(time: BSONDateTime) = new DateTime(time.value)
@ctcarrier
ctcarrier / gist:11348157
Created April 27, 2014 15:17
ReactiveMongoConnection
class ReactiveMongoConnection extends Module {
import ExecutionContext.Implicits.global
private val config = ConfigFactory.load()
implicit val context = inject[ActorSystem]
val driver = new MongoDriver
val pattern = "^mongodb:\\/\\/([\\w]*):([\\w]*)@([\\w\\.-]+):([\\d]+)\\/([\\w]+)".r
val envUri = Properties.envOrElse("MONGOLAB_URI", "").toString