This file contains hidden or 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
# Not clear in the rdocs what the behavior will be when you pass nil! | |
def foo(val = nil) | |
val ||= "default" | |
end | |
# This one provides much better documentation to the reader, especially "rdocs" | |
# (At least, I *think* rdocs show the default values...) | |
def bar(val = "default") | |
val | |
end |
This file contains hidden or 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 hidden or 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 MySwingWorker extends SwingWorker[List[TwitterUserId], Object](ids: List[String]) { | |
def doInBackground = twitterSession.loadAll(ids) | |
override def done = streams.setFollowerIds(get map (_.id.toString())) | |
} | |
(new MySwingWorker(twitterSession.getFollowersIds)).execute | |
(new MySwingWorker(twitterSession.getFriendsIds)).execute |
This file contains hidden or 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 javax.swing.SwingWorker | |
class A { | |
def loadAll(f:(Int) => List[String]): List[String] = List("a") | |
def getFriendsIds(page: Int): List[String] = List("a") | |
def getFollowersIds(page: Int): List[String] = List("a") | |
} | |
class B { | |
def setFollowers(followers: List[String]) {} |
This file contains hidden or 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
case class Point(x: Int, y: Int) { | |
require(x >= 0) | |
require(y >= 0) | |
} | |
case class Piece(ps: Set[Point]) { | |
def flip = { | |
val mx = spanx | |
Piece(ps.map(p => Point(mx - p.x, p.y))) | |
} |
This file contains hidden or 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
// When you run "scala colors.scala", it's like you compiled the following script, | |
// where the contents of colors.scala is embedded inside the "new Anyref {...}". | |
object Script { | |
def main(args: Array[String]): Unit = { | |
new AnyRef { | |
// If you change "object" to "class" and remove the | |
// "type Color = Value" declaration, it compiles. | |
class Color extends Enumeration { | |
type Color = Value | |
val Empty = Value |
This file contains hidden or 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
object looksLikeAFunction{ | |
def apply(s:String):Int=1 | |
} | |
object nowAFunction extends Function[String,Int]{ | |
def apply(s:String):Int=1 | |
} | |
object TestMethods { | |
implicit def functionToAnother(f:Function[String,Int]):Function[Int,String] = | |
(i:Int)=> f(i.toString()).toString() |
This file contains hidden or 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
case class Error[E,A](e:Either[E,A]) { | |
def flatMap[B](f:A => Error[E,B]):Error[E,B] ={ | |
Error(e.right.flatMap(a=> f(a).e)) | |
} | |
def map[B](f:A=>B):Error[E,B]={ | |
Error(e.right.map(f)) | |
} | |
} | |
object ErrorUtils{ |
This file contains hidden or 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
{ | |
"metadata" : { | |
"name" : "GraphFramesExample", | |
"user_save_timestamp" : "1970-01-01T01:00:00.000Z", | |
"auto_save_timestamp" : "1970-01-01T01:00:00.000Z", | |
"language_info" : { | |
"name" : "scala", | |
"file_extension" : "scala", | |
"codemirror_mode" : "text/x-scala" | |
}, |
This file contains hidden or 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 numpy as np | |
import ray | |
import time | |
ray.init() # Start Ray | |
@ray.remote | |
class ParameterServer(object): | |
def __init__(self, dim): |
OlderNewer