Skip to content

Instantly share code, notes, and snippets.

/**
* Created by pedrofurla on 26/03/14.
*/
package slicks.docs
import slicks.docs.dao.{Entity, IdentifiableTable, CrudComponent, Profile}
case class User(id: Option[Long], first: String, last: String) extends Entity[Long]
trait UserComponent extends CrudComponent { outer: Profile =>
@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

Hi, looking for scalac flags?

This gist has been upgraded to a blog post here.

@bhollis
bhollis / blog.js.coffee
Last active July 17, 2021 08:05
A simple, made-up example of the code for a simple AngularJS blog viewer as a more detailed exploration of http://benhollis.net/blog/2014/01/17/cleanly-declaring-angularjs-services-with-coffeescript/ . Yes, I know about `$resource`, but I prefer not to use it.
app = angular.module 'BlogExample', []
# Simple controller that loads all blog posts
app.controller 'BlogCtrl', ['$scope', 'Blog', ($scope, Blog) ->
# Get all the blog posts
Blog.all().then (posts) ->
$scope.posts = posts
# Extend the $scope with our own properties, all in one big block
# I like this because it looks like declaring a class.
@beschauer
beschauer / Build.scala
Last active December 26, 2015 04:48
Resource Versioning, Cache Busting, Fingerprinting with Playframework 2.1 All resources that are normally located under /assets/xxx now live under /assets/[VERSION]/xxx
import com.typesafe.config.ConfigFactory
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val conf = ConfigFactory.parseFile(new File("conf/application.conf")).resolve()
val appVersion = conf.getString("application.version")
import scala.slick.driver.JdbcProfile
import scala.slick.ast.BaseTypedType
trait Profile {
val profile: JdbcProfile
}
trait TableComponent extends Profile {
import profile.simple._
trait TypedId{ def id:Long }
trait Entity[ID]{
def id : Option[ID]
@mikefowler
mikefowler / StartView.js.coffee
Created December 28, 2012 02:56
Defining RequireJS modules + Coffeescript classes with the RequireJS sugar syntax. More detail here: http://requirejs.org/docs/whyamd.html#sugar
define (require) ->
$ = require 'jquery'
_ = require 'underscore'
Backbone = require 'backbone'
Handlebars = require 'handlebars'
View = require 'lib/view'
startTemplate = require 'text!templates/start.html'
class StartView extends View
@timothyklim
timothyklim / Application.scala
Created June 12, 2012 17:22
After I talked with co-author of play with topic subdomains, I was a little bit confused. My current framework doesn't support my thoughts and I was started write some code!
// app/controllers/Application.scala
trait SubdomainController extends Controller {
def WithSubdomain(f: => String => Request[AnyContent] => Result) = Action { implicit request =>
val splitDomain = request.domain.split("\\.")
if (splitDomain.length < 2) {
BadRequest("Domain not found!")
} else {
f(splitDomain.head)(request)
@guillaumebort
guillaumebort / 1.sql
Created May 25, 2012 15:17
Play 2.0/Anorm
# --- !Ups
CREATE TABLE users(
email VARCHAR(255) NOT NULL PRIMARY KEY,
name VARCHAR(255)
);
CREATE TABLE subjects(
id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
title LONGTEXT NOT NULL,
@benmccann
benmccann / SchemaGen.java
Created March 16, 2012 04:24
Liquibase integration for Play 2.0
package com.benmccann.example.schema;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URL;
import java.util.Arrays;