Skip to content

Instantly share code, notes, and snippets.

def writes(o: T): JsObject = {
val canonicalName = Option(clazz.getCanonicalName()).getOrElse(throw new IllegalArgumentException("Cannot serialize this class because its canonical name is null. This is most likely because it is an Array or a Local or Anonymous class."))
JsObject(Seq("className" -> JsString(canonicalName)))
}
// i find using the container type in one place better for understanding
// since we are threading transformations and operations on the Option until
// the end when we either have a result or we throw an exception
def writes(o: T): JsObject =
Option(clazz.getCanonicalName())
@trane
trane / zsh_theme.zsh
Created July 8, 2016 21:51
my zsh theme based on my-ys-terminal-theme
# Clean, simple, compatible and meaningful.
# Tested on Linux, Unix and Windows under ANSI colors.
# It is recommended to use with a dark background and the font Inconsolata.
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white.
#
# http://ysmood.org/wp/2013/03/my-ys-terminal-theme/
# Mar 2013 ys
# Machine name.
function box_name {
{ pkgs ? import <nixpkgs> {}
, lookout ? import <lookout> {}
, ... }:
let
inherit (pkgs) stdenv nixops jq git which bash curl ruby_1_9 maven redis procps;
inherit (pkgs.haskellPackages) ShellCheck;
inherit (lookout) jruby1_7_22;
in
stdenv.mkDerivation {
name = "micropush-ci";
case class KeymasterPostLoginFilter(store: SessionStore)(implicit secretStoreApi: SecretStoreApi)
extends Filter[SessionIdRequest, Response, IdentifyRequest[Auth], IdentifyResponse[Tokens]] {
def apply(req: SessionIdRequest,
service: KeymasterIdentityProvider[IdentifyRequest[Auth], IdentifyResponse[Tokens]]): Future[Response] = {
for {
// this is where a `map would be nice on IdentifyRequest
// it would just look like `req.map(auth => transform(BasicRequest))`
// which we could expose via the IdentityService as a `.to[A]` method which calls the `map`
// so it would be `service.requestTo[BasicRequest](req)`
// anyway, using the `.transform` method, it should look like this:
def consulResponse(s: Secrets): ConsulResponse =
ConsulResponse(...., Base64Encode(s.toJson), ...)
def mockConsulService(secrets: Secrets): Service[Request, Response] = {
new Service[Request, Response] {
def apply(req: Request): Future[Response] = {
val res = Response(Status.Ok)
(req.method, req.path) match {
case (Get, Root / "/v1/k1") => res.contentString = consulResponse(secrets).toJson
// define the ADT
trait Tag {
val id: Byte
}
case object Empty extends Tag {
val id = -1.toByte
}
case object Initial extends Tag {
val id = 0.toByte
}
trait Binder[A] {
def name(a: A): String
def hosts(a: A): String
}
implicit object LoginManagerBinder extends Binder[LoginManager] {
def name(manager: LoginManager): String =
manager.name
def hosts(manager: LoginManager): String =
manager.host
scala> import io.circe._, io.circe.generic.auto._, io.circe.jawn._, io.circe.syntax._
import io.circe._
import io.circe.generic.auto._
import io.circe.jawn._
import io.circe.syntax._
scala> import io.circe._
import io.circe._
scala> import io.circe.generic.auto._
trait LoginProvider {
val loginPath: Path // listen for POST on this
val location: String
def redirect: Response =
tap(Response(Status.Found))(_.location = location)
}
case class InternalLoginProvider(path: Path, hosts: String, loginPath: Path) extends LoginProvider {
val location = path.toString
val server = Http.newClient(hosts)
@trane
trane / endpoint.scala
Created October 23, 2015 18:30 — forked from maheshkelkar/endpoint.scala
Adding endpoint concept to keymaster
/******* Option-1: **********/
/**
* Keymaster Config:
*
* "keymaster" {
* "upstreamEndpoints" : {
* identityProvider" : {
* "hosts" : "localhost:8081", // CSV of servers
* "path" : "/identityProvider" // use this path upstream