Skip to content

Instantly share code, notes, and snippets.

View krak3n's full-sized avatar
🏳️‍🌈

Chris Reeves krak3n

🏳️‍🌈
View GitHub Profile
type TestSetter struct {
cmd *redis.StatusCmd
}
func (t *TestSetter) Set(k string, v interface{}, d time.Duration) *redis.StatusCmd {
return t.cmd
}
// Unit - make it fail
func Test_setUser(t *testing.T) {
package main
import (
"bufio"
"bytes"
"flag"
"io/ioutil"
"path/filepath"
"testing"
)
package main
import (
"bufio"
"bytes"
"flag"
"io/ioutil"
"path/filepath"
"testing"
)
package main
import (
"bufio"
"bytes"
"io/ioutil"
"path/filepath"
"testing"
)
@krak3n
krak3n / main.go
Last active September 12, 2017 10:35
Testing using Golden files in Go
package main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"os"
)
@krak3n
krak3n / looplabel.go
Created September 3, 2015 10:19
Golang Loop Labels
func (p *PerceptorService) Run() {
for {
conn, _, err := d.Dial(host, headers)
if err != nil {
fmt.Printf("WS Connection Failure: %s", err)
time.Sleep(time.Second)
continue
}
ReadLoop:
for {
@krak3n
krak3n / consume.go
Created September 2, 2015 09:26
Fault Tolerant Redis Connections in Go
func (s *subscription) consume() {
for {
client := s.client
// Connect to Redis Pubsub Channel
pubsub := client.PubSub()
err := pubsub.Subscribe(s.channel)
// On error sleep for 1 second, log and continue to the next loop iteration
if err != nil {
log.Errorf("Redis Connection Error: %s", err)
time.Sleep(time.Second)
#!pydsl|stateconf -ps
include('apt-transport-https', 'python-software-properties')
lxc_docker = state('.lxc-docker')
lxc_docker.pkgrepo.managed(
name='deb https://get.docker.io/ubuntu docker main',
keyserver='hkp://keyserver.ubuntu.com:80',
keyid='36A1D7869245C8950F966E92D8576A8BA88D21E9')
lxc_docker.pkg.installed('lxc-docker') \
@krak3n
krak3n / gist:967a4fe638e42e8a832f
Created August 10, 2014 14:32
SaltStack PyDSL|Stateconf renderers
#!pydsl|stateconf -ps
state('.repo') \
.git.latest(
name='https://github.com/itagenten/tree',
rev='json',
target='/tmp/tree')
state('.make') \
.cmd.wait(
@krak3n
krak3n / python.snippets
Created July 30, 2014 10:11
Ultisnips Python Header Snippet
snippet #! "Shebang header for python scripts" b
#!/usr/bin/env python
# encoding: utf-8
"""
$1
`!p snip.rv = ''.join(['=' for i in range(0, len(t[1]))])`
$2
"""