View generics.go2
package main | |
import ( | |
"fmt" | |
"reflect" | |
) | |
func main() { | |
ss := []string{"hello", "generic", "world"} | |
is := []int{0, 3, 7} |
View main.go
package main | |
import "fmt" | |
type node struct { | |
v int | |
l *node | |
r *node | |
} |
View done_channel.go
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) |
View errors.go
package main | |
import "fmt" | |
type Error struct { | |
Message string | |
} | |
func (e *Error) Error() string { | |
return "an error occured" |
View main.go
// 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" |
View main.go
// 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" |
View query.go
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"strings" | |
"time" | |
) | |
// multiQuery uses a buffered channel, otherwise the two slower goroutines |
View pipeline.go
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 | |
} |
View gist:09e044a979a66a76893df950d823bd2e
ffmpeg -i test.mov \ | |
-pix_fmt yuv420p \ | |
-vcodec libx264 \ | |
-vf scale=640:-1 \ | |
-acodec aac \ | |
-vb 1024k \ | |
-minrate 1024k \ | |
-maxrate 1024k \ | |
-bufsize 1024k \ | |
-ar 44100 \ |
View interface.go
package account | |
import ( | |
"errors" | |
) | |
type CheckingAccount struct { | |
balance int | |
} |
NewerOlder