Skip to content

Instantly share code, notes, and snippets.

View jdolson's full-sized avatar

Jeff Olson jdolson

View GitHub Profile
@jdolson
jdolson / MyPlugin.scala
Created August 31, 2013 02:44
Example barebones sbt plugin
import sbt._
object MyPlugin extends Plugin {
val newSetting = settingKey[String]("A new setting.")
val newTask = taskKey[Unit]("A new task.")
override def projectSettings = Seq(
newSetting := "test",
newTask := println(newSetting.value)
)
import sbt._
import sbt.testing.Event
import scala.collection.{concurrent, mutable}
class ThreadSafeTestsListener extends TestReportListener {
val groups = concurrent.TrieMap.empty[String, TestGroup]
class TestGroup(val name: String) {
val events = new mutable.ArrayBuffer[Event] // does this need to be an ArrayBlockingQueue?
}
@jdolson
jdolson / gist:3846435
Created October 6, 2012 22:57
A naive covariant set
trait Set[+A] extends (Any => Boolean) { self =>
def contains(x: Any): Boolean
def apply(x: Any): Boolean = contains(x)
def + [B >: A](x: B): Set[B] = new Set[B] {
def contains(y: Any) = (y == x) || self.contains(y)
}
@jdolson
jdolson / FlatArrayFactory.scala
Created February 15, 2012 19:24
FlatArrayFactory with Boxed/Unboxed representation type-class
import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.{Builder, ArrayBuffer, IndexedSeq, IndexedSeqLike}
import scala.specialized
trait Representation[Unboxed, Boxed] {
def box(x: Unboxed): Boxed
def unbox(x: Boxed): Unboxed
}
abstract class FlatArrayFactory[@specialized Unboxed: ClassManifest, Boxed] {
@jdolson
jdolson / IdentityHashMap.scala
Created January 5, 2012 18:49
scala mutable IdentityHashMap implementation
package com.github.gist.jdolson.collection.mutable
import scala.collection.generic.CanBuildFrom
import scala.collection.mutable.{MapLike, MapBuilder, HashMap}
final class IdentityHashMap[A <: AnyRef, B]() extends HashMap[A, B] with MapLike[A, B, IdentityHashMap[A, B]] {
override protected def elemEquals(key1: A, key2: A): Boolean = key1 eq key2
override protected def elemHashCode(key: A) = System.identityHashCode(key)
@jdolson
jdolson / MultiMap.scala
Created January 5, 2012 18:47
scala mutable MultiMap implementation
package com.github.gist.jdolson.collection.mutable
import scala.collection.mutable.{Set, Map, Iterable, Builder, Cloneable}
import scala.collection.generic.{CanBuildFrom, Shrinkable}
import scala.collection.{Iterator, IterableLike, breakOut}
object MultiMap {
type Coll = MultiMap[_, _]
implicit def canBuildFrom[A, B] = new CanBuildFrom[Coll, (A, B), MultiMap[A, B]] {