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 OptionalEmbeddedField[V](override val mongoFieldName: String, val g: T => Option[V], val p: Option[(T,Option[V]) => Unit]) | |
extends MongoScalar[V] with EmbeddedContent[V] with FieldModifyOp[V] with Optional[V] { | |
self: MongoField[V] with ObjectIn[V, QueryType] => | |
override val rep = parent.Represented.byOption(g, p) | |
override def canEqual(other: Any): Boolean = other.isInstanceOf[OptionalEmbeddedField[_]] | |
} | |
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 A { | |
val initVal: String = "aa" | |
def useInitVal { println(initVal) } | |
useInitVal | |
} | |
class B extends A { | |
override val initVal = "bb" | |
} |
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 for MongoDB Scala Driver | |
import com.osinka.mongodb._ // <- this replaces Preamble | |
import com.osinka.mongodb.shape._ | |
import com.mongodb.{Mongo,DBObject} | |
// Scala complains you are using "case class" here and I understand it. "class" is more | |
// appropriate as you have no arguments | |
class User extends MongoObject { | |
var id: Int = _ | |
var name: 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
# Config for Nginx to act as a front-end for Riak | |
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc) | |
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_) | |
# Config is in /etc/nginx/sites-available/default or somewhere like that | |
# Set up load-balancing to send requests to all nodes in the Riak cluster | |
# Replace these IPs/ports with the locations of your Riak nodes | |
upstream riak_hosts { | |
server 127.0.0.1:8098; |
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
def toArray(dbo: DBObject): Seq[Any] = { | |
def arrayValues(i: Int): Stream[Any] = { | |
val key = i.toString | |
if (dbo.containsField(key)) Stream.cons(dbo.get(key), arrayValues(i+1)) | |
else Stream.empty | |
} | |
arrayValues(0).toList | |
// | |
// |
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
// Model | |
case class User(val name: String) | |
// Factory object: | |
object User extends AbstractShape[User] { | |
// one scalar field called "name" | |
object name extends Scalar[String]("name", _.name) with Functional[String] | |
// fields list | |
override lazy val * = name :: Nil |
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 Word(word: String, count: Long) { | |
override def toString = word + ": " + count | |
def +(n: Long): Word = Word(word, count + n) | |
} | |
private def showWordCloud { | |
val words = statusTableModel.filteredStatuses.flatMap(_.text.split("\\s")) | |
val emptyMap = immutable.Map.empty[String, Word].withDefault(w => Word(w, 0)) | |
val counts = words.foldLeft(emptyMap)((map, word) => map(word) += 1) | |
val countList = counts.values.toList.sort(_.count > _.count) |
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
// Sketch of an immutable domain model in Scala | |
// We used this scheme together with this JPA module: | |
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/JPA.scala | |
// ...and this GenericRepository: | |
// http://github.com/jboner/skalman/blob/d1e03a85be3964b9012f9e79dd726b0546342b2b/core/src/main/scala/GenericRepository.scala | |
abstract class Entity[T](val id: Int) | |
object User { |
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
/* | |
* Scala trait to hold Configuration Admin | |
*/ | |
package com.yours.app | |
import org.osgi.service.cm.ConfigurationAdmin | |
trait ConfigAdminHolder { | |
protected var configAdmin: Option[ConfigurationAdmin] = None |
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
Netbeans: | |
http://www.netbeans.org | |
Scala plugin для NetBeans 6.7 тут: | |
http://blogtrader.net/dcaoyuan/entry/scala_plugin_version_1_for | |
У меня еще сделаны такие настройки: | |
1. в файле NetBeans .../etc/netbeans.conf прописана JDK 1.6: | |
netbeans_jdkhome=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home |