Skip to content

Instantly share code, notes, and snippets.

View ricsirigu's full-sized avatar
👨‍💻
explo[r|it]ing

Riccardo Sirigu ricsirigu

👨‍💻
explo[r|it]ing
View GitHub Profile
@ricsirigu
ricsirigu / DynamicSelect.scala
Last active November 12, 2016 19:44
An example with the Lift framework on how to dynamically load the content of a select according to the value of another one.
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.
@ricsirigu
ricsirigu / clippy-error.scala
Created February 17, 2017 10:52
Scala clippy
[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
@ricsirigu
ricsirigu / typeclassExample.scala
Last active June 1, 2017 13:40
A practical example of the Type class pattern in Scala
//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
}
@ricsirigu
ricsirigu / subtypePolymorphismExample.scala
Created June 1, 2017 13:40
A practical example of subtype polymorphism in Scala
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}"
@ricsirigu
ricsirigu / typeclassWithTypeEnrichment.scala
Created June 3, 2017 08:27
Type Class with Type Enrichment
// 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
}
@ricsirigu
ricsirigu / AsyncRestExample.scala
Created June 30, 2017 14:55
Asynchronous Rest with Scala and Lift Framework
/**
* 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
@ricsirigu
ricsirigu / JWTAuthentication.scala
Last active July 21, 2017 08:25
JWT Authentication with Scala and Lift web framework
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 {
@ricsirigu
ricsirigu / StripeInjector.scala
Created October 14, 2017 13:38
Custom implementation of Stripe Checkout with Scala and the Lift framework
/**
* Example of a custom implementation of Stripe Checkout
*
* https://stripe.com/docs/checkout#integration-custom
*
* @author Riccardo Sirigu
*/
class StripeInjector {
@ricsirigu
ricsirigu / google-dorks
Created February 27, 2019 15:48 — forked from stevenswafford/google-dorks
Listing of a number of useful Google dorks.
" _ _ "
" _ /|| . . ||\ _ "
" ( } \||D ' ' ' C||/ { % "
" | /\__,=_[_] ' . . ' [_]_=,__/\ |"
" |_\_ |----| |----| _/_|"
" | |/ | | | | \| |"
" | /_ | | | | _\ |"
It is all fun and games until someone gets hacked!
@ricsirigu
ricsirigu / ConditionalRendering.scala
Last active July 11, 2019 10:40
How to dynamically render HTML with Scala and the Lift framework
class ConditionalRendering{
def render: (NodeSeq) => NodeSeq = {
"#content-container" #> {if(trueness) PassThru else ClearNodes} andThen
"#inclusions" #> {".inclusions-text *" #> { List("food", "drinks") } }
}
}