Skip to content

Instantly share code, notes, and snippets.

@monmohan
monmohan / x5c.der
Created November 11, 2019 14:06
Certificate created from x5c string
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
6a:4a:0f:86:8d:0c:26:be:7a
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=dev-ejtl988w.auth0.com
Validity
Not Before: Oct 29 22:07:22 2019 GMT
Not After : Jul 7 22:07:22 2033 GMT
@monmohan
monmohan / http_request_with_context.go
Last active July 11, 2020 16:57
Sample code to accompany the blog
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/http/httputil"
"time"
@monmohan
monmohan / request_hangs.go
Created July 11, 2020 16:59
Gist for Blog
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"net/http/httputil"
"time"
@monmohan
monmohan / context_propagation.go
Created July 12, 2020 09:56
Context propagation from client to server
unc runTestServer() string {
slowServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
incoming, _ := httputil.DumpRequest(r, false)
fmt.Printf("Server: Incoming Request %s", string(incoming))
ctx := r.Context()
echan := make(chan error)
go func() {
time.Sleep(12 * time.Second) // Do difficult Job
_, err := w.Write([]byte("Hello There!"))
echan <- err
@monmohan
monmohan / asymmetric.go
Created November 7, 2019 10:06
Sample JWS Validation with RSA Key
package jws
import (
"bytes"
"crypto"
"crypto/rsa"
_ "crypto/sha256"
"encoding/base64"
"encoding/binary"
"math/big"
func writeOps(outfile string) error {
f, err := os.OpenFile(outfile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Fatalf("Failed to create file %s", err.Error())
}
defer f.Close()
op1 := &typedefs.Patch_Copy{Start: 10, End: 100}
op2 := &typedefs.Patch_Insert{RawBytes: []byte{'a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e'}}
ops := []*typedefs.Patch{
syntax='proto3';
package typedefs;
option go_package ='./typedefs';
message Patch{
message Copy{
int64 start =1;
int64 end=2;
}
message Insert{
func readOps(outfile string) error {
in, err := ioutil.ReadFile(outfile)
if err != nil {
return err
}
instructions := &typedefs.Instructions{}
if err := proto.Unmarshal(in, instructions); err != nil {
return err
}
for _, patch := range instructions.Operations {
func serializeBookDataset(protoOutFile string) error {
w, err := os.OpenFile(protoOutFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer w.Close()
csvFile, err := os.Open("books.csv")
if err != nil {
return err
func readBookDataset(protoInFile string) error {
var rLen uint32
var book typedefs.Book
r, err := os.Open(protoInFile)
if err != nil {
return err
}
defer r.Close()