Skip to content

Instantly share code, notes, and snippets.

func SetupDatabase(t *testing.T) (func(), *sql.DB) {
pool, _ := dockertest.NewPool("")
# specify the container image here
postgres, _ := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres",
Tag: "13.2",
Env: []string{
"POSTGRES_USER=postgres",
"POSTGRES_PASSWORD=password",
# create a rate limiter to allow the http request at max 1 token within 1 sec
# this is the best way to avoid DDOS on the server because multiple requests
# can happen in different Goroutines
rl := rate.NewLimiter(rate.Every(time.Second), 1)
# We want to set up a common base client to do all the requests
client := resty.New().
SetTLSClientConfig(&tls.Config{...}). # setup TLS
SetTimeout(30 * time.Second). # client timeout
SetBaseURL(url). # base URL for all APIs
@eekwong
eekwong / multissh.py
Last active May 13, 2020 19:11
multissh is a script that runs a command in multiple hosts using the same password.
#!/usr/bin/python
import getpass
import paramiko
import socket
def main():
password = getpass.getpass()
hosts = raw_input("Hosts: ").split(",")
command = raw_input("Command: ").strip()