Skip to content

Instantly share code, notes, and snippets.

@rikonor
rikonor / main.py
Created September 1, 2020 01:16
Free disk-space in Python
import shutil
KB = 1024
MB = 1024 * KB
GB = 1024 * MB
shutil.disk_usage('/').free / GB
@rikonor
rikonor / main.go
Last active January 24, 2020 18:37
Unmarshaling JSON with multiple interface implementations
package main
import (
"encoding/json"
"errors"
"fmt"
"log"
"reflect"
)
@rikonor
rikonor / rename.go
Created April 23, 2019 08:29
Rename a file with fallback when encountering "invalid cross-device link"
package rename
// renameFile renames a file
// it can be used instead of os.Rename in cases where we attempt
// to move files between partitions (e.g when using Docker volumes)
func renameFile(src string, dst string) error {
err := os.Rename(src, dst)
if err == nil {
return nil
}
@rikonor
rikonor / writer.go
Created March 29, 2019 20:51
Self-healing io.Writer
package x
type InitializeFunc func() (io.Writer, error)
type Writer struct {
initFn InitializeFunc
backoff Backoff
w io.Writer
mu *sync.Mutex
@rikonor
rikonor / transaction.go
Created March 28, 2019 15:32
Transaction RoundTripper
package transaction
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"sync"
)
@rikonor
rikonor / index.js
Created January 23, 2019 04:10
Script to convert time objects in RethinkDB dumps
const fs = require("fs");
//
// Utilities
//
const isArray = a => {
return !!a && a.constructor === Array;
};
@rikonor
rikonor / main.go
Created January 19, 2019 02:43
Server Sent Events (SSE) Example in Go
package main
import (
"fmt"
"log"
"net/http"
"sync"
"time"
)
@rikonor
rikonor / main.go
Created January 2, 2019 20:31
control shell from go
package main
import (
"io"
"log"
"os"
"os/exec"
"time"
)
@rikonor
rikonor / main.go
Created December 28, 2018 21:50
loki simple usage
package main
import (
"net/url"
"os"
"time"
"log"
"github.com/cortexproject/cortex/pkg/util/flagext"
@rikonor
rikonor / main.go
Last active December 19, 2018 02:08
opencensus-verbose
package main
import (
"context"
"fmt"
"log"
"time"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"