Skip to content

Instantly share code, notes, and snippets.

View tbje's full-sized avatar

Trond Bjerkestrand tbje

View GitHub Profile
<Get name="sessionHandler">
<Get name="sessionManager">
<Set name="refreshCookieAge">120</Set>
<Set name="maxCookieAge">1200</Set>
</Get>
</Get>
class MyProject(info: ProjectInfo) extends DefaultWebProject(info){
<!-- Your dependencies here -->
val jetty7WebApp = "org.eclipse.jetty" % "jetty-webapp" % "7.0.2.RC0" % "test"
val jetty7Server = "org.eclipse.jetty" % "jetty-server" % "7.0.2.RC0" % "test"
val jetty7Plus = "org.eclipse.jetty" % "jetty-plus" % "7.0.2.RC0" % "test"
<!-- Path to jetty-env.xml -->
override def jettyEnvXml = Some(
(sourcePath / "main" / "jetty" / "jetty-env.xml").asFile
)
import scala.xml._
def googleLocalisation(adr: String) : Option[(Double, Double)] = {
val url = "http://maps.google.com/maps/api/geocode/xml?sensor=false&address="
val xml = XML.load(url+adr)
if ((xml \ "status" text) == "OK") {
val lat = ((xml \ "result" \ "geometry" \ "location" \ "lat") text).toDouble
val lng = ((xml \ "result" \ "geometry" \ "location" \ "lng") text).toDouble
Some((lat, lng))
} else {
<!-- disable surefire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- enable scalatest -->
<plugin>
import net.liftweb.util.ActorPing
import net.liftweb.common.Logger
class Boot extends Logger {
def boot {
// where to search snippet
LiftRules.addToPackages("your.package")
...
val myActor = new MyActor
myActor ! Msg
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._
/* 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))
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))
def render = {<a onclick={Alert(Call(myFunction, 4, 5))}>Click me</a>}