Skip to content

Instantly share code, notes, and snippets.

@afiore
afiore / ExampleBindings.scala
Created December 30, 2020 12:56
Using ACL bindings
object Examples {
val validAcl1 = AclBinding(ResourcePattern(ResourceType.TOPIC, "position-report", PatternType.LITERAL), AclEntry("User:andrea", "example.cloud", Operation.ALL, PermissionType.ALLOW))
val validAcl2 = AclBinding(ResourcePattern(ResourceType.CLUSTER, "kafka-test-", PatternType.PREFIXED), AclEntry("Group:testers", "example.cloud1", Operation.DESCRIBE, PermissionType.ALLOW))
val invalidAcl = AclBinding(ResourcePattern(ResourceType.TRANSACTION_ID, "*", PatternType.LITERAL), AclEntry("User:andrea", "cloud1", Operation.ALTER, PermissionType.ALLOW))
}
@afiore
afiore / acls.scala
Created December 30, 2020 12:49
Tapir snippets
import io.circe.generic.semiauto.deriveCodec
import io.circe.Codec
final case class ResourcePattern(resourceType: ResourceType,
resource: String,
patternType: PatternType)
object ResourcePattern {
implicit val codec: Codec[ResourcePattern] = deriveCodec
}
@afiore
afiore / PhantomMembers.scala
Last active October 7, 2017 14:13
AWS IAM Conditions encoded using phantom types and type members
package typeformation.cf.iam
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{FreeSpec, Matchers}
/**
* Encoding of AWS IAM conditions using a combination of phantom types and type members
*
* A `Condition` is a type representing a key, and an expected parametric value.
* Conditions might be universally or existentially quantified, and can present an additional
@afiore
afiore / RequiredFields.scala
Last active August 22, 2018 19:21
Filtering non-optional fields using shapeless
import shapeless._
import shapeless.labelled._
trait Required[A] {
def isRequired: Boolean
}
object Required {
implicit def optIsRequired[A]: Required[Option[A]] = new Required[Option[A]] {
override def isRequired = false
}
@afiore
afiore / FromConfig.scala
Created December 10, 2016 16:31
FromConfig.scala
package swag
import com.typesafe.config.Config
import shapeless._
import shapeless.labelled._
object FromConfig {
sealed trait Error
### Keybase proof
I hereby claim:
* I am afiore on github.
* I am afiore (https://keybase.io/afiore) on keybase.
* I have a public key ASDOj-CbhhpO4ZN_j4oJ3sfPi6BZfaPqP3_t_9XD_nQ9Pgo
To claim this, I am signing this object:
@afiore
afiore / build.sbt
Last active June 23, 2016 22:10
Skip the test when the current build SHA1 has a successful status flag associated (Github API)
import org.kohsuke.github.{GHCommitState, GHCommitStatus, GitHub}
name := "gitStatus"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.6" % "test"
import Function.const
import scala.annotation.tailrec
import scala.collection.SortedMap
object Palindrome {
case class Palindrome(s: String, startIdx: Int)
case class PalKey(index: Int, length: Int)
type PalIndex = SortedMap[PalKey, Int]
object Palindrome {
@afiore
afiore / voting.scala
Last active August 29, 2015 14:22
akka persistence workshop
package pt.akka.workshop
import java.util.UUID
import akka.actor.{ActorLogging, Actor}
import akka.persistence.{RecoveryCompleted, SnapshotOffer, PersistentActor}
/*
@afiore
afiore / collection_parser.rb
Last active August 29, 2015 13:57
A generic (flat) collection parser using Nokogiri's SAX capabilities
require 'nokogiri'