Skip to content

Instantly share code, notes, and snippets.

View pedrofurla's full-sized avatar

Pedro Furlanetto pedrofurla

View GitHub Profile
@pedrofurla
pedrofurla / gist:4631716
Created January 25, 2013 04:21
How to do have constant values in a insert, so it doesn't have to be provided in the insert invokation?
// It's a Table[(Int, Int, DATE)]
def autoInc = compilationId ~ creationDate returning id into {
case (tuple, id) => (id,tuple._1,tuple._2)
}
def autoInc2 = * returning id
// this is the work around. I don't want use session here.
def insertNewVersion(c:Compilation)(implicit session:Session) = autoInc.insert(c.id.get,newDate)._1
// what i want - my very wrong attempt
private ReadOnlyObjectWrapper<Status> statusPropertyImpl() {
if (this.status == null) {
this.status = new ReadOnlyObjectWrapper() {
protected void invalidated() {
if (get() == MediaPlayer.Status.PLAYING)
MediaPlayer.this.setCurrentRate(MediaPlayer.this.getRate());
else
MediaPlayer.this.setCurrentRate(0.0D);
}
dir=`dirname $0`
java -Xmx2048m -server -XX:MaxPermSize=1024m -Xss4M -jar $dir/sbt-launch-0.12.2.jar "$@"
@pedrofurla
pedrofurla / plugins.sbt
Created March 22, 2013 16:50
My Play Resolvers
resolvers ++= Seq(
"Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
"Typesafe Snapshots" at "http://repo.typesafe.com/typesafe/snapshots/",
Resolver.url(
"Typesafe Ivy Snapshots",
url("http://repo.typesafe.com/typesafe/ivy-snapshots/"))(Resolver.ivyStylePatterns),
Resolver.url(
"Typesafe Snapshots with ivy style",
url("http://repo.typesafe.com/typesafe/snapshots/"))(Resolver.ivyStylePatterns)
@pedrofurla
pedrofurla / gist:5898177
Created July 1, 2013 03:25
auto increment insert in slick. There must be better way.
def autoInc = * returning id.? into {
case (Person(_, a, b,c ,d), id) => Person(id, a, b, c, d)
}
def autoInc2 = fullName ~ birthday ~ login ~ password returning id.? into {
case (m, id) => Function.uncurried(((Person.apply _).curried(id))).tupled(m)
}
@pedrofurla
pedrofurla / gist:5915532
Created July 3, 2013 04:55
unfinished books slick example
package slickdemo.dal
import slickdemo.dal.DAL._
import dataLayer.profile.simple._
case class Book(id: PK, title: String, synopsis: String) {
def authors:List[Author] = ???
}
object Book {
def likeTitle(title:String):List[Book] = ???
package slickdemo
//import dal._
import dal.DAL._
import scala.slick.jdbc.SetParameter
import scala.slick.session.{PositionedResult, PositionedParameters}
//import dataLayer.profile.simple._
/**
@pedrofurla
pedrofurla / Macros.scala
Created July 13, 2013 06:14
Returns the line number where it was invoked
def line:Int = macro lineImpl
def lineImpl(c:Context) = {
import c.universe._
c.Expr[Int](Literal(Constant(c.enclosingPosition.line)))
}
@pedrofurla
pedrofurla / Macros.scala
Created July 13, 2013 06:19
source file
def source:String = macro sourceImpl
def sourceImpl(c:Context) = {
import c.universe._
c.Expr[String](Literal(Constant(c.enclosingUnit.source.file.canonicalPath)))
}
@pedrofurla
pedrofurla / gist:6044137
Last active December 20, 2015 00:49
This error occurs when trying to compile my source code with -Yrangepos. My source depends on Slick macro I will post the usage site below, links for the Slick source and the error.
My Source:
override def expr(n: Node, skipParens: Boolean = false) =
n match {
case Extract(n @ _*) =>
val datePart = n(1).asInstanceOf[LiteralNode].value.asInstanceOf[String]
b"""extract('${datePart}' from ${n(0)})"""
case _ => super.expr(n, skipParens)
}