Skip to content

Instantly share code, notes, and snippets.

View bwmcadams's full-sized avatar

Brendan McAdams bwmcadams

View GitHub Profile

Keybase proof

I hereby claim:

  • I am bwmcadams on github.
  • I am rit (https://keybase.io/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
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._
@bwmcadams
bwmcadams / document.scala
Created March 3, 2016 18:49 — forked from mpilquist/document.scala
Example of using scodec to decode a document of fields
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
bwmcadams / ADTAnnotationMacro.scala
Last active February 16, 2016 18:19
ADT Root Type validator, makes sure it's either a trait or abstract class *AND* sealed.
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
bwmcadams / gist:3980646
Created October 30, 2012 14:49
Casbah DSL for MongoDB Aggregation

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 }
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"
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION "/Users/brendan/code/mongodb/mongo-hadoop/hive/test";
LOAD DATA LOCAL INPATH "scores.bson" INTO TABLE scores;
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]
[error] {.}/*:hadoop-release from {.}/*:library-dependencies
[error]
[error] Use 'last' for the full log.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
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