This file contains hidden or 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 orDone(done <-chan bool, ch <-chan Data) <-chan Data { | |
| stream := make(chan Data) | |
| go func() { | |
| defer close(stream) | |
| for { | |
| select { | |
| case <-done: | |
| return | |
| case v, ok := <-ch: | |
| if !ok { |
This file contains hidden or 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 ( | |
| "context" | |
| "log" | |
| "net/http" | |
| "os" | |
| "os/signal" | |
| "syscall" | |
| "time" |
This file contains hidden or 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 ( | |
| "fmt" | |
| "time" | |
| ) | |
| func main() { | |
| ch := make(chan int) | |
| time.AfterFunc(5*time.Second, func() { |
This file contains hidden or 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 ( | |
| "errors" | |
| "fmt" | |
| "go/ast" | |
| "go/build" | |
| "go/parser" | |
| "go/token" | |
| "log" |
This file contains hidden or 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 ( | |
| "database/sql" | |
| "database/sql/driver" | |
| "errors" | |
| "fmt" | |
| "reflect" | |
| sqlmock "github.com/nasa9084/go-sql-mock" |
This file contains hidden or 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
| #!/bin/bash | |
| for i in {0..2}; do | |
| docker-machine create -d xhyve --xhyve-memory-size 512 consul-$i | |
| done | |
| for i in {0..2}; do | |
| docker $(docker-machine config consul-$i) run \ | |
| -d \ | |
| --name consul$i \ |
This file contains hidden or 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 (v Value) IsZero() bool { | |
| switch v.Kind() { | |
| case reflect.Array, reflect.String: | |
| return v.Len() == 0 | |
| case reflect.Bool: | |
| return !v.Bool() | |
| case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | |
| return v.Int() == 0 | |
| case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: | |
| return v.Uint() == 0 |
This file contains hidden or 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
| set -xe | |
| # create docker-machines | |
| for i in {0..2} | |
| do | |
| # create manager nodes | |
| docker-machine create -d virtualbox --virtualbox-memory="512" --virtualbox-hostonly-cidr="10.20.${i}.1/24" manager-${i} | |
| # create worker nodes | |
| for n in {0..1} | |
| do |
This file contains hidden or 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
| expect -c ' | |
| spawn vagrant destroy | |
| expect "y/N" | |
| send "y" | |
| exit 0 | |
| '; vagrant up |
This file contains hidden or 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
| # ... omit import and variable definitions | |
| while True: | |
| ipt = input('input member:score> ') | |
| if ipt == 'show': | |
| ranking = redis.zrange('ranking:', 0, 5, withscores=True)[::-1] | |
| for i, m in enumerate(ranking): | |
| values = { | |
| 'rank': i + 1, | |
| 'member': m[0].decode(), | |
| 'point': m[1] |