Skip to content

Instantly share code, notes, and snippets.

@freekh
freekh / Emscripten.scala
Created December 3, 2013 13:11
Emscripten 002
import sbt._
import sbt.Keys._
import java.io.File
import play.Keys._
import play.PlayExceptions._
import play.PlaySourceGenerators
object EmscriptenKeys {
val eccFiles = taskKey[PathFinder]("C/C++ files to be compiled")
val eccCompiler = settingKey[String]("Path to Emscripten compiler")
@freekh
freekh / Emscripten.scala
Created December 3, 2013 13:12
Emscripten 003
import sbt._
import sbt.Keys._
import java.io.File
import play.Keys._
import play.PlayExceptions._
import play.PlaySourceGenerators
object EmscriptenKeys {
val eccFiles = taskKey[PathFinder]("C/C++ files to be compiled")
val eccCompiler = settingKey[String]("Path to Emscripten compiler")
@freekh
freekh / Emscripten.scala
Created December 3, 2013 13:12
Emscripten 004
import sbt._
import sbt.Keys._
import java.io.File
import play.Keys._
import play.PlayExceptions._
import play.PlaySourceGenerators
object EmscriptenKeys {
val eccFiles = taskKey[PathFinder]("C/C++ files to be compiled")
val eccCompiler = settingKey[String]("Path to Emscripten compiler")
@freekh
freekh / EmscriptenCompiler.scala
Created December 3, 2013 13:13
Emscripten (Naive) Compiler
import java.io.File
case class EmscriptenCompilerException(filename: String, lineNo: Option[Int], colNo: Option[Int], msg: String) extends Exception
class EmscriptenCompiler(eccCompiler: String) {
private val compilerString = eccCompiler + " "
val ErrorLine = """(.*?):(\d+):(\d+): error: (.*?)""".r
@freekh
freekh / AdeptExample.scala
Created December 19, 2013 22:06
Example of Adept API usage: initialises and resolves some dependencies (requirements), downloads the jars needed then publishes
val standardProgressIndicator = new adept.progress.default.AllEncompassingProgress(System.out)
val repo1: RepositoryRef = GitRepository.init(Adept.HOME_DIR, "one") //init new adept repository in HOME_DIR/one
val repo2: RepositoryRef = GitRepository.open(Adept.HOME_DIR, "two") //open adept repository in HOME_DIR/two
val repo3: RepositoryRef = GitRepository.clone(Adept.HOME_DIR, "three", "git://server/project.git", standardProgressIndicator) //clone remote to HOME_DIR/three from git using the standard progress indicator
// Can also do: repo3.isFailure() //returns true if repo3 failed to init/open/clone
// And: repo1.addRemote("git://server2/project.git") //adds a new remote just for fun
val adept: Adept = new Adept(repo1, repo2, repo3) //a single instance that manages all repositories
@freekh
freekh / gist:8059708
Created December 20, 2013 19:02
Adept plan
SBT projects and packages:
adept-hash (merge with core?)
- adept.hash (Hashing object with (static) methods used to generate hashes. Hashes are generated from strings)
adept-core
- adept.variant.models (Variant, Id, Attribute, ArtifactRef, Requirement (dependency))
- adept.variant.models.constraints (Constraint base class + EqualConstraint and IdConstraint (TODO) )
- adept.variant.ordering (Ordering implicits. Used to generate the same ordered Seq(uences) from unordered Set(s))
@freekh
freekh / AdeptExample.scala
Created December 20, 2013 19:22
Example code, resolve a project, then publish a new one:
val standardProgressIndicator = new adept.progress.default.AllEncompassingProgress(System.out)
// the repo we will publish to
val projectRepo = if (GitRepository.exists(Adept.HOME_DIR, projectName)) GitRepository.open(Adept.HOME_DIR, projectName) else GitRepository.init(Adept.HOME_DIR, projectName)
val repo1: RepositoryRef = GitRepository.init(Adept.HOME_DIR, "one") //init new adept repository in HOME_DIR/one
val repo2: RepositoryRef = GitRepository.open(Adept.HOME_DIR, "two") //open adept repository in HOME_DIR/two at HEAD
val repo3: RepositoryRef = GitRepository.clone(Adept.HOME_DIR, "three", "git://server/project.git", standardProgressIndicator) //clone remote to HOME_DIR/three from git using the standard progress indicator
// Can also do: repo3.isFailure() //returns true if repo3 failed to init/open/clone
@freekh
freekh / gist:8973256
Created February 13, 2014 11:03
Very first successful end-to-end resolution of ivy import data in Adept
> adept set com.typesafe.play/play
Resolved (2227ms)
> adept graph
- com.typesafe.play/play/config/compile [organization=(com.typesafe.play),name=(play_2.10),version=(2.2.0)]
- joda-time/joda-time/config/compile [organization=(joda-time),name=(joda-time),version=(2.2)]
- joda-time/joda-time <defined>
- com.fasterxml.jackson.core/jackson-core/config/compile [organization=(com.fasterxml.jackson.core),name=(jackson-core),version=(2.2.2)]
- com.fasterxml.jackson.core/jackson-core <defined>
- oauth.signpost/signpost-commonshttp4/config/master [organization=(oauth.signpost),name=(signpost-commonshttp4),version=(1.2.1.2)]
- oauth.signpost/signpost-commonshttp4 [organization=(oauth.signpost),name=(signpost-commonshttp4),version=(1.2.1.2),configuration-hash=(1e39682502e773549f42391188d3120d7f46cc942b15cfa6ae8e35d9c0612c92)]
@freekh
freekh / gist:9132313
Last active May 15, 2017 10:48
Async play form
package controllers
import play.api._
import play.api.mvc._
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.format.Formats._
import models.Credential
import views.html.defaultpages.unauthorized
import scala.concurrent.Await
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.json.JsValue
import play.api.data.Form
import play.api.data.Forms._
import play.api.data.format.Formats._
import play.api.data.validation.Constraints._
import models.Credential