This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """) | |
val matcher = pattern.matcher (input) | |
while (matcher.find) { | |
val col1 = matcher.group (2) | |
val col2 = matcher.group (4) | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class some[X](val value : X) { type T = X } | |
abstract class someFactory[S <: some[_]](val P : (S#T) => boolean) | |
{ | |
def apply(t : S#T) : Option[S] = if(P(t)) Some(fetch(t)) else None | |
def unapply(s : S) : Option[S#T] = if(s == null) None else Some(s.value) | |
def fetch(t : S#T) = mk(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//isValid = predicate/constraint | |
abstract class Type[T](val isValid : (T) => boolean) | |
{ | |
//X is the reference type | |
final protected[Type] case class X[T] (val value : T) { | |
override def toString = Type.this.getClass.getSimpleName + "(" + value + ")" | |
} | |
//Type is the alias for X[T] that we expose to the outside world | |
type Type = X[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package retweetrec | |
import scala.xml.XML | |
import java.net.URL | |
import java.io.InputStream | |
object ReTweetRec { | |
def getFollowers(id: String) = { | |
val data = new URL("http://twitter.com/followers/ids/" + id + ".xml").getContent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER | | |
CREATE FUNCTION uuid_from_bin(b BINARY(16)) | |
RETURNS CHAR(36) DETERMINISTIC | |
BEGIN | |
DECLARE hex CHAR(32); | |
SET hex = HEX(b); | |
RETURN CONCAT(LEFT(hex, 8), '-', MID(hex, 9,4), '-', MID(hex, 13,4), '-', MID(hex, 17,4), '-', RIGHT(hex, 12)); | |
END | |
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://gist.github.com/161702. | |
* Start with this Groovy example, http://gist.github.com/160492 | |
* and Scala variants suggested by others, http://gist.github.com/161159 | |
* and http://gist.github.com/162389 | |
* | |
* Here is what I came up with, but it's somewhat different. The others assume | |
* that Cucumber will parse the regex's and invoke the anonymous function | |
* specified with the Given declaration. The problem is that it's difficult to | |
* define a generic function signature. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex._ | |
object Cucumber { | |
var givens:List[(String,(String) => Boolean)] = Nil | |
var whens:List[(String,(String) => Boolean)] = Nil | |
var thens:List[(String,(String) => Boolean)] = Nil | |
var testsRun = 0 | |
var testsFailed = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// scala 2.7 simple type constraint. This can only constrain a type parameter of this function. | |
// Below, in ListW.sumint28, we can't use this approach because we want to constrain T, | |
// a type param of the enclosing trait. | |
def sumint27A[T <: Int](l: List[T]) : Int = l.reduceLeft((a: Int, b: Int) => a + b) | |
trait IntLike[X] extends (X => Int) | |
object IntLike { | |
implicit val intIntLike: IntLike[Int] = new IntLike[Int] { def apply(x: Int) = identity(x) } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ThreadLocal[T](init: => T) extends java.lang.ThreadLocal[T] with Function0[T] { | |
override def initialValue:T = init | |
def apply = get | |
def withValue[S](thunk:(T => S)):S = thunk(get) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
OlderNewer