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
// Stitcher calls the Hello and World APIs to create a very useful string | |
func Stitcher(helloURL string, worldURL string) string { | |
helloChannel := make(chan []byte, 1) | |
worldChannel := make(chan []byte, 1) | |
go func() { | |
helloResponse, _ := http.Get(helloURL) | |
defer helloResponse.Body.Close() | |
helloContent, _ := ioutil.ReadAll(helloResponse.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
func Benchmark_the_stitcher(b *testing.B) { | |
slowHelloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
time.Sleep(500 * time.Millisecond) | |
fmt.Fprint(w, "Hello") | |
})) | |
slowWorldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
time.Sleep(500 * time.Millisecond) | |
fmt.Fprint(w, "world") | |
})) |
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" | |
"io/ioutil" | |
"net/http" | |
) | |
// Stitcher calls the Hello and World APIs to create a very useful string | |
func Stitcher(helloURL string, worldURL string) 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
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/httptest" | |
"testing" | |
) | |
func Test_it_calls_the_services_and_concatenates_the_results(t *testing.T) { |
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
// Stitcher calls the Hello and World APIs to create a very useful string | |
func Stitcher(helloURL string, worldURL string) string { | |
return "" | |
} |
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
func Stitcher(hello_url string, worldURL string) string { | |
return "" | |
} |
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 LetterCounter extends App{ | |
val filters = args.lift(1).getOrElse("aeiou").toList | |
val grouped = args(0).groupBy(l=>l).collect{case (l,g) => (l, g.length)} | |
val groupCount = filters.map(v => grouped.find(x=> x._1==v).getOrElse((v,0))) | |
val output = groupCount.foldLeft("")((result, pair) => result+pair._1 + ": "+pair._2+" ") | |
println(output) | |
} |
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" | |
) |
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
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) | |
} | |
} |