Skip to content

Instantly share code, notes, and snippets.

Kingsley Davies kings13y

Block or report user

Report or block kings13y

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
kings13y / FizzBuzzScalaCheck.scala
Created May 28, 2012
FizzBuzz spec using ScalaCheck
View FizzBuzzScalaCheck.scala
package org.scalabound.scatdd.scalacheck
import org.scalabound.scatdd.FizzBuzz
import org.scalacheck.ConsoleReporter.testReport
import org.scalacheck.Prop.forAll
import org.scalacheck.Prop.propBoolean
import org.scalacheck.ConsoleReporter
import org.scalacheck.Test
object FizzBuzzScalaCheck {
kings13y / FizzBuzzScalaTest.scala
Created May 28, 2012
FizzBuzz Test spec with ScalaTest
View FizzBuzzScalaTest.scala
package org.scalabound.scatdd.scalatest
import org.junit.runner.RunWith
import org.scalatest.FunSpec
import org.scalatest.junit.JUnitRunner
import org.scalabound.scatdd.FizzBuzz
class FizzBuzzScalaTest extends FunSpec {
kings13y / FizzBuzzSpecs2.scala
Created May 28, 2012
FizzBuzz test case in Specs2
View FizzBuzzSpecs2.scala
package org.scalabound.scatdd.specs2
import org.scalabound.scatdd.FizzBuzz
import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner
// package unitTest { |> Scala IDE will not pick the class up as runnable if I sub-package it like this :-(
class FizzBuzzJUnitSpec extends org.specs2.mutable.Specification {
kings13y / FizzBuzz.scala
Created May 28, 2012
Minimal FizzBuzz implementation in Scala
View FizzBuzz.scala
package org.scalabound.scatdd
object FizzBuzz {
def eval(x: Int) = (x % 3, x % 5, x) match {
case(0, 0, _) => "FizzBuzz"
case(0, _, _) => "Fizz"
case(_, 0, _) => "Buzz"
case _ => "" + x
kings13y /
Created May 28, 2012
FizzBuzz Java JUnit test
package org.scalabound.scatdd;
import static org.junit.Assert.*;
import org.junit.Test;
import org.scalabound.scatdd.FizzBuzz;
public class FizzBuzzJUnitTest {
kings13y / gist:2136456
Created Mar 20, 2012
mvn archetype quickstart commands for Scala
View gist:2136456
mvn archetype:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple
mvn compile
mvn exec:java -Dexec.mainClass="" -Dexec.args="arg0 arg1 arg2"
kings13y / MinimalRestServer.scala
Created Aug 9, 2011
Sample Rest style service using just Scala and Java 6 annotations
View MinimalRestServer.scala
package output
import javax.xml.bind.{ Marshaller, JAXBContext }
import javax.xml.bind.annotation._
import javax.xml.bind.util.JAXBSource
import javax.xml.transform.Source
import{ Endpoint, Provider, ServiceMode, WebServiceContext, WebServiceProvider }
import javax.annotation.Resource
kings13y / PartialUpdateToImmutableObject.scala
Created Jul 26, 2011
Partial updates with immutable domain objects
View PartialUpdateToImmutableObject.scala
case class Person(val firstName: String, val lastName: String, val age: Int, val email: String) {
def update(firstName: String = firstName, lastName: String = lastName, age: Int = age, email: String = email) : Person = {
Person(firstName, lastName, age, email)
val seedPerson = Person("A", "B", 1, "")
val updatedPerson = seedPerson update (age = 100, firstName = "Z")
kings13y / ReifiedManifest.scala
Created Jun 16, 2011
Reification via a Manifest example
View ReifiedManifest.scala
class ReifiedManifest[T <: Any : Manifest](value: T) {
val m = manifest[T] // So at this point we have the manifest for the Parameterized type
// At which point we could either do an if() expression on what type is contained in our manifest
if (m equals manifest[String]) {
println("The manifest contains a String")
} else if (m <:< manifest[AnyVal]) { // A subtype check using the <:< operation on the Manifest trait
println("The manifest contains a subtype of AnyVal")
} else if (m <:< manifest[AnyRef]) {
kings13y / PrintFormatter.scala
Created Jun 16, 2011
Generalized type constraints example
View PrintFormatter.scala
case class PrintFormatter[T](item : T) {
def formatString(implicit evidence: T =:= String) = { // Will only work for String PrintFormatters
println("STRING specialised printformatting...")
def formatPrimitive(implicit evidence: T <:< AnyVal) = { // Will only work for Primitive PrintFormatters
println("WRAPPED PRIMITIVE specialised printformatting...")
val stringPrintFormatter = PrintFormatter("String to format...")
You can’t perform that action at this time.