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
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
// 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
const wordSeparator = ", " | |
// 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 getStringFromAPI(helloChannel, helloURL) | |
go getStringFromAPI(worldChannel, worldURL) |
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 Test_it_handles_non_ok_from_hello_api(t *testing.T) { | |
helloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
http.Error(w, "oops", http.StatusInternalServerError) | |
})) | |
worldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
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
const wordSeparator = ", " | |
const errorMsg = "ALL OTHER SOFTWARE TEAMS ARE USELESS, OUTSOURCING IS A SHAM" | |
type apiResult struct { | |
content string | |
err error | |
} | |
// 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" | |
) | |
type Baz struct { | |
Y 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" | |
) | |
type CoPublisher struct { | |
id string | |
link 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
foo=> (defn x [a] (+ a 1)) | |
#'foo/x | |
foo=> (defn y [a] (+ a 2)) | |
#'foo/y | |
foo=> (-> 5 x y) | |
8 | |
foo=> (defn z [a] (-> a x y)) | |
#'foo/z | |
foo=> (z 10) | |
13 |
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
(comment | |
Clojure notes. Gathered from links below and "Programming Clojure" | |
- Uniform syntax. | |
- Code is data | |
- Immutablility encouraged | |
- [http://learnxinyminutes.com/docs/clojure/] | |
- [http://www.4clojure.com/problem/8#prob-title] | |
- [http://www.braveclojure.com/] | |
- Revenge of the nerds http://www.paulgraham.com/icad.html |