Skip to content

Instantly share code, notes, and snippets.

View bwmcadams's full-sized avatar

Brendan McAdams bwmcadams

View GitHub Profile
@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 / fixDecksetThemes.py
Last active September 7, 2015 17:15
Python script to restore the metadata for a Deckset file after it is in version control, via xattr. Set your preferred Theme name and Colorscheme in top of file.
!/usr/bin/env python
#
# Quick Script to Fix the Local Settings of Deckset Themes
#
# Deckset uses `xattr` metadata which isn't preserved
# by version control.
#
# Note that Vim will also overwrite your metadata unless you `set backupcopy=yes`
#
# Brendan McAdams <brendan@boldradius.com>
@bwmcadams
bwmcadams / TestStrings.java
Last active August 29, 2015 14:25
Java String Concatenation Performance
public class TestStrings {
public static void main(String[] args) {
String foo = "Foo " + "bar";
String omg = "OMG" + "WTF" + "BBQ";
String test = foo + omg;
}
}
insert.transact(xa).attemptSomeSqlState {
case INTEGRITY_CONSTRAINT_VIOLATION =>
ERR_PartnerEntryExists
}.run

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 / scalazTestHelpers.scala
Last active August 29, 2015 14:05
Scalaz Failure tester for ScalaTest
import org.scalatest.Suite
import scalaz._
import Scalaz._
import org.scalatest.matchers._
/**
* Helper matchers for hacking with Scalaz.
*/
@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?