Skip to content

Instantly share code, notes, and snippets.

View iv-m's full-sized avatar

Ivan Melnikov iv-m

  • BaseALT
  • Saratov, Russia (mostly)
View GitHub Profile
#!/usr/bin/env python
more = 0
less = 0
for n in range(100, 1000):
a = n / 100
b = n % 100 / 10
c = n % 10
if a > b > c:
more += 1
@iv-m
iv-m / spread_partitions_ring.sh
Created March 27, 2017 11:55
Reassign Kafka partitions, possibly increasing the replication factor
#!/bin/bash
#
# Spreads the topic among the active brokers.
# Can increase the replication factor; by default sets it to 3.
#
# Usage: $0 <ZOOKEEPER> <TOPIC> <REPLICATION_FACTOR>
set -eu ${DEBUG:+-x}
KAFKA_HOME="${KAFKA_HOME:-/opt/kafka}"
@iv-m
iv-m / add-gcloud-key.sh
Last active December 3, 2017 12:02
Adding your key to google cloud project metadata
#!/bin/bash
# Usage: add-gcloud-key.sh [PROJECT_ID]
set -eu
# Change these two lines
# USER=<your user name>
KEY="$HOME/.ssh/your_key.pub"
PROJECT="${1:+--project=$1}"
@iv-m
iv-m / spread_partitions.sh
Created January 19, 2017 15:31
Scripts that calls kafka-reassign-partitions and kafka-preferred-replica-election tools
#!/bin/bash
#
# Spreads the topic among the active brokers.
# Does not change the replication factor.
#
# Usage: $0 <ZOOKEEPER> <TOPIC>
set -eu
KAFKA_HOME="/crypt/home/iv/opt/kafka_2.11-0.10.1.0"
@iv-m
iv-m / log_diagram.py
Created January 5, 2017 10:11
Script that creates heatmap with log Y and color scales
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
# read the data
x, y = np.loadtxt('responses.dat', unpack=True)
# change absolute timestamps to relative to start, and convert to seconds:
x = (x - x[0]) / 1000.0
# Select which JDK to use
# Usage example:
# $ . use_java 1.8
JDK_DIR="$HOME/opt/jdk"
JDK_NAME=$(ls "$JDK_DIR" | grep "${1:-}" | tail -n1)
export JAVA_HOME="$JDK_DIR/$JDK_NAME"
export PATH="$JAVA_HOME/bin:$(awk -v RS=: -v ORS=: '/jdk/ {next} {print}' <<< "$PATH" | sed 's/:*$//g')"