Skip to content

Instantly share code, notes, and snippets.

View simcap's full-sized avatar

Simon simcap

View GitHub Profile
package client_test
import (
"bytes"
"encoding/json"
"strings"
"testing"
"github.com/wallix/gopeps/pepssdk/go/client"
)
package client
import (
"encoding/base64"
"reflect"
)
func DecodeBase64Payload(i interface{}) {
val, ok := getStructPtr(i)
if !ok {
@simcap
simcap / main.go
Created February 6, 2018 14:11
aws ec2 ips
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
package main
import "fmt"
func main() {
//params := []string{"1", "2", "3"}
fmt.Println(and(and(stringNode("1"), stringNode("2")), or(stringNode("3"))))
}
@simcap
simcap / weeklyc.go
Created June 16, 2017 15:07
Weekly report of code stats done historically
package main
import (
"context"
"flag"
"fmt"
"log"
"sort"
"time"
@simcap
simcap / ayncer.go
Created May 11, 2017 17:37
Run interdependent tasks asynchronously
package main
import (
"fmt"
"sync"
"time"
)
func main() {
cmds := []*cmd{
@simcap
simcap / console_printers.go
Created March 21, 2017 08:12
Golang friendly console printers
func printOk(s string, a ...interface{}) {
fmt.Printf("\033[32m[OK]\033[m %s\n", fmt.Sprintf(s, a...))
}
func printKo(s string, a ...interface{}) {
fmt.Fprintf(os.Stderr, "\033[31m[KO]\033[m %s\n", fmt.Sprintf(s, a...))
}
func printInfo(s string, a ...interface{}) {
fmt.Printf("[+] %s\n", fmt.Sprintf(s, a...))
@simcap
simcap / aggregator.go
Created June 6, 2016 13:01
Prez - Replay aggregator
func (a *replayAggregator) Run() {
var timer = time.NewTimer(a.flushFrequency)
var elapsed <-chan time.Time
var out chan []*sarama.ConsumerMessage
for {
select {
case msg := <-a.in:
if !a.slicer.add(msg) {
a.out <- a.slicer.flush()
@simcap
simcap / pooling.go
Created June 6, 2016 10:46
Prez - Collectors Pool
// ...
bodyBuf := getBuf()
_, err := bodyBuf.ReadFrom(body)
if err != nil {
putBuf(bodyBuf)
jsonError(w, http.StatusInternalServerError, "problem reading request body")
return
}
@simcap
simcap / collecting.go
Last active March 21, 2017 08:07
Prez- Collectors
func (c *Collector) ServeHTTP(w http.ResponseWriter, r *http.Request) {
limitReader := http.MaxBytesReader(w, r.Body, c.MaxPayloadSize)
payload, err := ioutil.ReadAll(limitReader)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
if IsIgnorableError(err) {
return
}
log.Printf("read body from %s: %s\n%s", err, RemoteAddr(r), payload)
return