Skip to content

Instantly share code, notes, and snippets.

View nesv's full-sized avatar

Nick Saika nesv

View GitHub Profile
@nesv
nesv / dynect_funcopt.go
Last active February 11, 2017 20:46
Functional options for nesv/go-dynect
package dynect
import (
"crypto/tls"
"net/http"
)
type ClientOption func(*Client)
func InsecureSkipVerify() ClientOption {
@nesv
nesv / errors.go
Last active June 30, 2016 19:07
Parse SPF records
package spf
import (
"errors"
"fmt"
)
var (
ErrInvalidPrefix = errors.New("invalid or missing spf prefix")
)
@nesv
nesv / flags.go
Created June 30, 2016 13:45
Get input from command-line arguments, or fallback to STDIN
package main
import (
"bufio"
"flag"
"os"
"strings"
)
func main() {
@nesv
nesv / with_tx.go
Last active May 16, 2016 22:45
A function that wraps your SQL interactions in a transaction, and handles errors
var db *sql.DB
func WithTx(fn func(*sql.Tx) error) error {
tx, err := db.Begin()
if err != nil {
return err
}
if err := fn(tx); err != nil {
if err := tx.Rollback(); err != nil {
@nesv
nesv / httpclient.go
Created January 19, 2016 21:26
Sample HTTP client
package main
import (
"log"
"net/http"
"net/url"
"time"
)
func main() {
@nesv
nesv / factory.go
Created January 28, 2015 21:39
Factory pattern in Go (potentially?)
package provider
// Some empty types for "completeness".
type (
VMConfig struct{}
VM struct{}
)
type InfraProvider interface {
Launch(cfg VMConfig) (*VM, error)
@nesv
nesv / keybase.md
Created September 17, 2014 21:21
keybase.md

Keybase proof

I hereby claim:

  • I am nesv on github.
  • I am nesv (https://keybase.io/nesv) on keybase.
  • I have a public key whose fingerprint is 392E 5F87 22FE 2CC3 5605 D4B6 77FA 3F86 5BAA E611

To claim this, I am signing this object:

@nesv
nesv / dynect_example.go
Last active August 29, 2015 14:01
An example on how to use the go-dynect/dynect package
package main
import (
"log"
"strings"
"github.com/nesv/go-dynect/dynect"
)
func main() {
@nesv
nesv / main.go
Last active April 12, 2018 11:59
package main
import (
"flag"
"fmt"
"net/http"
)
var (
NWorkers = flag.Int("n", 4, "The number of workers to start")
@nesv
nesv / dispatcher.go
Last active December 11, 2018 21:41
package main
import "fmt"
var WorkerQueue chan chan WorkRequest
func StartDispatcher(nworkers int) {
// First, initialize the channel we are going to but the workers' work channels into.
WorkerQueue = make(chan chan WorkRequest, nworkers)