Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am ribice on github.
  • I am ribice (https://keybase.io/ribice) on keybase.
  • I have a public key ASClwYeNkzBrC3mcLbp7Lc4Uf7DIo_SKsbbIQ1FGHi2nQgo

To claim this, I am signing this object:

@ribice
ribice / httperr.go
Created January 18, 2020 21:46
Handling http errors in Go
package httpresp
import (
"context"
"fmt"
"net/http"
"github.com/go-chi/render"
"github.com/go-pg/pg/v9"
@ribice
ribice / log.go
Last active May 8, 2023 19:36
Golang logging middleware
package log
import (
"context"
"net/http"
"net/http/httptest"
"net/http/httputil"
"os"
"time"
@ribice
ribice / main.go
Created February 3, 2020 10:02
Golang map used for concurrent read/write
package main
import (
"fmt"
"sync"
"time"
)
var countryCities = map[string][]string{}
var mutex = &sync.RWMutex{}
@ribice
ribice / caller.go
Last active July 7, 2023 07:07
A robust rabbitmq client for Go
go func() {
for {
err = rmq.Stream(cancelCtx)
if errors.Is(err, rabbitmq.ErrDisconnected) {
continue
}
break
}
}()
@ribice
ribice / trim-nulls.go
Last active June 20, 2022 12:57
Remove null values from JSON with Golang - https://www.ribice.ba/golang-null-values/
func removeNulls(m map[string]interface{}) {
val := reflect.ValueOf(m)
for _, e := range val.MapKeys() {
v := val.MapIndex(e)
if v.IsNil() {
delete(m, e.String())
continue
}
switch t := v.Interface().(type) {
// If key is a JSON object (Go Map), use recursion to go deeper
// NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to
// hook into various parts of the response process.
func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter {
_, fl := w.(http.Flusher)
bw := basicWriter{ResponseWriter: w}
if protoMajor == 2 {
_, ps := w.(http.Pusher)
if fl && ps {
@ribice
ribice / custom-domain.js
Last active December 21, 2021 22:55
Use custom domain for PolymerSearch app
// Change these to suit your case!
const config = {
dataset_url: "polymer/flixgem",
cf: {
cf: {
// Always cache this fetch regardless of content type
// for a max of 5 seconds before revalidating the resource
cacheTtl: 1800,
cacheEverything: true
}