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 ( | |
"flag" | |
"fmt" | |
"github.com/Masterminds/semver/v3" | |
) | |
var vFlag = flag.String("version", "0.1", "version to check") |
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
// Given an array of integers that is already sorted in ascending | |
// order find two numbers such that they add up to a specific target number. | |
// | |
// The function twoSum should return indices of the two numbers such that | |
// they add up to the target where index1 must be less than index2. | |
package main | |
import ( | |
"errors" | |
"fmt" |
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
// Go 2 Playground: https://go2goplay.golang.org/ | |
// | |
// Or to install the go2go tool: | |
// git clone https://go.googlesource.com/go goroot | |
// cd ./goroot | |
// git checkout dev.go2go | |
// cd ./src | |
// CGO_ENABLED=0 ./all.bash | |
// export PATH=/path/to/your/goroot/bin:$PATH | |
// |
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 "fmt" | |
type node struct { | |
v int | |
l *node | |
r *node | |
} |
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 ( | |
"fmt" | |
"time" | |
) | |
// multiples uses a done channel to shut down | |
func multiples(i int) (chan int, chan struct{}) { | |
out := make(chan int) |
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 "fmt" | |
type Error struct { | |
Message string | |
} | |
func (e *Error) Error() string { | |
return "an error occured" |
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
// Converts the data created by Fitbit export from the output JSON | |
// to comma-separated values. | |
// go run main.go > weight.csv | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"os" |
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
// Do not use package math/rand to generate keys, even throwaway ones. | |
// Unseeded, the generator is completely predictable. Seeded with | |
// time.Nanoseconds(), there are just a few bits of entropy. Instead, | |
// use crypto/rand's Reader, and if you need text, print to hexadecimal | |
// or base64. | |
package main | |
import ( | |
"crypto/rand" | |
"fmt" |
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 ( | |
"fmt" | |
"math/rand" | |
"strings" | |
"time" | |
) | |
// multiQuery uses a buffered channel, otherwise the two slower goroutines |
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 "fmt" | |
// first adds 20 integers in sequence to a channel then closes | |
// it, signalling all of the writing is done. | |
func first(out chan<- int) { | |
for x := 0; x < 20; x++ { | |
out <- x | |
} |
NewerOlder