This file contains 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 scalaz.{Tag, @@} | |
trait EmailAddress | |
implicit def EmailAddress(str: String): String @@ EmailAddress = { | |
require(str.matches("[^@]+@.*"), "String is not an email") | |
// ^ Over simplified email regex, I know. | |
// Also it should be defined elsewhere so it's not compiled everytime. I know. This is just an example :) | |
Tag[String,EmailAddress](str) | |
} |
This file contains 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
def validate(data: T)(onSuccess: T => Either[BadRequest, T]): Either[BadRequest, T] = | |
validateCreateData(data) match { | |
case Right(sanitizedData) => onSuccess(sanitizedData) | |
case fail: Left => fail | |
} |
This file contains 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
implicit class PimpedListOfEither[A,B](list: List[Either[A,B]]) { | |
def tupled = { | |
@tailrec | |
def traverseList(curList: List[Either[A,B]], transformedList: (List[A], List[B]) = (List.empty[A], List.empty[B])): (List[A], List[B]) = { | |
traverseList( | |
curList.tail, | |
curList.headOption map { | |
case Left(a) => (a :: transformedList._1, transformedList._2) | |
case Right(b) => (transformedList._1, b :: transformedList._2) | |
} getOrElse transformedList) |
This file contains 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 scala.annotation.tailrec | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration._ | |
import scala.util.Try | |
object Main extends App { | |
import scala.concurrent.ExecutionContext.Implicits.global |
This file contains 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
[error] Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.AbstractMethodError: com.badlogic.gdx.backends.lwjgl.LwjglGL30.glGenBuffer()I | |
[error] at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120) | |
[error] Caused by: java.lang.AbstractMethodError: com.badlogic.gdx.backends.lwjgl.LwjglGL30.glGenBuffer()I | |
[error] at com.badlogic.gdx.graphics.glutils.VertexBufferObject.<init>(VertexBufferObject.java:83) | |
[error] at com.badlogic.gdx.graphics.glutils.VertexBufferObject.<init>(VertexBufferObject.java:67) | |
[error] at com.badlogic.gdx.graphics.Mesh.<init>(Mesh.java:95) | |
[error] at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.<init>(ImmediateModeRenderer20.java:66) | |
[error] at com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20.<init>(ImmediateModeRenderer20.java:56) | |
[error] at com.badlogic.gdx.graphics.glutils.ShapeRenderer.<init>(ShapeRenderer.java:116) | |
[error] at com.badlogic.gdx.graphics.glutils.ShapeRenderer.<init>(S |
This file contains 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 bodies: ListBuffer[Body] | |
def gravitate(): Unit = { | |
val length = bodies.length | |
for { | |
i <- 0 until length | |
bodyA <- bodies(i) | |
j <- (i+1) until length | |
bodyB <- bodies(j) | |
} yield { |
This file contains 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
ArrayList<Body> bodies = new ArrayList<Body>; | |
Float gravitationalConstant = 0.0001f; | |
public void gravitate() { | |
int length = bodies.length; | |
for (int i=0; i < length; i++){ | |
Body bodyA = bodies.get(i); | |
for (int j=i+1; j < length; j++) { | |
Body bodyB = bodies.get(j); | |
This file contains 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 tables | |
import models.Cat | |
import slick.driver.JdbcProfile | |
class CatTable(driver: JdbcProfile) { | |
import driver.api._ | |
class Cats(tag: Tag) extends Table[Cat](tag, "CAT") { | |
def name = column[String]("NAME", O.PrimaryKey) |
This file contains 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
case class Supplier(id: Int, name: String, street: String, city: String, state: String, zip: String) | |
object ExampleDatastore extends H2Datastore(mode = H2Memory("example"), columnNameAdapter = SnakeUpperCaseAdapter) { | |
object suppliers extends Table("SUPPLIERS", classOf[Supplier]) | |
} |
This file contains 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 models.dao | |
import scala.concurrent.ExecutionContext | |
import scala.concurrent.Future | |
import play.api.Play.current | |
import play.modules.reactivemongo.ReactiveMongoPlugin | |
import reactivemongo.api.collections.default.BSONCollection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONDocumentIdentity |