Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Last active September 8, 2017 06:58
Show Gist options
  • Save alextanhongpin/c05a8e59156b8d5b5e16c17bc0ca6d46 to your computer and use it in GitHub Desktop.
Save alextanhongpin/c05a8e59156b8d5b5e16c17bc0ca6d46 to your computer and use it in GitHub Desktop.
Useful go tips
package main
import (
"fmt"
)
func main() {
var a []string= []string{"a", "b"}
var b []string = []string{"c", "d"}
fmt.Println("Hello, playground", append(a, b...))
}
package main
import (
"fmt"
"math"
"strconv"
)
func main() {
n := int64(14)
v := string(strconv.FormatInt(n, 2))
for k, v := range Reverse(v) {
if string(v) != "0" {
fmt.Println(math.Pow(2, float64(k)))
}
}
}
func Reverse(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
}
// Code to write to json file
outjson, _ := json.Marshal(job)
err := ioutil.WriteFile("output.json", outjson, 0644)
log.Println(err)
// Go doesn't have math.round
// Multiple tags is not supported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment