Skip to content

Instantly share code, notes, and snippets.

View gbougeard's full-sized avatar

Greg BOUGEARD gbougeard

View GitHub Profile
@cvogt
cvogt / gist:9239494
Last active September 9, 2019 01:30
Slick app architecture 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
@cvogt
cvogt / gist:9193220
Last active February 13, 2022 13:50 — forked from ruescasd/gist:7911033
Slick: Dynamic query conditions using the **MaybeFilter** (Updated to support nullable columns)
import scala.slick.lifted.CanBeQueryCondition
// optionally filter on a column with a supplied predicate
case class MaybeFilter[X, Y](val query: scala.slick.lifted.Query[X, Y]) {
def filter[T,R:CanBeQueryCondition](data: Option[T])(f: T => X => R) = {
data.map(v => MaybeFilter(query.filter(f(v)))).getOrElse(this)
}
}
// example use case
import java.sql.Date
@heathermiller
heathermiller / gist:9158658
Last active December 11, 2018 06:35
A more beautiful Terminal experience.

A nicer Terminal experience.

Just add the following to your bash profile.

export PS1='\[\033[38;5;202;48;5;0m\]⏣ \[\033[38;5;134;48;5;0m\]\w \[\033[38;5;112;48;5;0m\]`git branch 2> /dev/null | grep -e ^* | sed -E  s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`\[\033[00m\]'

(The green bit there is the current branch you're on if you're in a directory that has a git repository within it)

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@loicdescotte
loicdescotte / streamFile.md
Last active September 15, 2017 09:17
Stream and transform file with Play

Chunck by chunk

def  transform = Action {
    
     val fileStream: Enumerator[Array[Byte]] = {
         Enumerator.fromFile(new File("data.txt"))
     }
     
     val transfo = Enumeratee.map[Array[Byte]]{byteArray =>  
@jessitron
jessitron / gist:8376139
Created January 11, 2014 20:15
scala: print all URLs on classpath
def urlses(cl: ClassLoader): Array[java.net.URL] = cl match {
case null => Array()
case u: java.net.URLClassLoader => u.getURLs() ++ urlses(cl.getParent)
case _ => urlses(cl.getParent)
}
val urls = urlses(getClass.getClassLoader)
println(urls.filterNot(_.toString.contains("ivy")).mkString("\n")
@simonbrandhof
simonbrandhof / gist:7914401
Last active December 31, 2015 01:29
Quality profile used for the Java sources of SonarQube project. Note that some rules added in versions 4.0 or 4.1 are probably enabled. This file can be imported via the top-right link "Restore Profile" of the page "Quality Profiles".
<?xml version="1.0" encoding="UTF-8"?>
<profile><name>Default</name><language>java</language><rules><rule><repositoryKey>squid</repositoryKey><key>S1223</key><priority>MAJOR</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1318</key><priority>CRITICAL</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1312</key><priority>MAJOR</priority><parameters><parameter><key>format</key><value>LOG(?:GER)?</value></parameter></parameters></rule><rule><repositoryKey>squid</repositoryKey><key>S1319</key><priority>MAJOR</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1231</key><priority>MINOR</priority></rule><rule><repositoryKey>pmd</repositoryKey><key>CompareObjectsWithEquals</key><priority>MAJOR</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1217</key><priority>CRITICAL</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1219</key><priority>CRITICAL</priority></rule><rule><repositoryKey>squid</repositoryKey><key>S1210</key><priority>CRITICAL</p
@helena
helena / CloudExtension.scala
Last active December 21, 2015 00:29
Simple (and truncated) example of the CloudExtension's load-time ordered provisioning and ordered graceful shutdown. Unfortunately this had to be written in an older version of scala and akka - for now. MyNodeGuardian.scala is started in CloudExtension.register() and is a sample of using ProvisioningGuardian which extends OrderedGracefulShutdown.
/**
* CloudExtension and factory for creating CloudExtension instances.
* Example:
* {{{
* val application = CloudExtension(system, config)
* }}}
*
* @author Helena Edelson
*/
object CloudExtension extends ExtensionId[CloudExtension] with ExtensionIdProvider {
@mandubian
mandubian / gist:5231877
Last active December 15, 2015 08:38
Play Framework Json sample: Copy JsObject only if passwords equal
import play.api.libs.json._
import play.api.data.validation._
import play.api.libs.functional.syntax._
val json = Json.obj(
"name" -> "John",
"email" -> "john.doe@company.com",
"password" -> "password",
"confirmPassword" -> "password"
)
@leon
leon / SlickUserService.scala
Created March 12, 2013 07:55
Secure Social UserService Slick implementation (Not Working)
package service
import play.api._
import securesocial.core._
import securesocial.core.providers.Token
import securesocial.core.UserId
import models._
class SlickUserService(application: Application) extends UserServicePlugin(application) {