This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Mixable | |
| @with: (classes...) -> | |
| for clazz in classes | |
| # add the class properties | |
| for key, value of clazz | |
| @[key] = value | |
| # add the instance (prototype) properties | |
| for key, value of clazz:: | |
| @::[key] = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package utils | |
| import javax.mail.internet.InternetAddress | |
| import javax.mail.util.ByteArrayDataSource | |
| import org.apache.commons.mail._ | |
| import scala.util.{Try, Failure, Success} | |
| import scala.concurrent.ExecutionContext | |
| import scala.concurrent.Future |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val locationReadsCreate = new Reads[(String, Option[String])] { | |
| def reads(json: JsValue) = { | |
| val subsidiary = (json \ "subsidiary").asOpt[String] | |
| val location = (json \ "location").asOpt[String] | |
| (subsidiary, location) match { | |
| case (None, _) => JsError(Seq(JsPath() \ "subsidiary" -> Seq(ValidationError("error.path.missing")))) | |
| case (Some("Autre"), None) => JsError(Seq(JsPath() \ "location" -> Seq(locationError))) | |
| case (Some("Autre"), loc @ Some(_)) => JsSuccess(("Autre", loc)) | |
| case (Some(sub), loc @ Some(_)) => JsError(Seq(JsPath() \ "location" -> Seq(locationError))) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var blob = new Blob(['foo, bar, baz'], {type: 'text/plain'}); | |
| var uri = URL.createObjectURL(blob); | |
| myAElement.download = 'myFileName.csv'; | |
| myAElement.href = uri; | |
| // when clicking on myAElement, it will download to the browser a file containing your string | |
| // see also: http://stackoverflow.com/a/19328891/1926897 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object Demo extends App { | |
| val formula = Add(Mult(X, Const(2)), Add(Const(-3), X)) | |
| val solutionDicho = Formula.solveForZeroDichotomy(formula) | |
| val solution = Formula.solve0(formula) | |
| println(s"$formula = 0 <=> X = $solution (dichotomy => $solutionDicho)") | |
| val fdiff = Add( Add(Mult(X,X), Mult(X, Const(2))), Const(-2) ) | |
| val extremum = Formula.solve0(fdiff.diff) | |
| println(s"Extremum of $fdiff => X = $extremum") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sealed trait IOToolResponse[+A] { | |
| def flatMap[B](f: A => IOToolResponse[B]): IOToolResponse[B] | |
| def map[B](f: A => B): IOToolResponse[B] = this.flatMap(a => IOToolResponse.unit(f(a))) | |
| } | |
| object IOToolResponse { | |
| def unit[A](a: A): IOToolResponse[A] = Authenticated(a) | |
| } | |
| case class Authenticated[A](data: A) extends IOToolResponse[A] { | |
| def flatMap[B](f: A => IOToolResponse[B]) = f(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.observe(model, function(changes){ | |
| changes.forEach(function(change) { | |
| // Troll observe | |
| console.log(change.type, change.name, change.oldValue); | |
| model[change.name] = change.oldValue; | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package controllers | |
| import scala.concurrent.Future | |
| import play.api._ | |
| import play.api.mvc._ | |
| object Application extends Controller { | |
| def index = Action { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| import atexit | |
| proc = subprocess.Popen("ping google.com", shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
| # register terminate function if python script is killed | |
| atexit.register(proc.terminate) | |
| for line in iter(proc.stdout.readline, ""): | |
| print "got line: '%s'" % line |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package play.api.mvc | |
| // needed to access protected method ActionRefiner#refine | |
| import scala.concurrent.Future | |
| import scala.language.higherKinds | |
| trait ActionPartial[R[_], P[_]] extends ActionRefiner[R, P] { self => | |
| def partial[A]: PartialFunction[R[A], Future[Either[Result, P[A]]]] | |
| def refine[A](request: R[A]): Future[Either[Result, P[A]]] = partial(request) |
OlderNewer