Skip to content

Instantly share code, notes, and snippets.

View betandr's full-sized avatar
🦄
Vague, but exciting...

Beth Anderson betandr

🦄
Vague, but exciting...
View GitHub Profile
@betandr
betandr / named_reciever_vs_pointer_receiver.go
Last active February 5, 2019 17:04
Go Named Reciever vs Pointer Receiver
package main
import "fmt"
type Mutatable struct {
a int
b int
}
func (m Mutatable) UpdateReceiver() {
@betandr
betandr / capturing_iteration_variables.go
Last active February 5, 2019 17:04
Capturing iteration variables with Go
package main
import "fmt"
func main() {
tempDirs := []string{"one", "two", "three", "four", "five"}
var rmdirs []func()
for _, dir := range tempDirs {
// Without this `dir := dir` line rmdir func would use outer `dir`
@betandr
betandr / pass_by_ref_and_val.go
Last active February 5, 2019 17:04
Pass by reference and value
package main
import "fmt"
type T struct{ X int }
// mutable
func inc1(t *T) {
t.X++
}
@betandr
betandr / prometheus.go
Last active February 5, 2019 17:04
Prometheus example in Go
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
@betandr
betandr / sieve.go
Last active February 5, 2019 17:04
Sieve of Eratosthenes implemented with Go goroutines and channels
package main
import "fmt"
// Generate primes and send them to channel `ch`
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i
}
}
@betandr
betandr / struct.go
Created December 4, 2018 13:20
Structs with pointers in Go
pp := new(Point)
*pp = Point{1, 2}
// is equvalent to
pp := &Point{1, 2}
@betandr
betandr / main.go
Created November 27, 2018 16:46
Graph using maps in Go
package main
import "fmt"
var graph = make(map[string]map[string]bool)
func addEdge(from, to string) {
edges := graph[from]
if edges == nil {
edges = make(map[string]bool)
@betandr
betandr / istio_manifests.yaml
Last active October 4, 2018 17:17
Istio Basic Workloads
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gateway
annotations:
kubernetes.io/ingress.class: "istio"
spec:
rules:
- http:
paths:
@betandr
betandr / giffit.go
Created September 9, 2018 08:40
Very Basic Gif Maker
package main
import "image"
import "image/gif"
import "os"
func main() {
files := os.Args[1:]
// files := []string{"g1.gif", "g2.gif","g3.gif", "g2.gif"}
@betandr
betandr / fork_bombs.md
Created July 20, 2018 12:27
Fork Bombs

Fork Bombs

Bash

:(){ :|:& };:

Windows bat