Skip to content

Instantly share code, notes, and snippets.

View JensRantil's full-sized avatar

Jens Rantil JensRantil

View GitHub Profile
module github.com/JensRantil/kafka-pinger
go 1.15
require (
github.com/frankban/quicktest v1.11.3 // indirect
github.com/golang/protobuf v1.5.1 // indirect
github.com/golang/snappy v0.0.2 // indirect
github.com/klauspost/compress v1.11.7 // indirect
github.com/kr/text v0.2.0 // indirect
@JensRantil
JensRantil / tombstone-count.sh
Last active March 31, 2021 18:04
How to count number of tombstones per partition key in one or multiple sstables.
#!/bin/bash
#
# Counts number of tombstones per partition key in one or multiple sstables.
#
# Usage: ./tombstone-count.sh /var/lib/cassandra/data/mykeyspace/mytable/*-Data.db
#
# Sample output:
# "40e6a9839bf44bdaa624cc53e96733fe" 8
# "8e177ab222c14f868bcb6d2922b18d2b" 8
# "28aaa9db0dad4ae78cabe8bcc25d14a3" 9
import random
# Number of VMs that will be restarted.
N=16
# Bucket the nodes randomly by hashing their hostnames and putting them in hourly buckets.
BUCKETS = 7*24
# Number of simulations we will make.
SIMULATIONS=100000
collisions = 0
@JensRantil
JensRantil / example-view.json
Last active February 8, 2021 21:31
Example event view projection for CouchDB event store.
{
"_id": "_design/eventProjections",
"views": {
"map": "function(doc) {
if (doc.aggregateType=='contact' &&
(doc.event.type=='ContactCreated' ||
doc.event.type=='DescriptionChanged') &&
doc.event.description) {
var colon = doc._id.indexOf(':');
var version = parseInt(doc._id.substr(colon + 1));
@JensRantil
JensRantil / example-output.txt
Last active October 23, 2020 14:01
Kafka script to generate Bash commands that will recreate Kafka topics. Possibly useful for backups of topics.
./bin/kafka-topics.sh --if-not-exists --zookeeper $(grep -E zookeeper.connect= ./config/server.properties | cut -d= -f2) --create --partitions 12 --replication-factor 3 --topic my-topic-1 --config retention.ms=3600000 --config min.insync.replicas=2
./bin/kafka-topics.sh --if-not-exists --zookeeper $(grep -E zookeeper.connect= ./config/server.properties | cut -d= -f2) --create --partitions 1 --replication-factor 3 --topic my-topic-2 --config min.insync.replicas=2
module github.com/JensRantil/yo
go 1.13
require github.com/nats-io/nats-streaming-server v0.16.2
@JensRantil
JensRantil / channel_demo.go
Last active August 18, 2019 01:44
Simplification of sample code at https://blog.gopheracademy.com/advent-2015/automi-stream-processing-over-go-channels/ Best practise is 1) to inject channels and 2) avoid concurrency in APIs.
func ingest(out <-chan []string) {
out <- []string{"aaaa", "bbb"}
out <- []string{"cccccc", "dddddd"}
out <- []string{"e", "fffff", "g"}
close(out)
}
func process(in <-chan []string, out <-chan int) {
for data := range in {
for _, word := range data {
@JensRantil
JensRantil / go.mod
Last active May 8, 2019 08:10
TopK implementation with filtering from dictionary.
module github.com/JensRantil/topk-challenge
require (
github.com/funkygao/golib v0.0.0-20180314131852-90d4905c1961 // indirect
github.com/google/pprof v0.0.0-20190502144155-8358a9778bd1 // indirect
github.com/hashicorp/go-multierror v1.0.0
github.com/pkg/errors v0.8.1
golang.org/x/arch v0.0.0-20190312162104-788fe5ffcd8c // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58
)
@JensRantil
JensRantil / go.mod
Last active May 3, 2019 05:29
Demonstrating potential memory leak.
module github.com/tink-ab/tink-backend/src/nats-streaming-pinger
require (
github.com/armon/go-metrics v0.0.0-20190423201044-2801d9688273 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/hashicorp/go-msgpack v0.5.4 // indirect
github.com/hashicorp/raft v1.0.1 // indirect
github.com/lib/pq v1.1.0 // indirect
github.com/nats-io/gnatsd v1.4.1 // indirect
@JensRantil
JensRantil / go.mod
Last active April 25, 2019 09:35
A tiny application that connects to NATS and measure latencies to NATS.
module github.com/tink-ab/tink-backend/src/nats-checker
require (
github.com/nats-io/gnatsd v1.4.1 // indirect
github.com/nats-io/go-nats v1.7.2
github.com/nats-io/nkeys v0.0.2 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/oklog/ulid v1.3.1
github.com/prometheus/client_golang v0.9.2
golang.org/x/sys v0.0.0-20190425045458-9f0b1ff7b46a // indirect