Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am williamchan on github.
  • I am wizzlechan (https://keybase.io/wizzlechan) on keybase.
  • I have a public key whose fingerprint is F64A 16D1 7D30 80DF D0E4 1C5E F9B3 96E9 0ABF FB68

To claim this, I am signing this object:

/** This is so slick.
* When working with Streams, use val instead of def so that memoization is enabled by default.
*
* Also see See http://derekwyatt.org/2011/07/29/understanding-scala-streams-through-fibonacci/
*/
import scala.math.BigInt
lazy val fibs: Stream[BigInt] = BigInt(0) #::
BigInt(1) #::
fibs.zip(fibs.tail).map { n => n._1 + n._2 }
@williamchan
williamchan / paxata-license-format.ftl
Created December 9, 2015 21:24
Format for third-party file returned by License Maven Plugin
<#-- For formatting third-party file returned by License Maven Plugin.
Format is semicolon-delimited: license; name; groupId; artifactId; version; url
-->
<#function licenseFormat licenses>
<#assign result = ""/>
<#list licenses as license>
<#assign result = result + license/>
</#list>
<#assign result = result + ";"/>
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@williamchan
williamchan / grep-for-missing-junitrunner-annotations
Created January 29, 2015 18:38
A short bash script that will find *Test.scala files that lack a JUnitRunner annotation
for i in $(find . -name *Test.scala);
do grep -s \"@RunWith(classOf\\[JUnitRunner\\])\" $i;
if [ $? -ne 0 ];
then
echo $i;
fi;
done
@williamchan
williamchan / simplemocha_test
Last active August 29, 2015 14:02
A few simple commands to run mocha tests
echo "Running mocha tests with grunt..."
echo `grunt -version`
npm install
grunt simplemocha --force