Skip to content

Instantly share code, notes, and snippets.

View ctcarrier's full-sized avatar

Chris Carrier ctcarrier

View GitHub Profile
ctcarrier / gist:11348157
Created April 27, 2014 15:17
class ReactiveMongoConnection extends Module {
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
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 {
implicit object BSONDateTimeHandler extends BSONHandler[BSONDateTime, DateTime] {
val fmt = ISODateTimeFormat.dateTime()
def read(time: BSONDateTime) = new DateTime(time.value)
trait BlPathMatchers {
val BSONObjectID: PathMatcher1[BSONObjectID] =
PathMatcher("""[\da-fA-F]""".r) flatMap { string ⇒
try Some(new BSONObjectID(string))
catch { case _: IllegalArgumentException ⇒ None }
private BallHttpClient<Ball> httpClient = new BallHttpClient<Ball>(SCHEME, HOST, PORT){
public ResponseHandler<Ball> createResponseHandler() {
return new ResponseHandler<Ball>(){
public Ball handleResponse(HttpResponse resp)
throws ClientProtocolException, IOException, NoResourceFoundException, ErrorAccessingResourceException {
return gson.fromJson(new InputStreamReader(resp.getEntity().getContent()), Ball.class);
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
BallHttpClient<Ball> httpClient = new GenericHttpClient<Ball>(SCHEME, HOST, PORT);
ctcarrier /
Last active January 1, 2016 17:29
Generic Android Http Client
import android.util.Base64;
import android.util.Log;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
ctcarrier / ImageDirectoryDao.scala
Created December 17, 2013 23:51
Basic ReactiveMongo DAO
package com.blrest.dao
import scala.concurrent.Future
import reactivemongo.bson.BSONDocument
import reactivemongo.api.{QueryOpts, DB}
import reactivemongo.core.commands.Count
import reactivemongo.api.collections.default._
ctcarrier / package.scala
Created December 17, 2013 23:40
User of ReactiveMongo macros
package com
import reactivemongo.bson.{Macros, BSONDocument, BSONDocumentReader}
import com.blrest.model.{FlickrData, ImageMeta}
* Created by ccarrier for bl-rest.
* at 3:19 PM on 12/15/13
package object blrest {
ctcarrier / gist:7989957
Created December 16, 2013 16:33
Scala regex pattern to extract MongoDB connection info
scala> "mongodb://"
res7: String = mongodb://
scala> val pattern = "^mongodb:\\/\\/([\\w]+):([\\w]+)@([\\w\\.]+):([\\d]+)\\/([\\w]+)".r
pattern: scala.util.matching.Regex = ^mongodb:\/\/([\w]+):([\w]+)@([\w\.]+):([\d]+)\/([\w]+)
scala> val pattern(user, password, host, port, db) = res7
user: String = dbuser
password: String = dbpassword
host: String =