Skip to content

Instantly share code, notes, and snippets.

🦄
Vague, but exciting...

Beth Anderson betandr

🦄
Vague, but exciting...
Block or report user

Report or block betandr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@betandr
betandr / main.go
Created Jan 16, 2020
Generate keys with crypto/rand
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"
@betandr
betandr / query.go
Last active Dec 30, 2019
Make multiple queries and return the fastest in Go, using goroutines and a buffered channel
View query.go
package main
import (
"fmt"
"math/rand"
"strings"
"time"
)
// multiQuery uses a buffered channel, otherwise the two slower goroutines
@betandr
betandr / pipeline.go
Created Dec 30, 2019
Simple pipeline example using Go channels
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 \
@betandr
betandr / interface.go
Created Jul 31, 2019
Encapsulation with an interface
View interface.go
package account
import (
"errors"
)
type CheckingAccount struct {
balance int
}
@betandr
betandr / primes.go
Created Jul 25, 2019
Primes generator using filters and pipes pattern
View primes.go
package main
import (
"fmt"
)
func main() {
// runtime.GOMAXPROCS(2)
ch := make(chan int)
@betandr
betandr / distance.go
Created Jul 24, 2019
Ambiguous struct embedding resolution
View distance.go
package main
import (
"fmt"
"os"
"strconv"
)
type Cycle struct{}
@betandr
betandr / message.go
Created Jul 24, 2019
Message-passing with channels.
View message.go
package main
import "fmt"
type Greeter struct{}
func (p *Greeter) greet(s string) {
fmt.Printf("Hello, %s!\n", s)
}
@betandr
betandr / camel_to_title.go
Created Jul 23, 2019
Expand a CamelCase string to a Title string
View camel_to_title.go
package main
import (
"fmt"
"unicode"
)
// expandTitle turns a string like NewYork into New York by finding a capital
// letter and inserting a space.
func camelToTitle(name string) string {
@betandr
betandr / main.go
Last active Jul 18, 2019
Pass by reference and value example
View main.go
package main
import "fmt"
type T struct{ X int }
func inc1(t *T) {
t.X++
}
You can’t perform that action at this time.