Skip to content

Instantly share code, notes, and snippets.

@arriqaaq
arriqaaq / guardian_gaza.ipynb
Last active Aug 29, 2015 — forked from darribas/guardian_gaza.ipynb
A IPython Notebook to analyze the Gaza-Israel 2012 crisis
View guardian_gaza.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View go-log-benchmark
package main
import (
"fmt"
zerolog "github.com/rs/zerolog/log"
"github.com/sirupsen/logrus"
"go.uber.org/zap"
"log"
"net/http"
)
View gist:aefc61daddaa5a8509120e27d2a76880
package main
import "github.com/tidwall/gjson"
const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}`
type User struct{
FirstName string `gjson:"name.first"`
LastName string `gjson:"name.last"`
Age string `gjson:"age"`
View http.go
package main
import (
"log"
"net/http"
)
func main() {
// Simple static webserver:
log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
View server-close.go
errs := make(chan error, 2)
server := &http.Server{Addr: ":8080", Handler: handler}
go func() {
errs <- server.ListenAndServe()
}
go func() {
// Setting up signal capturing
c := make(chan os.Signal)
View server.go
package main
import (
"fmt"
lucio "github.com/arriqaaq/server"
"log"
"net/http"
"os"
)
View service-a-1.go
func main() {
client := boomerang.NewHttpClient(clientCnf)
mux := http.NewServeMux()
mux.HandleFunc("/ping", func(w http.ResponseWriter, req *http.Request) {
request, _ := http.NewRequest("GET", URL_SERVICE_B, strings.NewReader("gopher"))
resp, httpErr := client.Do(request)
if httpErr != nil {
fmt.Println("ping failed ", httpErr)
w.Write([]byte("fail"))
return
View service-b-1.go
func main() {
client := redis.NewClient(&redis.Options{Addr:"localhost:6379",Password: "", DB:0, // use default DB})
pong, err := client.Ping().Result()
if err == nil {
log.Fatalln(pong, err)
}
client.Set("isco", "alarcon", 0).Err()
promCtx := boomerang.NewPrometheusMetrics("service_b", "info")
mux := http.NewServeMux()
mux.HandleFunc("/pong", func(w http.ResponseWriter, req *http.Request) {
View chord-1.go
// fingerEntry represents a single finger table entry
type fingerEntry struct {
Id []byte // ID hash of (n + 2^i) mod (2^m)
Node *internal.Node
}
func newFingerTable(node *internal.Node, m int) fingerTable {
ft := make([]*fingerEntry, m)
for i := range ft {
ft[i] = newFingerEntry(fingerID(node.Id, i, m), node)
View chord-2.go
type Node struct {
*internal.Node
predecessor *internal.Node
successor *internal.Node
fingerTable fingerTable
storage Storage
transport Transport
}