Skip to content

Instantly share code, notes, and snippets.

View bwmcadams's full-sized avatar

Brendan McAdams bwmcadams

View GitHub Profile
@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.
*/
insert.transact(xa).attemptSomeSqlState {
case INTEGRITY_CONSTRAINT_VIOLATION =>
ERR_PartnerEntryExists
}.run
@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;
}
}
diff --git a/pom.xml b/pom.xml
index ac0f723..32853f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@
</scm>
<properties>
- <scala.version>2.7.4</scala.version>
+ <scala.version>2.8.0</scala.version>
// Test Method
@Stache("unitTest", Some(3600)) def foo(x: Int) = {
println("Multiplying X (%s) by 2".format(x))
x * 2
}
// Compiler steps
var block = tree.find( _.isInstanceOf[Block] ) orElse tree.find( _.isInstanceOf[Apply] ) getOrElse(throw new IllegalArgumentException("Cannot find method body for Stache annotated DefDef '%s'. Was looking for either a code block or a one liner. Is method abstract or something else boneheaded?".format(dDef.name)))
val notHaveBlankRows = new Matcher[Iterable[Map[String, String]]] {
def apply(x: => Iterable[Map[String, String]]) = {
(x().forall(row => row.forall(kv => kv._2 != null && kv._2 != "" && kv._2 != None)),
"No blank rows contained in Iterable.",
"Blank rows (all values in row are either '', null or None) found in Iterable.")
}
}
@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 / Homebrew for Scala 2.8.1 RC4.rb
Created October 31, 2010 18:21
Homebrew recipe for Scala 2.8.1 RC4
require 'formula'
class Scala <Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/downloads/distrib/files/scala-2.8.1.RC4.tgz'
version '2.8.1.RC4'
md5 '835f07e494004b33b82ded8f9b291cb1'
def install
rm_f Dir["bin/*.bat"]
@bwmcadams
bwmcadams / scala2.8.1.final_homebrew.rb
Created November 9, 2010 18:44
Homebrew recipe for Scala 2.8.1 final
require 'formula'
class Scala <Formula
homepage 'http://www.scala-lang.org/'
url 'http://www.scala-lang.org/downloads/distrib/files/scala-2.8.1.final.tgz'
version '2.8.1'
md5 '4fa66742341b5c9f6877ce64d409cb92'
def install
rm_f Dir["bin/*.bat"]
@bwmcadams
bwmcadams / Oops.scala
Created December 22, 2010 19:39
When a one line change produces an error like this you may have a MINOR issue.
[error] /Users/bwmcadams/code/mongodb/casbah/casbah-query/src/test/scala/DSLCoreOperatorsSpec.scala:1271: type mismatch;
[error] found : ((some other)$anon(in value <local DSLCoreOperatorsSpec>) forSome { type (some other)$anon(in value <local DSLCoreOperatorsSpec>) <: java.lang.Object with com.mongodb.casbah.commons.MongoDBObject{def $maxDistance[T](radius: T)(implicit evidence$15: Numeric[T]): (some other)$anon(in value <local DSLCoreOperatorsSpec>)} })
[error] required: $anon(in value <local DSLCoreOperatorsSpec>) where type $anon(in value <local DSLCoreOperatorsSpec>) <: java.lang.Object with com.mongodb.casbah.commons.MongoDBObject{def $maxDistance[T](radius: T)(implicit evidence$15: Numeric[T]): $anon(in value <local DSLCoreOperatorsSpec>)}
[error] near must notBeNull
[error] ^
((some other)$anon(in value <local DSLCoreOperatorsSpec>) forSome { type (some other)$anon(in value <local DSLCoreOperatorsSpec>) <: java.lang.Object with com.mongodb.casbah.commons.MongoDBObject{def $maxDista