Skip to content

Instantly share code, notes, and snippets.

@cannium
cannium / main.go
Created March 9, 2020 09:25
billing map-reduce test
@@ -0,0 +1,29 @@
package main
import (
"fmt"
"github.com/journeymidnight/yig-billing/helper"
pb "github.com/journeymidnight/yig-billing/mapreduce/proto"
"google.golang.org/grpc"
"net"
)
@cannium
cannium / json.go
Created February 24, 2020 10:33
DB JSON type
package model
import (
"database/sql/driver"
"encoding/json"
"errors"
)
type JSON []byte
@cannium
cannium / yig.sql
Last active November 27, 2019 07:49
yig DB schema review
drop table if exists clusters;
create table clusters (
id varchar(64) not null default '',
pool varchar(16) not null default '',
weight int not null default 0,
primary key (id, pool)
);
drop table if exists buckets;
create table buckets (
@cannium
cannium / pressure.go
Last active July 31, 2019 15:08
files to do performance test for seaweedfs-cannyls
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
@cannium
cannium / get_original_dst.go
Created July 17, 2019 09:45 — forked from fangdingjun/get_original_dst.go
golang: get the original destination for the socket when redirect by linux iptables
// get the original destination for the socket when redirect by linux iptables
// refer to https://raw.githubusercontent.com/missdeer/avege/master/src/inbound/redir/redir_iptables.go
//
const (
SO_ORIGINAL_DST = 80
IP6T_SO_ORIGINAL_DST = 80
)
func getOriginalDst(clientConn *net.TCPConn) (rawaddr []byte, host string, newTCPConn *net.TCPConn, err error) {
if clientConn == nil {
@cannium
cannium / perf.go
Created September 13, 2018 03:40
a small performance test
package main
import (
"fmt"
"time"
ma "github.com/multiformats/go-multiaddr"
)
var addrs = []string{
"/ip4/127.0.0.1/tcp/4001/ipfs/QmPdJvfK74MknGSYS2E54EEzKcEY6c19D8BzcCPbW7Sjna",
@cannium
cannium / AES.go
Created April 16, 2018 09:43 — forked from shautzin/AES.go
AES/CBC/PKCS5Padding implementation by Golang
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"fmt"
)
func main() {
@cannium
cannium / aes-256-gcm.go
Last active May 9, 2021 20:19
golang aes-256-gcm
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
)
@cannium
cannium / gist:66a752ace83ddb80d2a7
Created November 18, 2015 10:27
funny/sync race conditons
==================
WARNING: DATA RACE
Read by goroutine 18:
github.com/funny/sync.(*monitor).diagnose()
/root/go/src/github.com/funny/sync/deadlock.go:95 +0x5e
github.com/funny/sync.(*monitor).wait()
/root/go/src/github.com/funny/sync/deadlock.go:89 +0x3a5
github.com/funny/sync.(*RWMutex).RLock()
/root/go/src/github.com/funny/sync/deadlock.go:45 +0x3e
github.com/influxdb/influxdb/meta.(*Store).Leader()
@cannium
cannium / gist:7aa58f13c834920bb32c
Created July 6, 2015 02:01
example for double fork
import os
import sys
print 'pid,pgid,sid', os.getpid(), os.getpgid(0), os.getsid(0)
pid = os.fork()
if pid > 0:
sys.exit(0)
print 'pid,pgid,sid', os.getpid(), os.getpgid(0), os.getsid(0)