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
var http = require('http') | |
var respond = function(res, s) { | |
res.writeHead(200); | |
res.write(s); | |
res.end(); | |
} | |
var makeService = function(resources) { |
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
<html> | |
<head></head> | |
<body> | |
<script> | |
var A = {who: "A"}; | |
A.sine = function(x) { return Math.sin(x); } | |
A.cube = function(x) { return x*x*x; } | |
A.compose = function(f, g) { | |
return function(x) { return f(g(x)); } |
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
PROMPT='%{$fg_bold[green]%}➜ %{$fg_bold[green]%}%p %{$fg[green]%}%c %{$fg_bold[green]%}$(git_prompt_info)%{$fg_bold[green]%} % %{$reset_color%}' | |
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[green]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%}) %{$fg[green]%}✗%{$reset_color%}" | |
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%})" |
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 play.api.libs.ws._ | |
import play.api.libs.iteratee._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
WS.url("http://www.bbc.co.uk").get( resp => Iteratee.fold(0) { (i:Int, el:Array[Byte] ) => println(el); i + 1} ) |
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
object twitter { | |
import play.api.libs.ws._ | |
import play.api.libs.iteratee._ | |
import play.api.libs.oauth._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val key = ConsumerKey("XXXX", "XXXX") | |
val twitter = OAuth(ServiceInfo( | |
"https://api.twitter.com/oauth/request_token", |
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
object TMP extends App { | |
import scala.concurrent.{Future, Await} | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.duration._ | |
def b1 = { | |
val f: Future[Int] = scala.concurrent.future { 100 } | |
val r = Await.result(f, 1.second) | |
println(":> " + r) | |
} |
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
// | |
// Is there a better way to do this. The difficulty is coming from the fact that the | |
// second future result may not be necessary, based on an optinal value in the first. | |
// | |
import scala.concurrent.{Await, Future} | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
case class User(name: String, homepageUrl: Option[String]) | |
case class UserProfile(userName: String, profile: 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
// Trying to understand the Magnet pattern (as used in spray) | |
// http://spray.io/blog/2012-12-13-the-magnet-pattern/ | |
/** | |
* A simple utility that writes things to strings. | |
* We'd like it to be able to work for multiple different types | |
*/ | |
object Writer { | |
/** | |
* We want this to work for multiple types that we don't know yet, |
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
class MapperHolder extends Serializable { | |
lazy val mapper = { | |
val m = new ObjectMapper with ScalaObjectMapper | |
m.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) | |
m.registerModule(DefaultScalaModule) | |
m | |
} | |
} | |
val holderBcast = sc.broadcast(new MapperHolder()) |
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
case class CarMake(name: String) | |
case class CarModel(name: String) | |
case class Car(make: CarMake, model: Option[CarModel]) | |
case class StreetName(value: String) | |
case class Address(number: String, street: StreetName) | |
case class Person(name: String, address: Option[Address], car: Option[Car]) |
OlderNewer