harshadptl-blog
harshadptl-blog
The Absurdist
3 posts
Fine tuned
Don't wanna be here? Send us removal request.
harshadptl-blog · 8 years ago
Text
Json parsing in golang - gabs
Parsing a long, intricate json with nested layers can be a pain in golang. Either you create a struct to match the path to the fields you are interested in or you make a cumbersome iteration of interface assertions.
This is where gabs (https://github.com/Jeffail/gabs) comes in handy. Want a specific field located deep down in a nested json? It is just a one line function to get that value or an error if it is not present. You can also check whether a field exists or search through the values of an array.
The reverse is also true, you can generate crispy json on the fly without much hassle.
Gabs uses the ‘encoding/json’ package under the hood and its performance is comparable to that.
0 notes
harshadptl-blog · 8 years ago
Text
Fibonnaci series in golang
package main import ( "fmt" "time" ) func main() { fmt.Println("Hello, playground") fmt.Println(Fibonnaci(1)) fmt.Println(Fibonnaci(2)) fmt.Println(Fibonnaci(3)) fmt.Println(Fibonnaci(4)) fmt.Println(Fibonnaci(5)) fmt.Println(Fibonnaci(6)) fmt.Println(Fibonnaci(7)) fmt.Println(Fibonnaci(8)) fmt.Println(Fibonnaci(9)) fmt.Println(Fibonnaci(10)) fmt.Println(Fibonnaci(11)) fmt.Println(Fibonnaci(12)) fmt.Println(Fibonnaci(13)) fmt.Println(Fibonnaci(14)) fmt.Println(Fibonnaci(15)) fmt.Println(Fibonnaci(16)) fmt.Println(Fibonnaci(17)) fmt.Println(Fibonnaci(18)) fmt.Println(Fibonnaci(19)) fmt.Println(Fibonnaci(20)) fmt.Println(Fibonnaci(21)) fmt.Println(Fibonnaci(22)) fmt.Println(Fibonnaci(23)) fmt.Println(Fibonnaci(24)) fmt.Println(Fibonnaci(240)) } var lookup map[int]int64 = map[int]int64{} func Fibonnaci(i int) int64 { //memoisation val, ok := lookup[i] if ok { return val } if i == 1 { return 1 } else if i == 2 { return 1 } //basic formula to recurse val = Fibonnaci(i -1) + Fibonnaci(i -2) lookup[i] = val return val }
0 notes
harshadptl-blog · 13 years ago
Text
Life?
A. What is long and hard.
0 notes