Skip to content

Instantly share code, notes, and snippets.

View abhirockzz's full-sized avatar
👋
fmt.Println(hello, world!)

Abhishek Gupta abhirockzz

👋
fmt.Println(hello, world!)
View GitHub Profile
package main
import (
"fmt"
"github.com/confluentinc/confluent-kafka-go/kafka"
)
func main() {
kafkaBroker := "localhost:9092"
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/confluentinc/confluent-kafka-go/kafka"
func main() {
kafkaBroker := "localhost:9092"
p, _ := kafka.NewProducer(&kafka.ConfigMap{"bootstrap.servers": kafkaBroker})
topic := "bar"
partition := kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny}
msg := &kafka.Message{TopicPartition: partition, Key: []byte("hello"), Value: []byte("world")}
p.Produce(msg, nil)
fmt.Println("done...")
}
package main
import (
"fmt"
"github.com/confluentinc/confluent-kafka-go/kafka"
)
func main() {
kafkaBroker := "foo:9092"
func main() {
kafkaBroker := "foo:9092"
p, err := kafka.NewProducer(&kafka.ConfigMap{"bootstrap.servers": kafkaBroker})
if err != nil {
fmt.Println("producer creation failed ", err.Error())
return
}
topic := "bar"
partition := kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny}
@abhirockzz
abhirockzz / Dockerfile
Last active November 29, 2018 10:26
Fn TensorFlow example Dockerfile
FROM fnproject/fn-java-fdk-build:jdk9-1.0.75 as build-stage
WORKDIR /function
ENV MAVEN_OPTS -Dhttp.proxyHost= -Dhttp.proxyPort= -Dhttps.proxyHost= -Dhttps.proxyPort= -Dhttp.nonProxyHosts= -Dmaven.repo.local=/usr/share/maven/ref/repository
ADD pom.xml /function/pom.xml
RUN ["mvn", "package", "dependency:copy-dependencies", "-DincludeScope=runtime", "-DskipTests=true", "-Dmdep.prependGroupId=true", "-DoutputDirectory=target", "--fail-never"]'
ARG TENSORFLOW_VERSION=1.12.0
RUN echo "using tensorflow version " $TENSORFLOW_VERSION
RUN curl -LJO https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-$TENSORFLOW_VERSION.jar
@abhirockzz
abhirockzz / call-functions-using-oci-go-sdk.go
Created November 15, 2018 12:06
Invoke a Function using OCI signature using OCI Go SDK
package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/oracle/oci-go-sdk/common"
...
var notification newReleaseNotification
json.NewDecoder(strings.NewReader(payload)).Decode(&notification)
err := tweet(notification.Details(), fnCtx.Config()["twitter_consumerkey"], fnCtx.Config()["twitter_consumersecret"], fnCtx.Config()["twitter_accesstoken"], fnCtx.Config()["twitter_accesstokensecret"])
if err != nil {
fdk.WriteStatus(out, 500)
prob := "Could not tweet new release details due to " + err.Error()
log.Println(prob)
return
...
func matchSignature(signature, key, payload string) bool {
mac := hmac.New(sha1.New, []byte(key))
mac.Write([]byte(payload))
expectedHMAC := mac.Sum(nil)
//signature format is sha1=foobarred
githubHMAC, _ := hex.DecodeString(strings.Split(signature, "=")[1])
match := hmac.Equal(githubHMAC, expectedHMAC)
return match
...
signatureFromGithub := fnCtx.Header().Get("X-Hub-Signature")
if !matchSignature(signatureFromGithub, fnCtx.Config()["github_webhook_secret"], payload) {
log.Println("Signature did not match. Webhook was not invoked by Github")
return
}
...