This file contains hidden or 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 io.circe._, io.circe.generic.auto._, io.circe.jawn._, io.circe.syntax._ | |
case class WIFI(network:String,password:String) | |
val myWifi = WIFI("Scala","My_Wifi_Password") | |
myWifi.asJson | |
myWifi.asJson.noSpaces // will return a String "{"password":"My_Wifi_Password","network":"Scala"}" |
This file contains hidden or 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 org.joda.time._ | |
val dateStream: Stream[LocalDate] = { | |
def loop(ld: LocalDate): Stream[LocalDate] = ld #:: loop(ld plusDays 1) | |
loop(LocalDate.now()) | |
} | |
dateStream.take(18).toList |
This file contains hidden or 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
<link rel="import" href="../components/polymer/polymer.html"> | |
<polymer-element name="my-element"> | |
<template> | |
<style> | |
#design_host { | |
position: absolute; | |
width: 100%; | |
height: 100%; |
This file contains hidden or 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
case class Deal(title:String="",disc:Int=0,city:String="") | |
val r = url("http://localhost:8086") | |
(for{x<-Http(r<>{_\"deal"});d=(x\"disc").text.toInt if d>20}yield Deal((x\"title").text,d,(x\"city").text))groupBy(_.city)mapValues(_.size) |
This file contains hidden or 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
Http(url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") >>> System.out) | |
Http(url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") as_str) | |
val grouponCitiesURL = url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") | |
Http(grouponCitiesURL as_str) | |
val citiesAsXML = Http(grouponCitiesURL <> { response => response \\ "division" }) | |
val cityNames = citiesAsXML map ( city => (city \ "name").text ) | |
val cityNames = citiesAsXML map ( city => (city \ "name").text ) filter(_.startsWith("H")) | |
val cityLocations = citiesAsXML map { city => ((city \ "name").text,(city \ "lat").text,(city \ "lng").text) } | |
cityLocations find (location => location._1 == "Honolulu") | |
cityLocations find (_._1 == "Honolulu") |
This file contains hidden or 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
:power | |
def using[A <: {def close(): Unit}, B](param: A)(f: A => B): B = | |
try { f(param) } finally { param.close() } | |
def appendToFile(fileName:String, textData:String) = | |
using (new java.io.FileWriter(fileName, true)){ | |
fileWriter => using (new java.io.PrintWriter(fileWriter)) { | |
printWriter => printWriter.println(textData) | |
} | |
} | |
def timedAndLogged[T](body: => T): T = { |
This file contains hidden or 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
case class Deal( title:String = "", discount:Int = 0, city:String = "" ) | |
val deal = Deal() | |
val deal = Deal("Hotel") | |
val deal = Deal("Hotel",city="Paris") | |
val betterDeal = deal.copy(discount=50) | |
import dispatch._ | |
val request = url("http://localhost:8086/deals") | |
Http( request >>> System.out) | |
val deals = Http( request as_str ) | |
val dealsAsXml = Http( request.handleResponseAsXml({ response => response }) ) |
This file contains hidden or 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 dispatch._ | |
import akka.dispatch._ | |
import Future.flow | |
val params = Promise[Map[String,String]]() | |
val deals = Future( Http( url("http://localhost:8086/deals") <<? params.get as_str )) | |
println("Result:" + deals.result) | |
flow { params << Map ("city" -> "stockholm") } | |
Thread.sleep(2000) | |
println("Result:" + deals.result) |
This file contains hidden or 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
case class Conference(name:String="JFokus",year:Int=2011,myTalk:Option[String]=None) | |
val lastYear = Conference() | |
val thisYear = Conference(year=2012,myTalk=Some("One-liners are your friend")) |
This file contains hidden or 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 teletubbies = List("Tinky Winky","Dipsy","Laa-Laa","Po").reduceLeft(_+", "+_) + " say hello" |