Skip to content

Instantly share code, notes, and snippets.

View jessedearing's full-sized avatar

Jesse Dearing jessedearing

View GitHub Profile
aws --profile invision ec2 describe-instances --filters "Name=tag:Service,Values=mongo" | jq -r '.Reservations[].Instances[] | .PrivateIpAddress + " "+ (.Tags[] | select(.Key == "Name")).Value' | v -

This is a call to the RDS API to create new instances of MySQL. One of the things I've found really helpful is that as a staticly typed language, Go gives me reliable parameter autocomplete (via https://github.com/nsf/gocode) so I can pretty easily look up parameters to the *Input and *Output structs in all editors that have the integration In my case vim-go.

Amazon's Go API has a few quriks (like the pointers for everything needing the aws.String and aws.Bool convenience functions), but once you get into it flows easily.

Since the AWS functions are all in interfaces, I can mock github.com/aws/aws-sdk-go/service/rds/rdsiface using https://github.com/maxbrunsfeld/counterfeiter and write expectations in my unit tests.

@jessedearing
jessedearing / profile.go
Created January 5, 2017 23:39
Have go dump a stack trace on USR1
package main
import (
"os"
"os/signal"
"runtime/pprof"
"syscall"
)
func main() {
package main
import (
"database/sql"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"sync"
File.open(‘hello.txt’, ‘r’) do |f|
while line = f.gets
puts line
end
end
try(FileInputStream input = new FileInputStream(“file.txt”)) {
int data = input.read();
while(data != -1) {
System.out.print((char) data);
data = input.read();
}
}
connection, err := net.Dial("tcp", "example.com:80")
if err != nil {
// Do something to handle the error
return
}
defer connection.Close()
sshClient, err := setUpSSHClient(host)
if err != nil {
log.Panic(err)
}
defer sshClient.Close()
lsofOut, err := runCmd(sshClient, "sudo lsof -i tcp:"+port+" | tail -1 | awk '{ print $2; }'")
lsofOut = strings.Trim(lsofOut, "\n\r ")
if err != nil {
log.Panic(err)
db, err := sql.Open("mysql", user+":"+password+"@tcp("+host+":3306)/information_schema")
if err != nil {
log.Fatal(err)
}
defer db.Close()
hostWithPort := getHost(db)
if hostWithPort == nil {
log.Println("Could not find query with that ID")
return

Keybase proof

I hereby claim:

  • I am jessedearing on github.
  • I am jessed (https://keybase.io/jessed) on keybase.
  • I have a public key ASDHcM5dilzf0pRTuwAcQfzaPVtA7X4eT_hnyRk8ztRYcgo

To claim this, I am signing this object: