This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.xml._ | |
import scala.xml.transform._ | |
object Main extends App { | |
import Stuff._ | |
val sourceXml = XML.loadFile("metadata.switchaai.xml") | |
val allEntities = sourceXml \\ "EntityDescriptor" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import util.Random | |
/* | |
Takes a sequence of secret santa participants and suggests who should give to who | |
*/ | |
object SecretSanta { | |
def main(args: Array[String]){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait MyTrait{ | |
def say: String | |
} | |
trait ConcreteTrait extends MyTrait{ | |
def say = "Hello, world" | |
} | |
trait TestTrait extends MyTrait{ | |
def say = "Testing" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pretend this is your awesome library code that you want others to use freely | |
object MyAmazingSerialisationLib{ | |
trait Serialiser[A]{ | |
def toJson(x: A): String | |
} | |
def writeJsonToDisk[A](item: A)(implicit serialiser: Serialiser[A]){ | |
def writeToDisk(x: String) {println(s"I saved [$x] to disk, honest!")} | |
writeToDisk(serialiser.toJson(item)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Quackable = { | |
def quack(): Unit | |
} | |
def listenToSomeQuacking(x: Quackable){ | |
println("Gosh I love the sound of quacks") | |
x.quack() | |
} | |
class Duck{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [A: Serialiser] means the compiler expects an implicit Serialiser | |
// needs to be available for A | |
def writeJsonToDisk[A: Serialiser](item: A){ | |
def writeToDisk(x:String){println(s"I saved [$x] to disk, honest!")} | |
// Access the parameter with implicity | |
writeToDisk(implicitly[Serialiser[A]].toJson(item)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index(doi: String) = Action.async { request => | |
// Fake way of checking whether a particular user has access to the content or not (for demo purposes of course!) | |
val fakeAccessCheck = math.random < 0.50 | |
for { | |
timeBody <- getBodyOf("http://localhost:9000/time") | |
fullTextBody <- getFulltextOrAbstract(doi,fakeAccessCheck) | |
downloadsBody <- getBodyOf(s"http://localhost:9000/downloads/${encodeDoi(doi)}") | |
} yield { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val fromVarnish = request.headers.get("X-VARNISH").isDefined | |
private def getBodyOf(url:String, fromVarnish:Boolean = false): Future[String] = { | |
if(fromVarnish){ | |
Future(s"""<esi:include src="$url" onerror="continue"/>""") | |
}else{ | |
WS.url(url).get.map(r=> r.body) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.concurrent.Future | |
object TimingFutures extends App{ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
def timedFuture[T](future: Future[T]) = { | |
val start = System.currentTimeMillis() | |
future.onComplete({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"os" | |
"reflect" | |
"strings" | |
) |
OlderNewer