Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alaz's full-sized avatar

Alexander Azarov alaz

View GitHub Profile
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[_]]
}
class A {
val initVal: String = "aa"
def useInitVal { println(initVal) }
useInitVal
}
class B extends A {
override val initVal = "bb"
}
// 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 = _
@alaz
alaz / nginx.conf
Created March 6, 2010 15:44 — forked from johnthethird/nginx.conf
Edits and comments to the Nginx config for Riak
# 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;
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
//
//
@alaz
alaz / mongo-scala-driver first example.scala
Created October 13, 2009 18:10
Simple example for mongo-scala-driver "Getting Started" Wiki page
// 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
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)
// 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 {
/*
* Scala trait to hold Configuration Admin
*/
package com.yours.app
import org.osgi.service.cm.ConfigurationAdmin
trait ConfigAdminHolder {
protected var configAdmin: Option[ConfigurationAdmin] = None
@alaz
alaz / Netbeans 6.7 + Scala config
Created July 9, 2009 11:20
Netbeans 6.7 + Scala config
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