Skip to content

Instantly share code, notes, and snippets.

View lanceon's full-sized avatar

Oleksiy lanceon

View GitHub Profile
@lanceon
lanceon / recursion.scala
Created September 19, 2013 01:41
Scala recursive factorial calculation
package examples
import scala.annotation.tailrec
object fact {
// see: http://stackoverflow.com/questions/1025181/hidden-features-of-scala/4027156#4027156
def timed[T](thunk: => T) = {
val t1 = System.nanoTime
val ret = thunk
@lanceon
lanceon / classvals.scala
Created September 23, 2013 09:51
Initializing vals in Scala - Lift pattern
/*
dpp: The way I do it in Lift is as follows:
http://scala-programming-language.1934581.n4.nabble.com/scala-Work-around-for-super-references-to-vals-td2000298.html
*/
class Foo { lazy val x = _x ; protected def _x = 1 }
class Bar extends Foo { protected override def _x = super._x + 1 }
(new Bar).x // 2
@lanceon
lanceon / template.html
Created September 23, 2013 16:44
Lift snippet eager evaluation syntax with data-lift attribute
<div data-lift="TestSnippet.methodName?eager_eval=true">
<div data-lift="embed?what=/templates-hidden/my-template"></div>
</div>
@lanceon
lanceon / Access.scala
Created November 19, 2013 13:09
Scala member access modifiers test
class Super {
val public_ = "public"
protected val protected_ = "protected"
private val private_ = "private"
protected[Super] val protected_super = "ps"
protected[this] val protected_this = "pt"
// Import the magic libraries
import scala.xml._
import scala.xml.transform._
// Source xml. In Scala, xml is literal.
val xml =
<user>
<email>joe@example.com</email>
@lanceon
lanceon / jqtree.js
Created May 1, 2014 18:59
jqTree - collapse/expand tree
var $tree = $('#tree1');
$('#collapse').click(function() {
var tree = $tree.tree('getTree');
tree.iterate(function(node) {
if (node.hasChildren()) {
$tree.tree('closeNode', node, true);
}
return true;
});
@lanceon
lanceon / start.cmd
Created May 30, 2014 15:31
Apache Directory Studio with JVM6
"Apache Directory Studio.exe" -vm "C:\Program Files (x86)\Java\jre7\bin\java.exe"
@lanceon
lanceon / gist:81828065159826781795
Last active August 3, 2022 07:47 — forked from cvogt/gist:9239494
Slick cheat sheet
// Please comment in case of typos or bugs
import scala.slick.driver.H2Driver._
val db = Database.for...(...)
case class Record( ... )
class Records(tag: Tag) extends Table[Record](tag,"RECORDS"){
...
def * = ... <> (Record.tupled,Record.unapply)
// place additional methods here which return values of type Column
@lanceon
lanceon / Tailrec.scala
Last active August 29, 2015 14:06
Compiled and decompiled scala recursive methods with and without @tailrec annotation
package main
import scala.annotation.tailrec
class Tailrec {
def tail1(i: Int): Int = {
if (i >= 10) i
else tail1(i+1)
}
@lanceon
lanceon / Projections.scala
Last active August 29, 2015 14:06
Slick projections/mappings
case class Emp(id: Long,
firstName: Option[String],
lastName: Option[String])
case class EmpProj(id: Column[Long],
firstName: Column[Option[String]],
lastName: Column[Option[String]])
implicit object EmpShape extends CaseClassShape(EmpProj.tupled, Emp.tupled)