Skip to content

Instantly share code, notes, and snippets.

package org.scalatra.ssgi.servlet
import javax.servlet.ServletConfig
import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet}
import org.scalatra.ssgi.Application
class SsgiServlet extends HttpServlet {
override def init(config: ServletConfig) {
@casualjim
casualjim / TemplateSupport.scala
Created October 29, 2010 10:34
Template support trait for scalatra
trait TemplateSupport extends ScalateSupport with Logging { self: (
ScalatraKernel with FlashMapSupport with CookieSupport { def servletContext: ServletContext }) =>
private var _viewsLocation = "/WEB-INF/views"
val Ssp = "ssp"
val Scaml = "scaml"
val Jade = "jade"
val Mustache = "mustache"
object Stream {
sealed trait XMPPStreamError
object BadFormatError {
def apply( text: Option[String] = None, applicationCondition: Seq[Node]) = {
<stream:error>
<bad-format xmlns={XMPP_STREAMS_NS} />
{text.map(t => <text xmlns={XMPP_STREAMS_NS}>{t}</text>) getOrElse Nil}
{applicationCondition getOrElse Nil}
</stream:error>
override def packageOptions =
manifestClassPath.map(cp => ManifestAttributes(
(Attributes.Name.CLASS_PATH, cp),
(IMPLEMENTATION_TITLE, "Backchat XMPP module"),
(IMPLEMENTATION_URL, "http://backchat.im"),
(IMPLEMENTATION_VENDOR, "Mojolly Ltd."),
(IMPLEMENTATION_VERSION, version.toString)
)).toList ::: getMainClass(false).map(MainClass(_)).toList
def allArtifacts = {
# nginx - web server
description "nginx web server"
author "Graham Edgecombe <[email protected]>"
start on runlevel [2345]
stop on runlevel [016]
expect fork
respawn
@casualjim
casualjim / gist:667785
Created November 8, 2010 15:10
Nginx upstart script
# nginx - web server
description "nginx web server"
author "Ivan Porto Carrero"
start on (net-device-up and local-filesystems)
stop on runlevel [016]
expect fork
respawn
exec sudo /usr/local/sbin/nginx
@casualjim
casualjim / AuthenticationSupport.scala
Created December 7, 2010 20:26
A basic auth strategy for scalatra's scentry
package org.scalatra.auth
import OurImplicits._
import com.mongodb.casbah.Imports._
import org.scalatra.auth.{ScentryConfig, ScentrySupport}
import org.scalatra.ScalatraKernel
trait AuthenticationSupport extends ScentrySupport[DBObject] with BasicAuthSupport { self: ScalatraKernel =>
val realm = Config.serviceName
import com.mongodb.casbah.Imports._
import akka.util.Logging
import com.mongodb.DBRef
import org.bson.types.ObjectId
trait DataCollection extends Logging with BackchatJsonFormat {
private var _collection: MongoCollection = null
protected val collectionName: String
def db: MongoDB = Config.mongo.db
trait InputStreamRenderable extends Renderable {
def in: InputStream
def writeTo(out: OutputStream, cs: Charset) {
val in = this.in // it's a def, and we only want one
streamCopy(Channels.newChannel(in), Channels.newChannel(out))
in.close()
}
private def streamCopy(src: ReadableByteChannel, dest: WritableByteChannel) {
get("/:login/:slug") {
contentType = "application/json"
val out = response.getOutputStream
while(true) {
val msg = pollBackendQueue
out.println(msg)
}
""
}