Skip to content

Instantly share code, notes, and snippets.

View hamnis's full-sized avatar

Erlend Hamnaberg hamnis

View GitHub Profile
package xmldecoder
import scala.util.Try
import scala.xml.{Node, NodeSeq}
case class XMLDecodeException(path: String, message: String) extends Exception {
override def getMessage: String = s"[$path] - $message"
}
trait Decoder[A] {
@Override
public void authenticationFinished(AuthenticationSessionModel authSession, BrokeredIdentityContext context) {
String prompt = authSession.getClientNote(OIDCLoginProtocol.PROMPT_PARAM);
if (OIDCLoginProtocol.PROMPT_VALUE_LOGIN.equals(prompt)) {
UserSessionModel usm = session.sessions().getUserSessionByBrokerSessionId(authSession.getRealm(), context.getBrokerSessionId());
if (!AuthenticationManager.isSessionValid(authSession.getRealm(), usm)) {
logger.debugf("User session '%s' is not valid, maybe creating a new one", context.getBrokerSessionId());
EventBuilder event = new EventBuilder(authSession.getRealm(), session, session.getContext().getConnection());
event.event(EventType.IDENTITY_PROVIDER_LOGIN);
ClientSessionContext ctx = AuthenticationProcessor.attachSession(authSession, usm, session, authSession.getRealm(), session.getContext().getConnection(), event);
package no.scalabin.http4s.directives
package routes
import cats.Monad
import linx._
import Route.{MethodPartial, ResponseDirective}
import org.http4s.{Method, Response, Status}
import scala.language.higherKinds
package no.scalabin.http4s.directives
package routes
import cats.Monad
import linx._
import Route.{MethodPartial, ResponseDirective}
import org.http4s.{Method, Response, Status}
import scala.language.higherKinds
package example
import io.circe.{DecodingFailure, JsonNumber, Decoder => CD, Json => CJ}
import argonaut.{Json => AJ}
object ArgoCirc extends App {
case class Person(name: String, age: Int)
object Person {
type ValueDirective[F[+_], A] = Directive[F, Response[F], A]
type ResponseDirective[F[+_]] = ValueDirective[F, Response[F]]
def directiveFor[F[+_]](resish: F[Response[F]])(implicit d: Directives[F]): ResponseDirective[F] = {
import d._
import ops._
for {
_ <- Method.GET
res <- successF(resish)
} yield { res }
@hamnis
hamnis / Replsession.md
Last active January 10, 2017 10:51
Odd scala 2.12 problem

This code works in scala 2.11

import scalaz._

type Id[+A] = A

implicit val monadInstance: Monad[Id] = new Monad[Id] {
  override def point[A](a: => A): Id[A] = a

  override def bind[A, B](fa: Id[A])(f: (A) => Id[B]): Id[B] = f(fa)
package sqldsl;
import java.sql.ResultSet;
import java.util.Iterator;
import java.util.function.Function;
public class ResultSetIterator implements Iterator<ResultSetRow> {
@SuppressWarnings("unchecked")
static <T extends Throwable> T sneakyRethrow(Throwable t) throws T {
package net.hamnaberg.json.examples;
import javaslang.collection.List;
import javaslang.control.Option;
import net.hamnaberg.json.Codecs;
import net.hamnaberg.json.DecodeResult;
import net.hamnaberg.json.Json;
import net.hamnaberg.json.JsonCodec;
import net.hamnaberg.json.io.JacksonStreamingParser;
@hamnis
hamnis / MergePatch.scala
Last active July 20, 2016 10:36
Implementation of rfc7396
import argonaut._, Argonaut._
object MergePatch {
def mergePatch(json: Json, patch: Json): Json = {
val target = json.objectOrEmpty.toMap
if (patch.isObject) {
patch.objectOrEmpty.toList.foldLeft(target) { case (map, (k, v)) =>
if (map.isDefinedAt(k)) {
if (v.isNull) map - k else map + (k -> mergePatch(map(k), v))
} else {