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
[INFO] [scala:compile {execution: default}] | |
[INFO] Checking for multiple versions of scala | |
[INFO] includes = [**/*.scala,**/*.java,] | |
[INFO] excludes = [] | |
[INFO] /home/hub/p/eee/src/main/scala:-1: info: compiling | |
[INFO] Compiling 128 source files to /home/hub/p/eee/target/classes at 1312794546514 | |
[INFO] Recompiling 1 files | |
[ERROR] /home/hub/p/eee/src/main/scala/Service.scala:72: error: type mismatch; | |
[ERROR] found : Unit | |
[ERROR] required: () => Any |
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
[INFO] [scala:compile {execution: default}] | |
[INFO] Checking for multiple versions of scala | |
[INFO] includes = [**/*.scala,**/*.java,] | |
[INFO] excludes = [] | |
[INFO] /home/hub/p/eee/src/main/scala:-1: info: compiling | |
[INFO] Compiling 128 source files to /home/hub/p/eee/target/classes at 1312794546514 | |
[INFO] Recompiling 1 files | |
[ERROR] /home/hub/p/eee/src/main/scala/Service.scala:72: error: type mismatch; | |
[INFO] found : Unit | |
[INFO] required: () => Any |
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
set nocompatible " must be the first line | |
filetype on | |
filetype indent on | |
filetype plugin on | |
"" General options | |
set bg=dark | |
syntax on | |
set number |
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
case class Person(firstname: String, lastname: String) | |
type MongoReader[T] = MongoDBObject => T | |
type MongoWriter[T] = T => MongoDBObject | |
def readArray[T : MongoReader](name: String) = new MongoReader[List[T]] { | |
def apply(dbo: MongoDBObject) = { | |
println("dbo = %s".format(dbo.toString)) | |
println("dbo.%s = %s".format(name, dbo.as[BasicDBList](name).toString)) |
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 patmat | |
import scala.language.postfixOps | |
import common._ | |
/** | |
* Assignment 4: Huffman coding | |
* | |
*/ | |
object Huffman { |
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
implicit class RichMap[K, V](m: Map[K, V]) { | |
def updateValue(k: K)(f: Option[V] => V): Map[K, V] = m + (k -> f(m get k)) | |
def incValue(k: K)(implicit ev: Numeric[V]): Map[K, V] = | |
updateValue(k){ o => | |
val one = ev.fromInt(1) | |
o map { ev.plus(_, one) } getOrElse one | |
} | |
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
%s should %s be balanced".format(s, | |
if (!expected) "NOT" else "")) | |
testBalance("(if (zero? x) max (/ 1 x))") | |
testBalance("I told him (that it's not (yet) done)." + | |
"(But he wasn’t listening)") | |
testBalance(":-)", expected = false) | |
testBalance("())(", expected = false) | |
} |
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
/** | |
* The water pouring problem is a classic one: | |
* 1. you have a limited set of containers, each of which has its specific | |
* capacity | |
* 2. you want to pour a precise volume of water in a jar, volume | |
* which is not obtained straight from one of the containers at | |
* hand | |
* 3. you then want to find the minimal set of operations to achieve | |
* your goal if at all possible. | |
*/ |
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
/** | |
* How to convert a distributed fleet from what type of hardware to | |
* another without degrading (too much) your service. | |
* | |
*/ | |
case class Machine(name: String, ECU: Double, mem: Int, disk: Int, TCO: Float) | |
object Machine { | |
val m1Xlarge = Machine("m1.xlarge", ECU = 1, mem = 7, disk = 700, TCO = 600) | |
val m2Xlarge = Machine("m2.xlarge", ECU = 2.6, mem = 14, disk = 1400, TCO = 400) |
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
/** | |
* How to convert a distributed fleet from what type of hardware to | |
* another without degrading (too much) your service. | |
* | |
*/ | |
import collection.{mutable, immutable} | |
case class Machine(name: String, ECU: Double, mem: Int, disk: Int, TCO: Float) | |
object Machine { | |
val m1Large = Machine("m1.large", ECU = 1, mem = 7, disk = 700, TCO = 600) |
OlderNewer