Skip to content

Instantly share code, notes, and snippets.

View mathieuancelin's full-sized avatar

Mathieu ANCELIN mathieuancelin

View GitHub Profile
trait FormUtils {
def FormAction(form: Form[User])(block: (User) => SimpleResult): EssentialAction = {
Action { request =>
form.bindFromRequest()(request).fold(
errors => BadRequest(errors),
user => block(user)
)
}
}
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 Association du Paris Java User Group.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
package controllers
import play.api.mvc.{Action, Controller}
import play.api.libs.iteratee.{Enumeratee, Enumerator, Concurrent}
import play.api.libs.ws.WS.WSRequestHolder
import play.api.http.{ContentTypeOf, Writeable}
import play.api.libs.ws.WS
import java.net.URLEncoder
import play.api.libs.oauth.OAuthCalculator
import play.api.libs.json.{JsValue, Json}
import scala.util.control.NoStackTrace
package object FlatFuture {
case object EmptyOption extends RuntimeException("Current option is empty :'(") with NoStackTrace
implicit final class futureOfOptionToFuture[A](future: Future[Option[A]]) {
def flatten(implicit ec: ExecutionContext): Future[A] = {
future.flatMap {
case Some(something) => Future.successful(something)
package controllers
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.libs.json._
import play.api.libs.ws._
import play.api.mvc._
import play.api.libs._
import play.api.libs.iteratee._
import play.Play
package fwk
import scala.concurrent.{Future, ExecutionContext}
import play.api.libs.json.{JsUndefined, Json, JsObject, Format}
import play.modules.reactivemongo.json.collection.JSONCollection
import reactivemongo.bson.BSONObjectID
import reactivemongo.core.commands.LastError
import play.modules.reactivemongo.ReactiveMongoPlugin
import play.modules.reactivemongo.json.BSONFormats._
import org.reactivecouchbase.ReactiveCouchbaseDriver
import scala.concurrent.Future
import play.api.libs.json._
object Application extends App {
val driver = ReactiveCouchbaseDriver()
val bucket = driver.bucket("default")
implicit val ec = ExecutionContext.fromExecutor(Executors.newSingleThreadExecutor())
implicit val keys = Seq("key-1", "key-2", "key-3")
@mathieuancelin
mathieuancelin / Component.js
Last active August 29, 2015 14:09
Experiments with mithril.js
var Component = Component || (function() {
return {
create: function(initial, init, render) {
var ctrl = {};
if (initial && !init && !render) {
ctrl = initial; // object oriented construction, other are closure oriented construction
} else if (initial && init && !render && _.isFunction(initial)) {
ctrl.initialState = initial();
ctrl.render = init;
} else if (initial && init && !render && !_.isFunction(initial)) {
@mathieuancelin
mathieuancelin / Elem.js
Last active August 29, 2015 14:10
No more string concat. Need jquery, underscore.js and sugar.js
var Elem = Elem || {};
(function(exports) {
function styleToString(attrs) {
if (_.isUndefined(attrs)) return '';
var attrsArray = _.map(_.keys(attrs), function(key) {
var keyName = key.dasherize();
if (key === 'className') {
keyName = 'class';
}
@mathieuancelin
mathieuancelin / answer.md
Last active August 29, 2015 14:10
Issue with UI events when rendering React component inside WebComponent

And the aswer is ...

because of the way Shadow DOM is handling events, React does not attach its listener on the right container (it attaches the listener on the owner document of the container instead of the container itself).

A pending PR will fix this behavior : facebook/react#1877 by patching src/browser/ui/ReactDOMComponent.js like the following :

-    var doc = container.nodeType === ELEMENT_NODE_TYPE ?
- container.ownerDocument :