Skip to content

Instantly share code, notes, and snippets.

// 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)
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")
}))
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 {
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func Test_it_calls_the_services_and_concatenates_the_results(t *testing.T) {
// Stitcher calls the Hello and World APIs to create a very useful string
func Stitcher(helloURL string, worldURL string) string {
return ""
}
@quii
quii / stitcher1.go
Created March 20, 2015 10:03
Sticher first pass
func Stitcher(hello_url string, worldURL string) string {
return ""
}
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)
}
@quii
quii / configserver.go
Last active August 29, 2015 14:12
Generic configuration exposed over HTTP
package main
import (
"fmt"
"net/http"
"os"
"reflect"
"strings"
)
@quii
quii / timedfuture.scala
Created August 27, 2014 12:38
Timing futures in Scala
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({
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)
}
}