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
@ctcarrier
ctcarrier / ReactiveMongoRandomDocument
Created December 16, 2013 04:22
Select a random document using
import reactivemongo.bson.BSONDocument
import reactivemongo.api.collections.default.BSONCollection
import reactivemongo.api.{QueryOpts, DB}
import reactivemongo.core.commands.Count
import reactivemongo.api.collections.default._
def getDocument(collection: BSONCollection): Future[Option[YourClass]] = {
val futureCount = db.command(Count(collection.name))
futureCount.flatMap { count =>
val skip = Random.nextInt(count)
@ctcarrier
ctcarrier / serviceTest1
Created April 23, 2012 16:09
Gatling scenario
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import scala.util.Random
import com.excilys.ebi.gatling.core.feeder.Feeder
class ServiceSimulation extends Simulation {
def apply = {
val random = new Random
random.setSeed(System.currentTimeMillis)
@ctcarrier
ctcarrier / spray_lift_json
Created October 20, 2011 04:32
Spray lift-json support
implicit def liftJsonUnmarshaller[A :Manifest] = new UnmarshallerBase[A] {
val canUnmarshalFrom = ContentTypeRange(`application/json`) :: Nil
def unmarshal(content: HttpContent) = protect {
val jsonSource = DefaultUnmarshallers.StringUnmarshaller.unmarshal(content).right.get
parse(jsonSource).extract[A]
}
}
implicit def liftJsonMarshaller[A <: AnyRef] = new MarshallerBase[A] {
val canMarshalTo = ContentType(`application/json`) :: Nil