Skip to content

Instantly share code, notes, and snippets.

View wolfendale's full-sized avatar

Michael Wolfendale wolfendale

View GitHub Profile
@wolfendale
wolfendale / unions.md
Created December 2, 2019 17:22
Issues with unions in Quill

Unions

  val e = quote {
    querySchema[TestEntity]("test_entity", _.s -> "field_s", _.i -> "field_i")
  }

  val e2 = quote {
    querySchema[TestEntity]("test_entity_2", _.s -> "field_s_2", _.i -> "field_i_2")
 }
@wolfendale
wolfendale / carMotor.scala
Last active October 28, 2018 16:43
Play JSON Reads
implicit lazy val reads: Reads[CarMotor] = {
import play.api.libs.json._
import play.api.libs.functional.syntax._
(__ \ "engineType").read[String].flatMap {
case "electric" =>
Reads.pure(Electric)
case "engine" => {
(__ \ "fuel").read[CarFuelType] and
package wolfendale.scalacheck.regexp.models
sealed trait Group[A] {
def intersect(other: Group[A]): Group[A]
def ++(other: Group[A]): Group[A]
def --(other: Group[A]): Group[A]
}
@wolfendale
wolfendale / maxsublist.scala
Created October 4, 2018 19:42
Maximum Sublist
import scala.util.Random
implicit class SubsetList[A](list: List[A]) {
def sublists: Stream[List[A]] = for {
length <- (0 to list.length).toStream
combination <- list combinations length
} yield combination
}
def maxSublistBounded(list: List[Int], boundary: Int): (List[Int], Int) = {
@wolfendale
wolfendale / readme.txt
Created August 11, 2018 19:01
Pilgrimage (PuzzleScript Script)
Play this game by pasting the script in http://www.puzzlescript.net/editor.html
@wolfendale
wolfendale / MyAction.scala
Created September 20, 2017 06:59
Route Params in Composed Actions
package com.example
import javax.inject.Inject
import play.api.i18n.MessagesApi
import play.api.mvc._
import scala.concurrent.Future
// note: `messagesApi` could be anything, it's just quite likely that your controller
@wolfendale
wolfendale / Main.scala
Last active June 23, 2017 14:13
Typeclass Example
package wolfendale
case class Person(name: String)
object Typeclasses extends App {
import Show.Showable
val tuple = (Person("Michael"), Person("Not Michael"))
val tuple2 = (Person("Michael"), (Person("Not Michael"), Person("Foo")))
@wolfendale
wolfendale / monoid.scala
Created February 26, 2016 10:33
Monoid Stuff
sealed trait Foobar
case object Foo extends Foobar
case object Bar extends Foobar
case class Baz(foo: Boolean = false, bar: Boolean = false)
implicit val bazMon: Monoid[Baz] =
new Monoid[Baz] {
override def zero: Baz = Baz()
override def append(f1: Baz, f2: => Baz): Baz =
@wolfendale
wolfendale / enum.scala
Last active April 18, 2016 13:25
Validation Shapeless
package wolfendale
trait Enum {
type Value <: Singleton
}
object Enum {
trait Aux[A <: Singleton] extends Enum { type Value = A }
}
@wolfendale
wolfendale / EitherMapping.scala
Last active December 8, 2015 15:58
Either Mapping
package forms
import play.api.data.{FormError, Mapping}
import play.api.data.validation.Constraint
case class EitherMapping[L, R](
lmapping: Mapping[L],
rmapping: Mapping[R],
key: String = "",
constraints: Seq[Constraint[Either[L, R]]] = Nil