Skip to content

Instantly share code, notes, and snippets.

View odeke-em's full-sized avatar

Emmanuel T Odeke odeke-em

View GitHub Profile
@odeke-em
odeke-em / full-snippet.go
Created February 20, 2017 08:34
full snippet for the earthquakes compile type assertions
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"strconv"
)
@odeke-em
odeke-em / cancellation-on-success.go
Created December 28, 2016 20:16
Demo how to cancel asynchronous processing after getting exactly n successful results
package main
import (
"fmt"
"time"
"github.com/odeke-em/semalim"
)
type echo struct {
@odeke-em
odeke-em / log.md
Created October 29, 2016 18:25
Inspecting bodies and requests from various methods
$ for method in "PATCH" "DELETE" "POST" "GET" "PUT" "AMETHOD";do go run main.go --body hello --method $method >> log;done && cat log
PATCH / HTTP/1.1
Host: 127.0.0.1:64022
Accept-Encoding: gzip
Content-Length: 5
User-Agent: Go-http-client/1.1

hello
DELETE / HTTP/1.1
@odeke-em
odeke-em / marshalJSON_unmarshalJSON.go
Last active December 30, 2022 10:44
Example on custom UnmarshalJSON and MarshalJSON
package main
import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
)
@odeke-em
odeke-em / main.go
Created August 21, 2016 03:16
File, Function name and line information for debugging call sites
package main
import (
"fmt"
"runtime"
)
func debugPrintf(fmt_ string, args ...interface{}) {
programCounter, file, line, _ := runtime.Caller(1)
fn := runtime.FuncForPC(programCounter)
@odeke-em
odeke-em / mcopy.go
Last active July 30, 2016 19:15
Duplicate a stream n times, and have a notifier to tell you when it is done.
package mcopy
import (
"io"
)
func DuplicateToManyStreams(r io.Reader, n uint) ([]io.Reader, chan bool) {
var readers []io.Reader
var writers []io.Writer
@odeke-em
odeke-em / ioVsos_test.go
Created June 26, 2016 22:22
io-vs-os:Pipe-comparisons to see which is better for use
package io_vs_os_test
import (
"io"
"io/ioutil"
"os"
"testing"
)
var (
@odeke-em
odeke-em / requester.go
Last active July 6, 2016 19:39
Make nparallel connections to a URI, nreq times. Sample for challenge https://twitter.com/indutny/status/738573179229249537
package main
import (
"crypto/tls"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@odeke-em
odeke-em / dcrypto-cli.go
Created May 22, 2016 23:02
CLI for testing out our new Pure Go file encrypter/decrypter
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/odeke-em/drive/src/dcrypto"
)
@odeke-em
odeke-em / client.go
Created May 13, 2016 03:23
Code to setup reproduction to try to fix https://github.com/golang/go/issues/15664
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)