Skip to content

Instantly share code, notes, and snippets.

View viveksyngh's full-sized avatar

Vivek Kumar Singh viveksyngh

View GitHub Profile
package main
import (
"fmt"
)
//Person type to repersent a person
type Person struct {
FirstName string
LastName string
package main
import (
"fmt"
)
//Person type to repersent a person
type Person struct {
FirstName string
LastName string
package main
import (
"fmt"
)
//Person struct to represent a person
type Person struct {
FirstName string
LastName string
package main
import (
"fmt"
)
//Person struct to store person information
type Person struct {
FirstName string
LastName string
package main
import (
"fmt"
)
//Person struct to store person information
type Person struct {
FirstName string
LastName string
package main
import (
"bytes"
"context"
"errors"
"fmt"
"log"
"os/exec"
"time"
//CommandTimeoutWithContext command timeout with background context
func CommandTimeoutWithContext(command string, timeout time.Duration) (string, error) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
cmd := exec.CommandContext(ctx, "/bin/bash", "-c", command)
out, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded {
fmt.Println("Command timed out")
//CommandTimeoutWithChannel command timeout using channel and goroutine
func CommandTimeoutWithChannel(command string, timeout time.Duration) (string, error) {
cmd := exec.Command("/bin/bash", "-c", command)
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Start()
if err != nil {
log.Printf("Error : %s", err.Error())
return err.Error(), err
func CommandTimeoutWithTimer(command string, timeout time.Duration) (string, error) {
cmd := exec.Command("/bin/bash", "-c", command)
timer := time.AfterFunc(timeout, func() {
cmd.Process.Kill()
})
out, err := cmd.CombinedOutput()
isExpired := timer.Stop()
@viveksyngh
viveksyngh / deploy-openfaas-operator.md
Created August 21, 2018 13:44
Step by Step instructions to Deploy OpenFaaS Operator

Install helm CLI client on your system

On MacOS using Homebrew

$ brew install kubernetes-helm

From script

$ curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
$ chmod 700 get_helm.sh
$ ./get_helm.sh