Skip to content

Instantly share code, notes, and snippets.

View fiorix's full-sized avatar

Alexandre Fiori fiorix

View GitHub Profile
@fiorix
fiorix / sse.go
Last active October 19, 2023 08:05
Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
// Go and Server Sent Events for HTTP/1.1 and HTTP/2.0
//go:generate go run $GOROOT/src/crypto/tls/generate_cert.go -host localhost
package main
import (
"fmt"
"io"
"log"
"net/http"
@fiorix
fiorix / ipcontinent.go
Created January 14, 2015 21:29
GEOIP continent lookup
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"net"
"net/url"
"os"
@fiorix
fiorix / OAuth2.md
Created November 21, 2014 02:47 — forked from mziwisky/Oauth2.md

OAUTH2

The Problem

I’m a web app that wants to allow other web apps access to my users’ information, but I want to ensure that the user says it’s ok.

The Solution

I can’t trust the other web apps, so I must interact with my users directly. I’ll let them know that the other app is trying to get their info, and ask whether they want to grant that permission. Oauth defines a way to initiate that permission verification from the other app’s site so that the user experience is smooth. If the user grants permission, I issue an AuthToken to the other app which it can use to make requests for that user's info.

Note on encryption

Oauth2 has nothing to do with encryption -- it relies upon SSL to keep things (like the client app’s shared_secret) secure.

@fiorix
fiorix / gist:a527556896522b1b1d8c
Created October 23, 2014 16:14
v8.go binding structs in structs
package v8
import "testing"
type User struct {
Name string
Info UserInfo
}
type UserInfo struct {
diff --git a/examples/httpassembly/main.go b/examples/httpassembly/main.go
index 51ead6e..28c2a63 100644
--- a/examples/httpassembly/main.go
+++ b/examples/httpassembly/main.go
@@ -11,17 +11,18 @@ package main
import (
"bufio"
+ "flag"
+ "io"
@fiorix
fiorix / proxy.go
Created June 27, 2014 03:31
HTTP reverse proxy that uses Redis for vhost routing.
// HTTP reverse proxy that uses Redis for vhost routing.
//
// ADDR=:8080 REDIS=127.0.0.1:6379 go run proxy.go
// redis-cli set localhost:8080 http://sports.yahoo.com
// curl -v localhost:8080
package main
import (
"errors"
@fiorix
fiorix / cmd-pipe.go
Last active November 7, 2015 23:00
Using command stdin/out/err to pipe stuff from and to Go.
package main
import (
"encoding/json"
"errors"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
@fiorix
fiorix / ms-exchange-auth.go
Created April 30, 2014 01:16
Authenticate on Microsoft Exchange via the Outlook Web App
// Copyright 2014 Alexandre Fiori. All rights reserved.
// Use of this source code is governed by a BSD-style license.
//
// Auhenticate on Microsoft Exchange via the Outlook Web App.
package main
import (
"fmt"
"log"
@fiorix
fiorix / gist:11047922
Created April 18, 2014 14:48
Go's encoding/binary performance
package main
import (
"bytes"
"encoding/binary"
"math"
"testing"
)
func BenchmarkEncodeFloat1(b *testing.B) {
@fiorix
fiorix / gist:9927296
Created April 2, 2014 03:03
Reading sequential pcap payload in Go
func pcapReader(filename string) (io.ReadCloser, error) {
pr, pw, err := os.Pipe()
if err != nil {
return nil, err
}
handle, err := pcap.OpenOffline(filename)
if err != nil {
return nil, err
}