Skip to content

Instantly share code, notes, and snippets.

View DrewEaster's full-sized avatar

Andrew Easter DrewEaster

View GitHub Profile
@DrewEaster
DrewEaster / uk-number-plate-validation.md
Created January 4, 2018 09:32 — forked from danielrbradley/uk-number-plate-validation.md
Regular Expression to Validate UK Number Plates

Regular Expression to Validate UK Number Plates

Regular Expression

(?<Current>^[A-Z]{2}[0-9]{2}[A-Z]{3}$)|(?<Prefix>^[A-Z][0-9]{1,3}[A-Z]{3}$)|(?<Suffix>^[A-Z]{3}[0-9]{1,3}[A-Z]$)|(?<DatelessLongNumberPrefix>^[0-9]{1,4}[A-Z]{1,2}$)|(?<DatelessShortNumberPrefix>^[0-9]{1,3}[A-Z]{1,3}$)|(?<DatelessLongNumberSuffix>^[A-Z]{1,2}[0-9]{1,4}$)|(?<DatelessShortNumberSufix>^[A-Z]{1,3}[0-9]{1,3}$)

Source information

DVLA website

Rules

// Provided by AmazingMongoFramework
case class MongoConfig(hostname: String, port: Int)
case class MongoConfigBuilder(hostname: Option[String] = Some("localhost"), port: Option[Int] = Some(27017)) {
def withHostname(hostname: String) = copy(hostname = Some(hostname))
def withPort(port: Int) = copy(port = Some(port))
def build() = {
// do some validation here..
@DrewEaster
DrewEaster / akka-ddd.scala
Last active December 26, 2015 15:49
An adapted version of Vaughn Vernon's ideas from his very useful blog post http://vaughnvernon.co/?p=770
trait AggregateType {
val description: String
val classType: Class[_ <: Actor]
}
object DomainModel {
def apply(name: String)(aggregateTypes: AggregateType*) = {
new DomainModel(name, aggregateTypes)
}
}
import scala.collection.mutable.ListBuffer
import akka.actor.{Actor,ActorRef}
import akka.actor.Actor._
import akka.routing.{ Listeners, Listen }
//Represents a domain event
trait Event
//A builder to create domain entities
trait EntityBuilder[Entity] {
object Global extends WithFilters(AccessLogFilter) {
}
@DrewEaster
DrewEaster / AccessLogFilter.scala
Last active December 19, 2015 17:29
Play! filter for performing access logging
object AccessLogFilter extends EssentialFilter {
val dateTimeFormat = ISODateTimeFormat.ordinalDateTimeNoMillis()
def apply(next: EssentialAction) = new EssentialAction {
def apply(rh: RequestHeader) = {
val startTime = System.currentTimeMillis()
def logTime(result: PlainResult): Result = {
val event = Json.obj(