Skip to content

Instantly share code, notes, and snippets.

@bwmcadams
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
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
bwmcadams / fixDecksetThemes.py
Last active Sep 7, 2015
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.
View fixDecksetThemes.py
!/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 Aug 29, 2015
Java String Concatenation Performance
View TestStrings.java
public class TestStrings {
public static void main(String[] args) {
String foo = "Foo " + "bar";
String omg = "OMG" + "WTF" + "BBQ";
String test = foo + omg;
}
}
View mysql-doobie.scala
insert.transact(xa).attemptSomeSqlState {
case INTEGRITY_CONSTRAINT_VIOLATION =>
ERR_PartnerEntryExists
}.run
View keybase.md

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 Aug 29, 2015
Scalaz Failure tester for ScalaTest
View scalazTestHelpers.scala
import org.scalatest.Suite
import scalaz._
import Scalaz._
import org.scalatest.matchers._
/**
* Helper matchers for hacking with Scalaz.
*/
@bwmcadams
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"
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;
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]
[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?