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 User(name: String, email: String) | |
object User {} // <--- Notice this part here | |
// https://groups.google.com/forum/#!topic/scala-user/jyWBMz5Qslw | |
class Users(tag: Tag) extends Table[User](tag, "User") { | |
def name = column[String]("name", O.NotNull, O.PrimaryKey) | |
def email = column[String]("first", O.NotNull) | |
def * = (name, email) <> (User.tupled, User.unapply) | |
// Compile complains here ---^ | |
} |
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
object Trond { | |
val age = 25 // value - immutable variable - final in java | |
def sayHi = println(s"My name is Trond and I'm $age years old!") // definition - method | |
} | |
// Trond.age = 27 does not compile as age is immutable (val) | |
Trond.sayHi | |
object Eli { // singleton object - only one of these in the JVM | |
var age = 22 // variable (mutable) |
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
if test $(sbt test | grep -c -E "Reformatted|Failed") != 0 | |
#if test $(sbt compile | grep -c -E "Reformatted|Failed") != 0 | |
#if test $(sbt ";scalariformFormat;test:scalariformFormat" | grep -c -E "Reformatted|Failed") != 0 | |
then | |
echo "Sbt detected problems" | |
exit 1 | |
fi |
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
akka { | |
loggers = [akka.event.slf4j.Slf4jLogger] | |
loglevel = "DEBUG" | |
actor { | |
provider = akka.remote.RemoteActorRefProvider | |
} | |
remote { | |
enabled-transports = [akka.remote.netty.tcp] |
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 Match(cols: Column[_]*) { | |
def against(what: Column[_], modifier: SearchModifier.Value*) = | |
SimpleExpression[Boolean]{ case (nodes, qb) => | |
import qb._ | |
qb.sqlBuilder += "MATCH(" | |
qb.sqlBuilder.sep(nodes, ", ")(expr(_)) | |
qb.sqlBuilder += ") AGAINST(" | |
qb.expr(what.toNode) | |
qb.sqlBuilder += " " | |
qb.sqlBuilder.sep(modifier, " ")(_.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 misc | |
// Animal | |
abstract class Animal { | |
def name: String | |
def eat(food: Food): Animal = | |
this |
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
def render = {<a onclick={Alert(Call(myFunction, 4, 5))}>Click me</a>} |
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 listFromDb : Box[List[String]]= ... should collect data from db, but throws exception ... | |
def render = { | |
listFromDb match { | |
case None => <p>No items.</p> | |
case Some(items) => | |
bind( | |
"myComet", defaultXml, | |
"content" -> transforListToXhtml(list)) |
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://tbje.blogspot.com/2010/04/random-unique-hash-in-scala.html */ | |
import scala.util.Random | |
def uniqueRandomKey(chars: String, length: Int, uniqueFunc: String=>Boolean) : String = { | |
val newKey = (1 to length).map(x => chars(Random.nextInt(chars.length))).mkString | |
if (uniqueFunc(newKey)) newKey else uniqueRandomKey(chars, length, uniqueFunc) | |
} | |
val chars = ('a' to 'z') ++ ('A' to 'Z') ++ ('1' to '9') | |
val key = uniqueRandomKey(chars.toString, 22, (x:String)=>!keyExists?(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
import net.liftweb.http._ | |
import net.liftweb.http.SHtml._ | |
import net.liftweb.util._ | |
import net.liftweb.util.Helpers._ | |
import net.liftweb.common._ | |
import java.net.{HttpURLConnection, MalformedURLException, URL, URLEncoder} | |
import java.io.{BufferedReader, InputStreamReader, IOException, OutputStreamWriter} | |
import scala.xml._ |
OlderNewer