Skip to content

Instantly share code, notes, and snippets.

View benjaminjackman's full-sized avatar

Ben Jackman benjaminjackman

View GitHub Profile
object ItemContainer {
implicit class ItemContainerExtensions(val ic: ItemContainer) extends AnyVal {
def allItems(character: Option[String]): List[AnyItem] = {
ic.items.toList.flatMap { item =>
(item :: item.socketedItems.toList.map { i =>
i.inItem = item
i
}) map { i =>
character.foreach(c => i.character = c.toJs.asJsStr)
i.locationId = i.getLocationId.toJs.asJsStr
/**
* This is a binary search operation
* if the element is found, and it matches an element at an index precisely,
* then that index is returned.
*
* If the element is not found it will return a negative number.
* the index returned is as follows, if it is before the 0th index
* then -1 is returned
* if it is before the first index, but after the zeroeth
* then -2 is returned
define ["jquery", "underscore", "barista"], ($, _, B) ->
outs = B.createModule()
#Define a protocol
IStack = outs.defTypeclass 'IStack', (self) -> {
push: self.Abstract
pop: self.Abstract
pushAll : (elems...) -> _(elems).forEach((elem) -> self.push(elem))
}
#Make an implementation for arrays.
//Supposing we have this a list of arbs of this form perhaps in a lib ArbFunc
object ArbFunc {
//...
def apply[T1, T2, T3, T4, R](f: (T1, T2, T3, T4) => R)(implicit a: Arbitrary[(T1, T2, T3, T4)]): Arbitrary[R] =
Arbitrary {for (t <- Arbitrary.arbitrary[(T1, T2, T3, T4)]) yield f(t._1, t._2, t._3, t._4)}
//...
}
//Given this case class
case class Point(label : String, x : Int, y : Int, z : Int)
class Settings extends Record {
import Dsl._
val maxQty = req("maxQty", 1, IntTransformer).ensuring{v=> v >=! 0}
//Alternate version
val maxQty = req("maxQty", 1, IntTransformer).ensuring(>=!0).ensuring(!==!666)
val minQty = opt(req("minQty", 2, IntTransformer).ensuring(>=!0))
override def check : Option[ErrorMsg] = {
maxQty.value >=! minQty.value
Squeryl/src/main/scala/org/squeryl/dsl/QueryDsl.scala:210: type mismatch;
found : org.squeryl.Query[org.squeryl.dsl.Measures[QueryDsl.this.LongType]]
required: org.squeryl.Query[QueryDsl.this.LongType]
Note that implicit conversions are not applicable because they are ambiguous:
both method singleColComputeQuery2ScalarQuery in trait QueryDsl of type [T](org.squeryl.Query[org.squeryl.dsl.Measures[T]])QueryDsl.this.ScalarQuery[T]
and method singleColComputeQuery2Scalar in trait QueryDsl of type [T](org.squeryl.Query[org.squeryl.dsl.Measures[T]])T
are possible conversion functions from org.squeryl.Query[org.squeryl.dsl.Measures[QueryDsl.this.LongType]] to org.squeryl.Query[QueryDsl.this.LongType]
def forUpdate = _inner.forUpdate
^
Squeryl/src/main/scala/org/squeryl/dsl/QueryDsl.scala:224: type mismatch;
diff --git a/src/main/scala/sbt/Compile.scala b/src/main/scala/sbt/Compile.scala
index aaaab2d..21f5ef6 100644
--- a/src/main/scala/sbt/Compile.scala
+++ b/src/main/scala/sbt/Compile.scala
@@ -261,9 +261,28 @@ final class LoggerReporter(maximumErrors: Int, log: Logger) extends scala.tools.
case NoPosition => log.log(level, msg)
case FakePos(fmsg) => log.log(level, fmsg+" "+msg)
case _ =>
- val sourcePrefix = pos.source.map(_.file.path).getOrElse("")
- val lineNumberString = pos.line.map(line => ":" + line + ":").getOrElse(":") + " "
trait CEnum {
/** The concrete subtype of EnumElements
*/
type ET <: EnumElement
/**
* Override this trait in your subclass with the
* base type of the EnumElements, then set ET = to that value
* the Template type in Ordered might need to be ET
* to ensure proper type safety, however I was getting
/** Class for testing the distribution of hashCodes for Products/Collections of items in Scala.
* Should be able to just copy - paste this right into the scala interpreter
*/
object Hashable {
val HashSeed = 0x27d4eb2d
val HashConstant = 41
val NullHashCode = 0
/**
* Adapted from
import java.lang.ref.SoftReference
object CSoftRef {
def apply[A](blk : => A) = new CSoftRef[A](blk)
}
class CSoftRef[A](blk : => A) extends MagicMixin {
private var ref = new SoftReference[A](blk)
def get : A = {
ref.get match {