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
(declare dbg-req) | |
(declare dbg-resp) | |
(defn bind-req-resp [handler re-pattern] | |
(fn [req] | |
(if (re-matches re-pattern (:uri req)) | |
(do | |
(alter-var-root (var dbg-req) (constantly req)) | |
(let [resp (handler req)] | |
(alter-var-root (var dbg-resp) (constantly resp)) |
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 _; | |
import org.joda.time.DateTime; | |
import org.joda.time.DateTimeZone; | |
import org.joda.time.format.ISODateTimeFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.TimeZone; |
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
; Mobile browser detection based on the JSP code at http://detectmobilebrowsers.com/ | |
(defn mobile-browser? [req] | |
(if-let [agent (get-in req [:headers "user-agent"])] | |
(let [agent (.toLowerCase agent)] | |
(or | |
(re-matches (Pattern/compile (str "(?i).*((android|bb\\\\d+|meego)" | |
".+mobile|avantgo|bada\\\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)" | |
"|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)" | |
"\\\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\\\.(browser|link)|vodafone|wap|windows ce|xda|xiino).*")) |
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
// Will tag an push if the property 'dockerRepository' is defined | |
task buildDocker(type: Docker) { | |
push = false | |
applicationName = 'curriculi-service-users' | |
dockerfile = file('src/main/docker/Dockerfile') | |
doFirst { | |
copy { | |
from jar |
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 getDates(product: String): Future[Either[String, List[LocalDate]]] = product match { | |
case "fast" => Future.successful(Right(List(LocalDate.parse("2018-03-09"), LocalDate.parse("2018-03-10")))) | |
case "slow" => Future.successful(Right(List(LocalDate.parse("2018-03-07"), LocalDate.parse("2018-03-08")))) | |
case "express" => Future.successful(Left("Service not available")) | |
case "flash" => Future.failed(new Throwable("haha")) | |
} |
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 getAllDatesScala(products: List[String]) = { | |
val futureAllDates = Future.sequence(products.map(p ⇒ getDates(p))) | |
futureAllDates.map(l ⇒ | |
if (l.exists(_.isLeft)) | |
None | |
else | |
Some(l.foldLeft(List[LocalDate]())((acc, e) => | |
e match { | |
case Left(_) => acc | |
case Right(l) => acc ++ l |
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 getAllDatesCats(products: List[String]) = { | |
val futureAllDates = Future.sequence(products.map(p ⇒ getDates(p))) | |
futureAllDates.map(l ⇒ l.combineAll.toOption) | |
} |
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
trait Semigroup[A] { | |
def combine(x: A, y: A): A | |
} | |
trait Monoid[A] extends Semigroup[A] { | |
def zero: A | |
} | |
// Laws: | |
//Associativity |
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 volume( box: Box) = for { | |
width <- box.width | |
length <- box.length | |
height <- box.height | |
} yield width * height * length |
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 volume(box: Box) = (box.width, box.length, box.height).mapN( _ * _ * _) |
OlderNewer