Skip to content

Instantly share code, notes, and snippets.

@julienrf
julienrf / foo.tmpl
Created December 1, 2011 15:11
forest
{* Example of template processing an article *}
{article: Article}
li class="article {article.featured ? 'featured'}" /view.root
a href="/details"
| {article.name} /data.name
span.actions
button type=button /view.editBtn | Edit
button type=button /view.deleteBtn | Delete
@julienrf
julienrf / implementation.scala
Created December 3, 2011 15:08
Querying JSON
package jsonquery
object `package` {
import dispatch.json._
implicit def jsonToSearchable(json: JsValue) = new {
def \ (selector: String): Either[String, JsValue] = json match {
case JsObject(map) => {
(for {
@julienrf
julienrf / JFunction1.java
Created December 3, 2011 17:55
Using scala.Function1 from Java
package lambda;
public interface JFunction1<T1, R> {
R apply(T1 t);
}
@julienrf
julienrf / reader.hs
Created December 8, 2011 21:00 — forked from paul-r-ml/reader-applicative-monadic.rb
simple reader monad
-- Un type qui sera une instance de Monad. Il s'agit d'un simple
-- conteneur pour les fonctions d'un environnement vers un résultat.
newtype Reader env res = Reader (env -> res)
-- Une fonction qui prend un Reader et un environnement, et qui
-- renvoit le résultat
runReader :: Reader env res -> env -> res
runReader (Reader f) e = f e
-- La fameuse instance de Monad. return ignore son environnement,
@julienrf
julienrf / Application.scala
Last active October 1, 2015 04:18
Composite UI without boilerplate using Play 2
object Application extends Controller {
val index = Action { implicit request =>
Ok(views.html.index())
}
val show = Action { implicit request =>
Ok(views.html.show("42"))
}
@julienrf
julienrf / Action.scala
Created April 9, 2012 16:20
How to implement a custom PathBindable with Play 2
def show(article: Article) = Action {
Ok(views.html.article(article))
}
object Application extends Controller with PathLang {
def index = Ok(html.index())
}
scala> trait Foo[+A]
defined trait Foo
scala> implicit object intFoo extends Foo[Int]
defined module intFoo
scala> implicit def traversableFoo[F[_], A](implicit bf: collection.generic.CanBuildFrom[F[_], A, F[A]], aFoo: Foo[A]) = new Foo[F[A]] {}
traversableFoo: [F[_], A](implicit bf: scala.collection.generic.CanBuildFrom[F[_],A,F[A]], implicit aFoo: Foo[A])java.lang.Object with Foo[F[A]]
scala> implicitly[Foo[List[Int]]]
@julienrf
julienrf / Application.scala
Created April 26, 2012 20:47
Write a Mapping[A] and get a QueryStringBindable[A] for free
// --- Definition of a query string binder for type A using a Mapping[A]
object Binders {
implicit def mappingBinder[A](implicit mapping: Mapping[A]) = new QueryStringBindable[A] {
override def bind(key: String, params: Map[String, Seq[String]]): Option[Either[String, A]] = {
val data = for {
(k, ps) <- params
if k startsWith key
p <- ps.headOption
} yield (k.drop(key.length + 1), p)
@julienrf
julienrf / Contact.scala
Created September 12, 2012 12:23
A bottom up approach to category theory: Functors
case class Contact(name: String, email: String)