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
/** | |
* Example of a custom implementation of Stripe Checkout | |
* | |
* https://stripe.com/docs/checkout#integration-custom | |
* | |
* @author Riccardo Sirigu | |
*/ | |
class StripeInjector { |
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
object jwtClaims extends TransientRequestVar[Option[String]](Empty) | |
case class JWTAuthentication(realmName: String)(func: PartialFunction[(String, Req), Boolean]) extends HttpAuthentication { | |
//Take the JWT from the Authorization header | |
def credentials(r: Req): Box[String] = { | |
header(r).flatMap{ token => | |
if (Jwt.isValid(sanitizeHeader(token), secret, Seq(JwtAlgorithm.HS256))) { | |
Jwt.decode(sanitizeHeader(token), secret, Seq(JwtAlgorithm.HS256)) match { |
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
/** | |
* Created by Riccardo Sirigu on 30/06/17. | |
*/ | |
object AsyncRestExample extends RestHelper{ | |
serve{ | |
case "async" :: Nil JsonGet _ => | |
val mainThreadName = Thread.currentThread.getName | |
RestContinuation.async{ reply => | |
val backgroundThreadName = Thread.currentThread.getName |
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
// Type Class example with Type Enrichment | |
case class Picture(name: String, uri: String) | |
case class Attachment(name: String, uri: String, visible: Boolean) | |
trait JsonWriter[T]{ | |
def toJson(in: T): String | |
} |
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 Jsonable{ | |
def toJson: String | |
} | |
case class Picture(name: String, uri: String) extends Jsonable{ | |
override def toJson = s"picture ${name}" | |
} | |
case class Attachment(name: String, uri: String, visible: Boolean) extends Jsonable{ | |
override def toJson = s"attachment ${name}" |
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
//Type class pattern example in Scala, to achieve ad hoc polymorphism | |
case class Picture(name: String, uri: String) | |
case class Attachment(name: String, uri: String, visible: Boolean) | |
trait JsonSerializer[T]{ | |
def toJson(in: T): String | |
} |
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] Clippy advises: did you forget to define an implicit akka.stream.ActorMaterializer? | |
[error] It allows routes to be converted into a flow. | |
[error] You can read more at http://doc.akka.io/docs/akka-stream-and-http-experimental/2.0/scala/http/routing-dsl/index.html |
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
class ConditionalRendering{ | |
def render: (NodeSeq) => NodeSeq = { | |
"#content-container" #> {if(trueness) PassThru else ClearNodes} andThen | |
"#inclusions" #> {".inclusions-text *" #> { List("food", "drinks") } } | |
} | |
} |
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 code.snippet | |
import net.liftweb.http.SHtml | |
import net.liftweb.http.SHtml.SelectableOption | |
import net.liftweb.http.js.JsCmd | |
import net.liftweb.http.js.JsCmds.Alert | |
import net.liftweb.util.Helpers._ | |
/** | |
* Created by Riccardo Sirigu on 11/11/2016. |
NewerOlder