Skip to content

Instantly share code, notes, and snippets.

View moehandi's full-sized avatar
:octocat:

M. Andi Saputra moehandi

:octocat:
  • Jakarta, Indonesia
View GitHub Profile
@moehandi
moehandi / EncodingResponseInterceptor.java
Created September 23, 2017 16:21
an android okhttp3 interceptor for set encoding response from server
class EncodingResponseInterceptor implements Interceptor {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
okhttp3.Response response = chain.proceed(request);
BufferedSource source = response.body().source();
source.request(Long.MAX_VALUE); // Buffer the entire body.
Buffer buffer = source.buffer();
@moehandi
moehandi / main.go
Created July 28, 2017 03:06
Go API versioning
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
// AnotherHandlerLatest is the newest version of AnotherHandler
@moehandi
moehandi / multipart_upload.go
Created May 24, 2017 01:59 — forked from mattetti/multipart_upload.go
Example of doing a multipart upload in Go (golang)
package main
import (
"bytes"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"os"
@moehandi
moehandi / reflection.go
Created April 30, 2017 20:21 — forked from drewolson/reflection.go
Golang Reflection Example
package main
import (
"fmt"
"reflect"
)
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`
curl -H "Content-Type:application/json" "Authorization:key=SERVER_KEY"
-X POST https://iid.googleapis.com/iid/v1:batchRemove
-d '{
"to": "/topics/sakit_perut",
"registration_tokens":[
"DeviceTokenFromUser"
]
}'
@moehandi
moehandi / time_tracer.go
Created April 24, 2017 16:11
function for tracking time used by function
package main
import (
"time"
"fmt"
"log"
"runtime"
"github.com/fatih/color"
)
@moehandi
moehandi / negroni-gorilla.go
Created April 23, 2017 02:30 — forked from danesparza/negroni-gorilla.go
Negroni with Gorilla mux subrouter
package main
import (
"fmt"
"github.com/codegangsta/negroni"
"github.com/gorilla/mux"
"log"
"net/http"
)
@moehandi
moehandi / main.go
Created April 23, 2017 02:13 — forked from Paulius-Maruska/main.go
Understanding http request routing with net/http and gorilla/mux.
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func handler(name string)func (http.ResponseWriter, *http.Request) {
dummyHandler := func (w http.ResponseWriter, r *http.Request) {
@moehandi
moehandi / .Title
Created April 22, 2017 18:47 — forked from congjf/.Title
Using MongoDB in golang with mgo
Using MongoDB in golang with mgo
@moehandi
moehandi / golang-nuts.go
Created April 14, 2017 06:32 — forked from ryanfitz/golang-nuts.go
two ways to call a function every 2 seconds
package main
import (
"fmt"
"time"
)
// Suggestions from golang-nuts
// http://play.golang.org/p/Ctg3_AQisl