Skip to content

Instantly share code, notes, and snippets.

View zeddee's full-sized avatar

Zed zeddee

View GitHub Profile
@zeddee
zeddee / readsecret.go
Last active August 10, 2018 19:08
Read secrets from a file, where secrets are the format `KEY=VALUE`, and returns a map. Access by calling secret["KEY"] => "VALUE".
package main
import (
"bufio"
"log"
"os"
"strings"
)
// ReadSecret gets API Key from a file
@zeddee
zeddee / golang-tls.md
Created August 12, 2018 05:16 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@zeddee
zeddee / load-json.go
Last active January 19, 2019 10:41
Quick example of loading json data with Golang
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
)
type jsonOrder map[string]struct {
{{ define "default" }}
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MessageBird Verify Example</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/main.css" type="text/css"/>
</head>
@zeddee
zeddee / listtz.go
Last active August 21, 2018 15:36
Quick example where we (1) load a list of locales from json, and (2) print out the time now in those locales.
// Get list of timezones from ftp://munnari.oz.au/pub/oldtz/
// ftp://munnari.oz.au/pub/oldtz/tzdata2018d.tar.gz
// Locale entries must exist in:
// go/1.10.3/libexec/lib/time/zoneinfo.zip
package main
import (
"encoding/json"
package main
import (
"fmt"
"log"
"time"
)
// func Date(year int, month Month, day, hour, min, sec, nsec int, loc *Location) Time
@zeddee
zeddee / get-from-random-list-of-phone-numbers.go
Last active January 19, 2019 10:39
Go program to output random string from a simple csv list
package main
import (
"encoding/csv"
"log"
"math/rand"
"os"
"time"
)
@zeddee
zeddee / Dockerfile
Created October 14, 2018 11:46
Quick messagebird golang container
# Fixed at 1.11, when they introduced dependency management
FROM golang:1.11
RUN mkdir -p /app
RUN go get -u github.com/messagebird/go-rest-api
WORKDIR /app
VOLUME ["/app"]

The MIT "Moral Machine" and Other Ethical Mistakes

Moved here

package main
import (
"errors"
"fmt"
"log"
"strings"
)
// Markov chain to predict the next word, given a set of sentences