Posts on Twitter:

Nagios, 2nd Edition :







Eliminate the legal risk of distributing improperly licensed and modules with our turn-key OEM editions. Download solution sheet:










kdungs is the Leader of the CH leaderboard for Go with Nano codebase size. Technical debt density for public code from GitHub is 1.16666667. More on .













































Posts on Tumblr:

medium.com
The anatomy of Arrays in Go

An array is a collection of same data type. For example, an array of integers or array of strings. Since Go is statically typed language, mixing different values belonging to different data types in an array is not allowed. In Go, array has a fixed length. via Pocket

youtube

A quick demonstration of the app.

Cancellation in Golang

Cancellation is very common, but a bit hard to implement.

Golang provides cancellation to ease the effort. Let’s take a example, I want to traverse a directory, and stop while I have listed enough files.

max := 5
numbers := make(chan int)
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)

Here I created max files to list, a channel to print numbers, and a context for cancellation.

count := 0
for num := range numbers {
    fmt.Printf("count: %d, num: %d\n", count, num)
    count++
    if count >= max {
        fmt.Println("cancel")
        cancel()
    }
}

Print numbers is simple, when maxFiles reaches, invoke cancel function to stop producer feeding in numbers channel.

outer:
  for i := start; i < end; i++ {
    select {
    case <- ctx.Done():
      fmt.Println("get done")
      break outer
    case numbers <- i:
      time.Sleep(500 * time.Millisecond)
      // do nothing
    }
  }

The producer procedure is a little complex, before feeding every number, it will check cancellcation. Here “break outer” is necessary, or break will only break select statement.

When we have multiple producers, the statement “if count >= max” will reach multi times. As multiple producers is waiting on “case numbers <- i”, after max reaches, another producer may still writing to numbers channel. To make code correct, another condition check is needs before printing number. As the code becomes ugly, I don’t recommend cancellation on multiple producers.

Besides Context, we can also use an empty struct channel, when closing, every receiver will receive the broadcast. Actually, ctx.Done() is an empty struct channel(<- chan struct{}), it’s identical to use ctx.Done() or empty struct channel manually.

Reference Markdowns

For any new programmer, I am starting to create quick reference guides to programming languages. If you are advanced these are probably not for you, I will work on advance ones later on. If you are starting out and need a quick reference go to, these could help. You can pull these off my repo. I literally started this today so hang in there, it will be updated a lot over the next few weeks.


https://github.com/leethen3rd/code-reference-markdowns

youtube

(via David Crawshaw SQLite and Go - YouTube)

youtube

(via Building modern desktop apps in Go - YouTube)

compiling .proto file with protoc

%userprofile%\go\src\github.com\edt-gRPC\proto\sftp>protoc –go_out=plugins=grpc:. sftp.proto

Setup GIT for SSH on Windows 10

Once we switched to go we started to clone project including all dependencies 

i.e. 

go get github.com/Deutsche-Boerse/gRPC

normally we run :

git config --global url."git@github.com:".insteadOf "https://github.com/"
go get github.com/Deutsche-Boerse/gRPC - Clone project
go get ./... - Install project dependencies

Because traffic goes through SSH you need to make additional steps on your machine:

git config --global user.email="your@email.com"

git config --global user.name="Your Name"

#open Git Bash from START menu and run 

$ ssh-keygen -t rsa -C "your@email.com" 

# generate key pair and add public key to your github
(https://github.com/settings/keys)

#add github public key to your GIT
$ ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts


 

And that’s all! enjoy…

heap in Go

Решая задачку по кучам на го, решил посмотреть как сделано в пакете container. Так вот там так же container/heap container/heap/heap.go:91 обычные двоичные кучи ;)

func up(h Interface, j int) {
  for {
     i := (j - 1) / 2 // parent
     if i == j || !h.Less(j, i) {
        break
     }
     h.Swap(i, j)
     j = i
  }
}

func down(h Interface, i0, n int) bool {
  i := i0
  for {
     j1 := 2*i + 1
     if j1 >= n || j1 < 0 { // j1 < 0 after int overflow
        break
     }
     j := j1 // left child
     if j2 := j1 + 1; j2 < n && h.Less(j2, j1) {
        j = j2 // = 2*i + 2  // right child
     }
     if !h.Less(j, i) {
        break
     }
     h.Swap(i, j)
     i = j
  }
  return i > i0
}