Skip to content

Instantly share code, notes, and snippets.

View gist:a33e4deebdd71c73a439f9bbe2d38a44
put =map(range(1,100), 'printf(''goreplay20191201_%d,'', v:val)')
@onemouth
onemouth / mcount.go
Last active Sep 22, 2019
get mcount from go
View mcount.go
package main
import (
"C"
"fmt"
"runtime"
"runtime/debug"
"time"
"os/exec"
_ "unsafe"
View test.py
class MedianFinder:
def __init__(self):
"""
initialize your data structure here.
"""
self.minHeap = []
self.maxHeap = []
def addNum(self, num: int) -> None:
View hashadd.go
func (m *Map) Add(nodes ...string) {
for _, n := range nodes {
for i := 0; i < m.replicas; i++ {
hash := int(m.hash([]byte(strconv.Itoa(i) + " " + n)))
m.nodes = append(m.nodes, hash)
m.hashMap[hash] = n
}
}
sort.Ints(m.nodes)
}
View ch.c
int ch(int key, int num_buckets) {
random.seed(key);
int b = -1;
int j = 0;
while (j < num_buckets) {
b = j;
double r = random.next();
j = floor((b + 1) / r);
}
return b;
View ch.c
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) {
int64_t b = -1, j = 0;
while (j < num_buckets) {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1));
}
return b;
}
View ch.c
int ch(int key, int num_buckets) {
random.seed(key);
int b = 0;
for (int j = 1; j < num_buckets; j++) {
if (random.next() < 1.0 / (j + 1))
b = j;
}
return b;
}
View test.go
func (m *Map) Get(key string) string {
hash := int(m.hash([]byte(key)))
idx := sort.Search(len(m.keys),
func(i int) bool { return m.keys[i] >= hash }
)
if idx == len(m.keys) {
idx = 0
}
return m.hashMap[m.keys[idx]]
}
View jwt.go
package main
import (
"encoding/base64"
"fmt"
"crypto/hmac"
"crypto/sha256"
)
// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
View jwt.go
package main
import (
"encoding/base64"
"fmt"
"crypto/hmac"
"crypto/sha256"
)
// ValidMAC reports whether messageMAC is a valid HMAC tag for message.
You can’t perform that action at this time.