Skip to content

Instantly share code, notes, and snippets.

Example table definitions & query:

case class House(id: Long, address: String)
case class Metro(id: Long, houseId: Long, name: String)
case class Room(id: Long, houseId: Long, area: Int)

object Houses extends Table[House]("Houses") {
  def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
  def address = column[String]("address")
@Rogach
Rogach / Declutter.scala
Created August 5, 2013 16:33
Phase for Slick, that unboxes wrapped tables
package scala.slick.compiler
import scala.slick.ast._
import scala.collection.mutable.HashMap
class Declutter extends Phase {
val name = "declutter"
def apply(tree: Node, state: CompilationState): Node = {
val replaced = new HashMap[Symbol, Symbol]
@Rogach
Rogach / toTree.hs
Last active December 15, 2015 00:19
Graph.toTree (haskell & scala)
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.List
import Text.Regex
import Control.Monad.State
import Control.Applicative
-- some setup for the types
type Graph a = Map.Map a [a]
data Tree a = Tree
@Rogach
Rogach / gist:4712253
Last active December 12, 2015 04:08
Scala-tuplicity proof :)
scala> (1 to 50).map(i => s"b$i:Int").mkString("case class A(", ", ", ")")
res0: String = case class A(b1:Int, b2:Int, b3:Int, b4:Int, b5:Int, b6:Int, b7:Int, b8:Int, b9:Int, b10:Int, b11:Int, b12:Int, b13:Int, b14:Int, b15:Int, b16:Int, b17:Int, b18:Int, b19:Int, b20:Int, b21:Int, b22:Int, b23:Int, b24:Int, b25:Int, b26:Int, b27:Int, b28:Int, b29:Int, b30:Int, b31:Int, b32:Int, b33:Int, b34:Int, b35:Int, b36:Int, b37:Int, b38:Int, b39:Int, b40:Int, b41:Int, b42:Int, b43:Int, b44:Int, b45:Int, b46:Int, b47:Int, b48:Int, b49:Int, b50:Int)
scala> case class A(b1:Int, b2:Int, b3:Int, b4:Int, b5:Int, b6:Int, b7:Int, b8:Int, b9:Int, b10:Int, b11:Int, b12:Int, b13:Int, b14:Int, b15:Int, b16:Int, b17:Int, b18:Int, b19:Int, b20:Int, b21:Int, b22:Int, b23:Int, b24:Int, b25:Int, b26:Int, b27:Int, b28:Int, b29:Int, b30:Int, b31:Int, b32:Int, b33:Int, b34:Int, b35:Int, b36:Int, b37:Int, b38:Int, b39:Int, b40:Int, b41:Int, b42:Int, b43:Int, b44:Int, b45:Int, b46:Int, b47:Int, b48:Int, b49:Int, b50:Int)
defined class A
s
@Rogach
Rogach / scala-tuplicity.sh
Last active December 12, 2015 04:08
Scala 2.10 with bigger tuples (the tuples in created dist are going up to 55 elements).
git clone git://github.com/scala/scala.git scala-tuplicity
cd scala-tuplicity
git checkout v2.10.0
export ANT_OPTS="-Xmx8192m -Xss25M -Xms4096M -XX:MaxPermSize=512M"
VERS="-Dbuild.release=true -Dversion.number=2.10.0-tuplicity -Dmaven.version.number=2.10.0-tuplicity"
ant build
sed -i 's/\(val MaxTupleArity, .*\) 22/\1 55/' src/reflect/scala/reflect/internal/Definitions.scala
ant build
sed -i 's/22/55/' src/library/scala/runtime/ScalaRunTime.scala
@Rogach
Rogach / gist:4546667
Last active December 11, 2015 04:39
Applying a list of functions to a case class
object ZipApply {
import shapeless._
import HList._
import Monoid._
implicit def ccMonoid[C, L <: HList](implicit iso : Iso[C, L], ml : Monoid[L]) = new Monoid[C] {
def zero = iso.from(ml.zero)
def append(a : C, b : C) = iso.from(iso.to(a) |+| iso.to(b))
}
@Rogach
Rogach / gist:3801267
Created September 28, 2012 17:55
Bigger scala tuples
git clone git://github.com/scala/scala.git scala-tuplicity
cd scala-tuplicity
git checkout v2.9.2
export ANT_OPTS="-Xmx8192m -Xss25M -Xms4096M -XX:MaxPermSize=512M"
VERS="-Dbuild.release=true -Dversion.number=2.9.2-tuplicity -Dmaven.version.number=2.9.2-tuplicity"
ant build
sed -i 's/\(val MaxTupleArity, .*\) 22/\1 222/' src/compiler/scala/tools/nsc/symtab/Definitions.scala
ant build
ant replacelocker
sed -i 's/\(MAX_ARITY .*\) 22/\1 222/' src/build/genprod.scala
@Rogach
Rogach / Simple.scala
Created September 18, 2012 08:07
File to test highlighting upon
package simple
package even.simpler
import scala.collection._
import scala.util.{Random => Rnd}
import scala.collection.mutable.Map
object Simple {
type TP = Seq[String]
@Rogach
Rogach / SlidingWindowMap.scala
Created September 3, 2012 03:51
SlidingWindowMap
class SlidingWindowMap(keys: Set[String], maxCount: Int, periodMs: Int) {
val times = collection.mutable.Map(keys.map(k => (k, Vector[Long]())).toList:_*)
def nextKey: Option[String] = {
val now = System.currentTimeMillis
this.synchronized {
val key = times.find(_._2.dropWhile(_ < now - periodMs).size < maxCount).map(_._1)
key.foreach { k => times(k) = times(k).dropWhile(_ < now - periodMs) :+ now }
key
}
}
@Rogach
Rogach / assoc.bat
Created June 19, 2012 14:24
java applet file assoc
assoc .svg=SvgGraphicsFile
ftype SvgGraphicsFile=C:\Program Files\Internet Explorer\iexplore.exe "www.someplace.ru/index.html?file=" "%1"