Skip to content

Instantly share code, notes, and snippets.

View bwmcadams's full-sized avatar

Brendan McAdams bwmcadams

View GitHub Profile
val encoder = new com.mongodb.DefaultDBEncoder()
def encode(doc: DBObject): Long = {
encoder.synchronized {
val start = System.currentTimeMillis()
val encoded = encoder.encode(doc)
val end = System.currentTimeMillis()
end - start
}
}
DeregisterConversionHelpers()
[error] /Users/brendan/code/mongodb/casbah/casbah-query/src/main/scala/Implicits.scala:151: not found: type scala
[error] @annotation.implicitNotFound("${A} is not a valid query parameter")
[error] ^
[error] /Users/brendan/code/mongodb/casbah/casbah-query/src/main/scala/Implicits.scala:151: not found: type scala
[error] @annotation.implicitNotFound("${A} is not a valid query parameter")
[error] ^
[error] one error found
[error] one error found
[error] {file:/Users/brendan/code/mongodb/casbah/}casbah-query/compile:doc: Scaladoc generation failed
[error] {file:/Users/brendan/code/mongodb/casbah/}casbah-query/compile:compile: Compilation failed
@bwmcadams
bwmcadams / ls
Created December 9, 2011 22:28
Scripts to setup Pip and Nose on new binary Python builds
[bamboo@bamboo-agent1 python2]$ ls
nosify.sh pip_me.sh r2.4.6 r2.5.6 r2.6.7 r2.7.2
@bwmcadams
bwmcadams / Controller.scala
Created November 29, 2011 19:48
Play 2.0 Scala + MongoDB via Salat
package controllers
import play.api._
import play.api.mvc._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
import util._
trait JodaDateTimePrimitive extends BSONDatePrimitive[DateTime] {
def rawValue(bson: Long): DateTime = {
new DateTime(bson)
}
def bsonValue(raw: DateTime): Long = {
raw.getMillis
}
}
implicit def kvPairAsDBObject[A <: Any](kv: (String, A)): DBObject = MongoDBObject(kv)
sealed class NestedListOper(outerField: String) {
def apply[A <% DBObject](fields: A*): DBObject = {
val b = Seq.newBuilder[DBObject]
fields.foreach(x => b += x)
MongoDBObject(outerField -> b.result())
}
}
/* I'm trying to refactor $and and $or (which are essentially the same code returning a different outer query).
The problem is that currently only "String, Any" pairs work, and I need to be able to combine both those *AND* "Query Expression Objects".
Here's the $or spec right now
*/
"Casbah's DSL $or Operator" should {
"Accept multiple values" in {
val or = $or("foo" -> "bar", "x" -> "y")
@bwmcadams
bwmcadams / Current$OR.Scala
Created November 6, 2011 21:45
Casbah Query DSL Issues
/**
* Trait to provide the $or method as a bareword operator.
*
* $or ("Foo" -> "bar")
*
* Targets an RValue of (String, Any)* to be converted to a DBObject
*
* TODO - Test that rvalue ends up being an array e.g.:
*
* scala> $or ("foo" -> "bar", "X" -> 5)
# note that I see *EXACT* same results as the original post with the original code.
# The fix below makes that not happen anymore (use snapshot mode)
# mongo.jar on my machine is the shipped version of 2.7.0, so same exact Java Driver of original test
# ( I was lead on the 2.7.0 release and did the build/release )
b-mac mongodb/mongo-java-driver ‹master*› » scala -cp mongo.jar Repro.scala
Inserting canary...
Inserting test data...
Paging through records...
Spotted the canary!
Updating canary object...
@bwmcadams
bwmcadams / ast_parser_combinator.scala
Created October 13, 2011 15:26
AST Parsing Combinator
import scala.util.parsing.combinator._
trait RunParser {
this: RegexParsers =>
type RootType
def root: Parser[RootType]
def run(in: String): ParseResult[RootType] = parseAll(root, in)
}
case class Variable(name: String)