Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
♠ ace hacker
committed
Jan 16, 2013
1 parent
547dd93
commit 8f92d79
Showing
34 changed files
with
828 additions
and
1,179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
l2met |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: bundle exec bin/web | ||
outlet: bundle exec bin/dboutlet | ||
web: l2met | ||
librato: librato |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package db | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
"github.com/bmizerany/pq" | ||
"os" | ||
"sync" | ||
) | ||
|
||
var ( | ||
PGLocker sync.Mutex | ||
PGRLocker sync.Mutex | ||
PG *sql.DB | ||
PGR *sql.DB | ||
) | ||
|
||
func init() { | ||
url := os.Getenv("DATABASE_URL") | ||
if len(url) == 0 { | ||
fmt.Printf("at=error error=\"must set DATABASE_URL\"\n") | ||
os.Exit(1) | ||
} | ||
str, err := pq.ParseURL(url) | ||
if err != nil { | ||
fmt.Printf("at=error error=\"unable to parse DATABASE_URL\"\n") | ||
os.Exit(1) | ||
} | ||
PG, err = sql.Open("postgres", str) | ||
if err != nil { | ||
fmt.Printf("at=error error=%s\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
rurl := os.Getenv("DATABASE_READ_URL") | ||
if len(url) == 0 { | ||
fmt.Printf("at=error error=\"must set DATABASE_READ_URL\"\n") | ||
os.Exit(1) | ||
} | ||
rstr, err := pq.ParseURL(rurl) | ||
if err != nil { | ||
fmt.Printf("at=error error=\"unable to parse DATABASE_READ_URL\"\n") | ||
os.Exit(1) | ||
} | ||
PGR, err = sql.Open("postgres", rstr) | ||
if err != nil { | ||
fmt.Printf("at=error error=%s\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package encoding | ||
|
||
import ( | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
var ( | ||
msgPat = regexp.MustCompile(`( *)([a-zA-Z0-9\_\-\.]+)=?(([a-zA-Z0-9\.\-\_\.]+)|("([^\"]+)"))?`) | ||
) | ||
|
||
func ParseMsgData(msg []byte) (map[string]string, error) { | ||
d := make(map[string]string) | ||
pairs := msgPat.FindAllStringSubmatch(string(msg), -1) | ||
for i := range pairs { | ||
k := pairs[i][2] | ||
v := pairs[i][4] | ||
v2 := pairs[i][6] | ||
if len(v) == 0 { | ||
v = v2 | ||
} | ||
d[k] = v | ||
} | ||
return d, nil | ||
} | ||
|
||
func DecodeArray(b []byte, dest *[]float64) { | ||
// pq returns something like: {1.0, 2.0} | ||
// let us remove the { and the } | ||
trimed := b[1:(len(b) - 1)] | ||
// Assuming the numbers are seperated by commas. | ||
numbers := strings.Split(string(trimed), ",") | ||
// Showing that we can do cool things with floats. | ||
for _, x := range numbers { | ||
f, err := strconv.ParseFloat(x, 64) | ||
if err == nil { | ||
*dest = append(*dest, f) | ||
} | ||
} | ||
} | ||
|
||
func EncodeArray(arr []float64) []byte { | ||
// Convert our array into a string that looks like: {1,2,3.0} | ||
var d []byte | ||
d = append(d, '{') | ||
for i, f := range arr { | ||
st := strconv.FormatFloat(f, 'f', 5, 64) | ||
for _, s := range st { | ||
d = append(d, byte(s)) | ||
} | ||
if i != (len(arr) - 1) { | ||
d = append(d, ',') | ||
} | ||
} | ||
d = append(d, '}') | ||
return d | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.