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 random | |
def simulate(a, b, iterations): | |
acount = bcount = 0 | |
for i in xrange(iterations): | |
vala = random.uniform(0, a) | |
valb = random.uniform(0, b) | |
if vala > valb: | |
acount+=1 | |
elif vala < valb: | |
bcount += 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
75a76 | |
> num_setable = 0; | |
271c272 | |
< int num_setable = 0; | |
--- | |
> int num_setable; |
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 ItemTest(t *testing.T) { | |
// Common setup. Abstract this out | |
// This allows each test to create its own handler by changing handler variable | |
handler := http.NotFound | |
hs := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { | |
handler(rw, req) | |
})) | |
defer hs.Close() | |
// Notice I set the base URL of the client to the httptest server | |
c := Client{ |
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
// +build integration | |
package smiteclient | |
// Create a file named info.json and put it at the root of your project. That file should have your | |
// devId and authKey. The file should be inside .gitignore and not checked into git. Then, | |
// run `go test -v --tags=integration .` to start integration tests using your auth key. | |
type devInfo struct { | |
AuthKey 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
const DefaultBaseURL = "http://api.smitegame.com/" | |
func (c *Client) urlBase() string { | |
if c.BaseURL == "" { | |
return DefaultBaseURL | |
} | |
return c.BaseURL | |
} |
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 (c *Client) doRequest(req *http.Request) { | |
resp, err := c.client.Do(req) | |
if err != nil { | |
return err | |
} | |
defer func() { | |
maxCopySize := 2 << 10 | |
io.CopyN(ioutil.Discard, resp.Body, maxCopySize) | |
resp.Close() | |
}() |
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
type ClientTrace struct { | |
// GetConn is called before a connection is created or | |
// retrieved from an idle pool. The hostPort is the | |
// "host:port" of the target or proxy. GetConn is called even | |
// if there's already an idle cached connection available. | |
GetConn func(hostPort string) | |
// GotConn is called after a successful connection is | |
// obtained. There is no hook for failure to obtain a | |
// connection; instead, use the error from |
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
type ClientTrace struct { | |
// Called before a connection is established. If it returns a | |
// non nil object, that object is used instead for the Connection. | |
GetConn func(hostPort string) *net.Conn | |
} |
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
type ClientTrace struct { | |
// Called before a connection is established. The returned context is used | |
// to finish processing the request. | |
GetConn func(ctx context.Context, hostPort string) context.Context | |
} |
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
type Request struct { | |
Method string | |
URL *url.URL | |
// ... | |
// Trace callbacks are executed if they are set | |
Trace ClientTrace | |
} | |
OlderNewer