Skip to content

Instantly share code, notes, and snippets.

View lanceon's full-sized avatar

Oleksiy lanceon

View GitHub Profile
object VarargTest {
abstract class OptionBase
case class Width(s: String) extends OptionBase
case object HasSearch extends OptionBase
case class Title(s: String) extends OptionBase
implicit def strToOption(s:String) : OptionBase = Title(s)
def func(options: OptionBase*) {
options.foreach(o => println("option = [%s]".format(o)))
@lanceon
lanceon / TraitsTest.scala
Last active December 20, 2015 16:59
Scala traits composition and method overriding
object TraitsTest {
trait Base {
def func() = println("Base.func")
}
trait A extends Base {
override def func() = { super.func(); println("A.func") }
}
@lanceon
lanceon / mysql_lift.txt
Last active December 20, 2015 21:29
Lift + MySQL
build.sbt
=========
libraryDependencies ++= {
val liftVersion = "2.5"
Seq(... "mysql" % "mysql-connector-java" % "5.1.26" ...)
}
default.props
@lanceon
lanceon / sbt.bat
Created August 21, 2013 23:43
sbt.bat
@echo off
set SCRIPT_DIR=%~dp0
start "sbt-%CD%" java -Dfile.encoding=UTF-8 -Xms256M -Xmx1536M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=384M -Xss2M -Drebel.lift_plugin=true -javaagent:path-to-jrebel\jrebel.jar -jar "%SCRIPT_DIR%sbt-launch-0.12.4.jar" %*
@lanceon
lanceon / AjaxButtonWithConfirm.scala
Created August 23, 2013 14:24
Ajax button with JS confirmation
SHtml.ajaxButton("Delete", () => {
JsCmds.Confirm(("Delete?"), SHtml.ajaxInvoke( ()=>{
// ... served-side action ...
JsCmds.Noop
})._2.cmd)
}
)
@lanceon
lanceon / MappedFieldValidations.scala
Last active December 21, 2015 14:29
Custom validation functions for mapper field
class Test extends LongKeyedMapper[Test] ...
{
...
object data MappedString(this, 32) {
def validateFormat(s: String) =
if (s.matches("[a-z0-9_]+")) Nil
else List(FieldError(this, "Format is not valid!"))
@lanceon
lanceon / RuntimeStats.scala
Created August 24, 2013 14:51
Lift runtime stats snippet
/*
* Copyright 2007-2013 WorldWide Conferencing, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@lanceon
lanceon / web.xml
Created August 25, 2013 15:14
Prevent static file locking on Windows
<web-app>
<filter>
<filter-name>LiftFilter</filter-name>
<display-name>Lift Filter</display-name>
<description>The Filter that intercepts lift calls</description>
<filter-class>net.liftweb.http.LiftFilter</filter-class>
</filter>
<filter-mapping>
@lanceon
lanceon / idea64.exe.vmoptions
Last active December 22, 2015 19:09
Intellij IDEA 12 options
// H
-Xms256m
-Xmx3096m
-XX:MaxPermSize=384m
-XX:ReservedCodeCacheSize=128m
-XX:+UseCodeCacheFlushing
-ea
-Dsun.io.useCanonCaches=false
if (Props.devMode) autologinFunc = Full(autoLogin)
private def autoLogin() {
val u = User.findUserByUserName("dummy@altus-insight.de")
if (u.isDefined) logUserIn(u.get)
else debug("could not find dummy user for auto login. please create user ...@altus-insight.de")
}