Skip to content

Instantly share code, notes, and snippets.

Paul Henry f3nry

Block or report user

Report or block f3nry

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@f3nry
f3nry / main.go
Created Feb 1, 2019
Third Attempt: Length-prefix Construction
View main.go
const (
payloadLen = 1
sizeLen = 4
headerLen = payloadLen + sizeLen
)
func msgHeader(data []byte) (hdr []byte, payload []byte) {
hdr = make([]byte, headerLen)
hdr[0] = byte(uint8(0))
@f3nry
f3nry / main.go
Created Feb 1, 2019
Second Attempt: Responding with protobuf
View main.go
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
message := &api.AliveResponse{Message: "Hello, world."}
b, err := proto.Marshal(message)
if err != nil {
return events.APIGatewayProxyResponse{
StatusCode: 500,
}, err
}
@f3nry
f3nry / output.log
Created Feb 1, 2019
gRPC Log Output
View output.log
http2: Framer 0xc0002c8380: wrote SETTINGS len=0
http2: Framer 0xc0002c8380: read SETTINGS len=18, settings: MAX_CONCURRENT_STREAMS=128, INITIAL_WINDOW_SIZE=65536, MAX_FRAME_SIZE=16777215
http2: Framer 0xc0002c8380: read WINDOW_UPDATE len=4 (conn) incr=2147418112
http2: Framer 0xc0002c8380: wrote SETTINGS flags=ACK len=0
http2: Framer 0xc0002c8380: wrote HEADERS flags=END_HEADERS stream=1 len=84
http2: Framer 0xc0002c8380: wrote DATA flags=END_STREAM stream=1 len=12 data="\x00\x00\x00\x00\a\n\x05Hello"
http2: Framer 0xc0002c8380: read SETTINGS flags=ACK len=0
http2: Framer 0xc0002c8380: read HEADERS flags=END_HEADERS stream=1 len=313
http2: Framer 0xc0002c8380: read DATA stream=1 len=15 data="\n\rHello, world."
http2: Framer 0xc0002c8380: read DATA flags=END_STREAM stream=1 len=0 data=""
@f3nry
f3nry / main.go
Created Feb 1, 2019
API Gateway gRPC: First attempt
View main.go
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
return events.APIGatewayProxyResponse{
Body: "Hello, world.",
Headers: map[string]string{
"Content-Type": "application/grpc+proto",
},
StatusCode: 200,
}, nil
}
@f3nry
f3nry / main.go
Last active Feb 12, 2019
Simple Go gRPC Client
View main.go
package main
import (
"context"
"flag"
"fmt"
"log"
"google.golang.org/grpc"
@f3nry
f3nry / protoc-gen-go.sh
Created Feb 1, 2019
Generating proto Go code from a definition
View protoc-gen-go.sh
brew install protobuf
go get -u google.golang.org/grpc
go get -u github.com/golang/protobuf/protoc-gen-go
protoc -I=./api --go_out=plugins=grpc:./api ./api/hello.proto
@f3nry
f3nry / hello.proto
Created Feb 1, 2019
Simple gRPC Protobuf
View hello.proto
// Location: api/hello.proto
syntax = "proto3";
option go_package = "api";
service Prod {
rpc Alive(AliveRequest) returns (AliveResponse) {}
}
message AliveRequest {
View gist:aeef7017add51080bcc83d9561a7b244
### Keybase proof
I hereby claim:
* I am f3nry on github.
* I am fenry (https://keybase.io/fenry) on keybase.
* I have a public key ASBPaQKqvBh3005h5-Y0h5Itb0kOhYOc-jtjEI1zHDu8vwo
To claim this, I am signing this object:
View gist:56f3ebd19e1e2947b96d
adder(3) do
adder(2) do
3
end
end
# => 8
@f3nry
f3nry / gist:4753221
Last active Dec 12, 2015
Initializing an array and setting an incredibly high index causes Ruby to immediately use all of the available memory due to initializing all previous values in the array to the high index. I'm using ruby 1.9.3p286 on a Macbook with 8 gb of ram.
View gist:4753221
some_array = []
some_array[Time.now.to_i] = 1
You can’t perform that action at this time.