Skip to content

Instantly share code, notes, and snippets.

View bblfish's full-sized avatar

Henry Story bblfish

View GitHub Profile
@bblfish
bblfish / AuthZ test
Created May 29, 2012 22:19
Funcional AuthZ
case class AuthZ[A](act: Action[A])(implicit findGuard: RequestHeader => Guard) extends Action[A] {
def apply(req: Request): Result = {
val guard = findGuard(req)
if (guard.allow(guard.subject(req))) act(req)
else Results.Unauthorized
}
override
@bblfish
bblfish / AuthZ.scala
Created May 30, 2012 11:59
Authorization action
package org.w3.readwriteweb.play.auth
import play.api.mvc._
import javax.security.auth.Subject
import java.security.Principal
import play.api.libs.concurrent.Promise
import java.security.cert.Certificate
/**
@bblfish
bblfish / RDFReaderFactory.scala
Created June 7, 2012 17:23
make rdReaderFactory a bit more flexible
package org.w3.banana
import java.io._
import scalaz.Validation
import scalaz.Validation._
trait RDFReaderFactory[Rdf <: RDF] {
def format(ser: RDFSerialization) = ser match {
case RDFXML => RDFXMLReader
@bblfish
bblfish / WebIDAuthN.scala
Created July 29, 2012 09:24
Claim logic
package org.w3.play.auth
import akka.actor.Actor
import org.openrdf.model.URI
import java.security.cert.X509Certificate
import org.w3.play.rdf.GraphCache
import scalaz._
import scala.Some
import scalaz.Scalaz._
import org.w3.banana.RDF
@bblfish
bblfish / RequestHeader.scala
Created September 19, 2012 20:27
ClaimMondad version 1 - does not compile
import java.net.URI
import scalaz.concurrent.Promise
import scalaz._
import Scalaz._
import language.implicitConversions
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] )
trait RequestHeader {
@bblfish
bblfish / RequestHeader.scala
Created September 19, 2012 20:50
Claim Monad for X509 Certificates - having trouble running map on it
import java.net.URI
import scalaz.concurrent.Promise
import scalaz._
import Scalaz._
import language.implicitConversions
import language.higherKinds
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] )
trait RequestHeader {
@bblfish
bblfish / crashCompiler.scala
Last active December 11, 2015 22:58
This code crahes the scala 2.10.0 compiler on OSX with java "1.7.0_11"
//Using library from "net.sf.uadetector" % "uadetector-resources" % "2012.12"
import net.sf.uadetector.service._
import net.sf.uadetector.UserAgentFamily._
import net.sf.uadetector.UserAgent
val agentParser = UADetectorServiceFactory.getResourceModuleParser
val UA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.45 Safari/53.22"
val agent = agentParser.parse(UA)
@bblfish
bblfish / CORSProxy.scala
Last active December 20, 2015 00:19
simple CORSProxy with Play2.2 - does not quite work. It blocks the HTTP connection, even though the URL is correctly fetched...
/*
* Copyright 2012 Henry Story, http://bblfish.net/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@bblfish
bblfish / akkaHttp.sc
Created July 10, 2017 16:46
attempt to get some linked data code working with akka http and streams
import coursier.core.Authentication, coursier.MavenRepository
interp.repositories() ++= Seq(MavenRepository(
"http://bblfish.net/work/repo/snapshots/"
))
@
import scala.concurrent.ExecutionContext
@bblfish
bblfish / extractor.scala
Created August 13, 2014 16:50
This extractor works. It starts from a very simple base
package shapeless.examples
import shapeless.PolyDefns._
import shapeless._
import shapeless.ops.hlist.At
import scala.math.Ordering
/**