Skip to content

Instantly share code, notes, and snippets.


Keybase proof

I hereby claim:

  • I am bwmcadams on github.
  • I am rit ( on keybase.
  • I have a public key whose fingerprint is 4419 19F1 1211 E233 F91E 03AA DD35 5DFB C6DD E69E

To claim this, I am signing this object:

bwmcadams / Controller.scala
Created Nov 29, 2011
Play 2.0 Scala + MongoDB via Salat
View Controller.scala
package controllers
import play.api._
import play.api.mvc._
import com.novus.salat._
import com.novus.salat.dao._
import util._
bwmcadams / document.scala
Created Mar 3, 2016 — forked from mpilquist/document.scala
Example of using scodec to decode a document of fields
View document.scala
package foo
import scodec.bits._
import scodec._
import scodec.codecs._
case class Document(fields: Vector[(String, Field)])
sealed trait Field
case class IntField(value: Int) extends Field
bwmcadams / ADTAnnotationMacro.scala
Last active Feb 16, 2016
ADT Root Type validator, makes sure it's either a trait or abstract class *AND* sealed.
View ADTAnnotationMacro.scala
package codes.bytes.macros_intro.macros
import scala.annotation.{ compileTimeOnly, StaticAnnotation }
import scala.language.postfixOps
import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
object ADT {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
bwmcadams / gist:3980646
Created Oct 30, 2012
Casbah DSL for MongoDB Aggregation
View gist:3980646

I'm interested in community input, as I'm finally finishing adding support to Casbah's Query DSL for MongoDB Aggregation.

The trick is to try to prevent accidental usage of the aggregation syntax for queries, and check statements as cleanly as possible.

There are a few ways to go about this, and some concerns with each. My current favorite looks a bit like this:

(scroll over to see the whole thing)

val agg = | $group { ("lastAuthor" $last "$author") ++ ("firstAuthor" $first "$author")  ++ ("_id" -> "$foo") } $unwind "$tags" $sort ( "foo" -> 1, "bar" -> -1 ) $skip 5 $limit 10 $match { "score" $gt 50 $lte 90 }
View gist:2943236
CREATE EXTERNAL TABLE scores ( student int, name string, score int )
ROW FORMAT SERDE "com.mongodb.hadoop.hive.BSONSerde"
STORED AS INPUTFORMAT "com.mongodb.hadoop.hive.input.BSONFileInputFormat"
LOCATION "/Users/brendan/code/mongodb/mongo-hadoop/hive/test";
View error.txt
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? r
[info] Loading global plugins from /Users/brendan/.sbt/plugins
[info] Loading project definition from /Users/brendan/code/mongodb/mongo-hadoop/project
[info] Compiling 1 Scala source to /Users/brendan/code/mongodb/mongo-hadoop/project/target/scala-2.9.1/sbt-0.11.2/classes...
[error] Reference to undefined setting:
[error] {.}/*:hadoop-release from {.}/*:library-dependencies
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
View gist:1732431
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
View gist:1708358
[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 / ls
Created Dec 9, 2011
Scripts to setup Pip and Nose on new binary Python builds
View ls
[bamboo@bamboo-agent1 python2]$ ls r2.4.6 r2.5.6 r2.6.7 r2.7.2