Skip to content

Instantly share code, notes, and snippets.

Avatar

Brendan McAdams bwmcadams

View GitHub Profile
@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.
*/
View mysql-doobie.scala
insert.transact(xa).attemptSomeSqlState {
case INTEGRITY_CONSTRAINT_VIOLATION =>
ERR_PartnerEntryExists
}.run
@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 scala time -> 2.8 patch
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>
View gist:527992
// 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)))
View noBlankRowsMatcher.scala
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 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 / Homebrew for Scala 2.8.1 RC4.rb
Created Oct 31, 2010
Homebrew recipe for Scala 2.8.1 RC4
View Homebrew for Scala 2.8.1 RC4.rb
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 Nov 9, 2010
Homebrew recipe for Scala 2.8.1 final
View scala2.8.1.final_homebrew.rb
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 Dec 22, 2010
When a one line change produces an error like this you may have a MINOR issue.
View Oops.scala
[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