Skip to content

Instantly share code, notes, and snippets.

@BowlingX
BowlingX / gist:1452046
Created December 9, 2011 15:46
Geonames.org Meta for elastic search
{
state: open
settings: {
index.analysis.filter.name_ngrams.side: front
index.analysis.filter.name_ngrams.type: edgeNGram
index.analysis.analyzer.full_name.type: custom
index.analysis.filter.name_ngrams.max_gram: 40
index.analysis.analyzer.full_name.tokenizer: standard
index.analysis.analyzer.partial_name.filter.3: name_ngrams
index.analysis.filter.name_ngrams.min_gram: 2
@BowlingX
BowlingX / gist:1471538
Created December 13, 2011 10:18
Mapping and Settings Geonames
{
state: open
settings: {
index.analysis.filter.name_ngrams.side: front
index.analysis.filter.name_ngrams.type: edgeNGram
index.analysis.analyzer.partial.tokenizer: standard
index.store: memory
index.number_of_replicas: 1
index.analysis.analyzer.partial.filter.3: name_ngrams
index.analysis.analyzer.partial_non_ascii.filter.2: name_ngrams
@BowlingX
BowlingX / gist:1647010
Created January 20, 2012 11:49
Accept Language locale extraction
package org.scalatra.i18n
import org.scalatra.{CookieSupport, ScalatraKernel}
import java.util.Locale
import org.scalatra.i18n.Messages
object I18nSupport {
def localeKey = "locale"
Cookies:
http://192.168.2.111:8080/login/test/blub?locale=de -> cookie path is /login/test
http://192.168.2.111:8080/login/test -> cookie path is /login
http://192.168.2.111:8080/login -> cookie path is /
@BowlingX
BowlingX / gist:2070600
Created March 18, 2012 11:15
SBT Reflective load a Class on fullClasspath
/* File: Build.scala in ~/project */
/*...Build Definition...*/
/* This Task should load a Class on my Project*/
val taskKey = TaskKey[Unit]("task-name", "task-description")
val myTask = taskKey <<= (fullClasspath in Runtime, scalaInstance) map { (cp, si) =>
@BowlingX
BowlingX / gist:2075392
Created March 18, 2012 15:30
How to run code from yourLibrary in sbt with a task
/*File Runner:scala*/
package com.myCompany
object Runner extends App {
val myArgument = args(0)
/*Do whatever you want :)*/
}
@BowlingX
BowlingX / gist:2633780
Created May 8, 2012 09:08
Atmosphere with Scalatra and Apache Shiro
get("/status") {
val currentUser = SecurityUtils.getSubject();
// Save current User to request, because this request will be suspended and forked in another thread.
// See: http://jfarcand.wordpress.com/2011/07/13/quick-tip-using-apache-shiro-with-your-atmospheres-websocketcomet-app/
request.setAttribute("subject", currentUser);
import org.atmosphere.cpr.HeaderConfig._
contentType = ContentType.JSON
val m: Meteor = Meteor.build(request)
m.addListener(new EventsLogger())
// Create or retrieve Broadcaster for current User
@BowlingX
BowlingX / gist:2635689
Created May 8, 2012 14:40
Exception during Websocket Access with Apache Shiro and Atmosphere
16:38:32.716 [qtp2112864060-76] WARN o.a.w.protocol.SimpleHttpProtocol - org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: java.io.InvalidClassException: scala.collection.mutable.HashSet; local class incompatible: stream classdesc serialVersionUID = 1, local class serialVersionUID = -693344176634852721 Status 500 Message Server Error
16:38:50.381 [qtp2112864060-73 Selector0] WARN o.a.websocket.WebSocketProcessor - AsynchronousProcessor.AsynchronousProcessorHook was null
16:38:50.775 [qtp2112864060-76] WARN o.a.websocket.WebSocketProcessor - Failed invoking AtmosphereFramework.doCometSupport()
org.apache.shiro.cache.CacheException: net.sf.ehcache.CacheException: java.io.InvalidClassException: scala.collection.mutable.HashSet; local class incompatible: stream classdesc serialVersionUID = 1, local class serialVersionUID = -693344176634852721
at org.apache.shiro.cache.ehcache.EhCache.put(EhCache.java:105) ~[shiro-ehcache-1.2.0.jar:1.2.0]
at org.apache.shiro.session.mgt.eis.CachingSessionD
ivyXML :=
<dependencies>
<exclude org="org.eclipse.jetty.orbit" />
</dependencies>
libraryDependencies ++= Seq(
"org.scalatra" % "scalatra" % "2.1.0-SNAPSHOT",
"org.scalatra" % "scalatra-specs2" % "2.1.0-SNAPSHOT" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.0" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.4.v20120524" % "container",
@BowlingX
BowlingX / gist:3788190
Created September 26, 2012 13:53
Scalate with Scalate Compiler
trait TemplateBindings extends ScalateSupport {
self: ScalatraServlet =>
override protected def defaultTemplatePath: List[String] = List("/webTmpl/views")
override protected def createTemplateEngine(config: ConfigT) = {
val engine = super.createTemplateEngine(config)
engine.layoutStrategy = new DefaultLayoutStrategy(engine,
TemplateEngine.templateTypes.map("/webTmpl/layouts/default." + _): _*)