Skip to content

Instantly share code, notes, and snippets.

@rikonor
rikonor / main.go
Created February 3, 2021 04:43
ETH Convert JSON Keystore to Private Key
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
void main() {
var d = StubDoer(() {
print("Also doing...");
});
d = wrapWithTimes(100)(d);
d = wrapWithMetrics()(d);
d = wrapWithTracing()(d);
doStuff(d);
export MUSIC_PATH=/media/pi/CC72-D726
docker network create koel
docker run \
-d \
--name mysql \
--network koel \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_USER=koel \
@rikonor
rikonor / main.go
Created September 29, 2020 16:56
Allow traffic from subnet
package main
import (
"fmt"
"log"
"net"
"net/http"
"strings"
)
@rikonor
rikonor / mw.go
Created September 29, 2020 16:20
HTTP Middleware Helpers
type wrapHandlerFunc func(hn http.Handler, pattern string) http.HandlerFunc
// mwLogs is used to wrap a handler so that it will emit HTTP logs for every request
func mwLogs(logger *zap.Logger, hn handlerWithError) handlerWithError {
return func(w http.ResponseWriter, r *http.Request) *apiError {
// Track time
startTime := time.Now()
// Track response status code
t := status.Track(w)
@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"
)