Skip to content

Instantly share code, notes, and snippets.

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

Chris Reeves krak3n

🏳️‍🌈
View GitHub Profile
@krak3n
krak3n / gist:9fa1268ee0a92a67f71a
Created July 4, 2014 13:38
Avoid DetachedInstanceError in Flask-SQLAlchemy
# The following produces DetachedInstanceError
app = Flask(__name__)
db = SQLAlchemy(app)
class Foo(db.Model):
id = db.Column(db.Integer, primary_key=True)
foo = Foo()
db.session.add(foo)
@krak3n
krak3n / gist:5884562
Last active March 2, 2019 19:37
Mocking open for ConfigParser.RawConfigParser.readfp() for unit testing.
import io
import six
from mock import patch
from six.moves import configparser as ConfigParser
data = """
[section]
key = value
"""
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 / gist:5884788
Created June 28, 2013 13:46
Facio's new CLI interface
Facio
Facio is a project scaffolding tool originally developed for Django and
expanded to be framework agnostic. You can use Facio to bootstrap any sort
of project.
Documentation:
https://facio.readthedocs.org
Usage:
@krak3n
krak3n / gist:3476269
Created August 26, 2012 08:40
Enable symlinks in Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Ensure you set your file system mount to NFS, you'll need to provide the VM with a static IP for a hostonly network.
#
Vagrant::Config.run do |config|
# ...
@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 {