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 | |
func main() { | |
conn := comms.NewConnection("my-producer", "my-exchange", []string{"queue-1", "queue-2"}) | |
if err := conn.Connect(); err != nil { | |
panic(err) | |
} | |
if err := conn.BindQueue(); err != nil { | |
panic(err) | |
} |
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 ( | |
"comms" | |
"github.com/streadway/amqp" | |
"log" | |
) | |
func main() { | |
forever := make(chan bool) |
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 comms | |
//Publish publishes a request to the amqp queue | |
func (c *Connection) Publish(m Message) error { | |
select { //non blocking channel - if there is no error will go to default where we do nothing | |
case err := <-c.err: | |
if err != nil { | |
c.Reconnect() | |
} | |
default: |
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 comms | |
//Consume consumes the messages from the queues and passes it as map of chan of amqp.Delivery | |
func (c *Connection) Consume() (map[string]<-chan amqp.Delivery, error) { | |
m := make(map[string]<-chan amqp.Delivery) | |
for _, q := range c.queues { | |
deliveries, err := c.channel.Consume(q, "", false, false, false, false, nil) | |
if err != nil { | |
return nil ,err | |
} | |
m[q] = deliveries |
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 comms | |
import ( | |
"errors" | |
"fmt" | |
"github.com/streadway/amqp" | |
) | |
//MessageBody is the struct for the body passed in the AMQP message. The type will be set on the Request header | |
type MessageBody struct { |
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 BuildImage(dockerBuildCtxDir, tagName string) error { | |
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(300)*time.Second) | |
defer cancel() | |
dockerFileTarReader, err := tarDirectory(dockerBuildCtxDir) | |
//this above method will create a tar file from the directory passed in. The return has to be of type io.Reader | |
if err != nil { | |
log.Printf("Error in taring the docker root folder - %s", err.Error()) | |
return err | |
} | |
buildArgs := make(map[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
FROM alpine:3.8 | |
RUN apk update | |
RUN mkdir -p /tmp/dhanush | |
WORKDIR /tmp/dhanush | |
COPY ./test.exe ./ | |
COPY ./test.env ./ | |
ENTRYPOINT [ "/tmp/dhanush/test.exe" ] |
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 downloadMultipleFiles(urls []string) ([][]byte, error) { | |
done := make(chan []byte, len(urls)) | |
errch := make(chan error, len(urls)) | |
for _, URL := range urls { | |
go func(URL string) { | |
b, err := downloadFile(URL) | |
if err != nil { | |
errch <- err | |
done <- nil | |
return |
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 downloadFile(URL string) ([]byte, error) { | |
response, err := http.Get(URL) | |
if err != nil { | |
return nil, err | |
} | |
defer response.Body.Close() | |
if response.StatusCode != http.StatusOK { | |
return nil, errors.New(response.Status) | |
} | |
var data bytes.Buffer |
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 pandas | |
import math | |
from numpy.random import permutation | |
from sklearn import svm | |
x_cols = [] #array of all the features (column names in the file) we use to predict | |
y_cols = ['role'] #to be predicted item | |
#Create Pandas dataframe | |
training_data_frame = pandas.read_csv('train.csv') |
NewerOlder