Skip to content

Instantly share code, notes, and snippets.

@alces
alces / git_log.sh
Last active July 3, 2020 11:58
Getting list of subset of the commits in a git branch in a reverse order with a custom format
# See git log --help for details
git log --reverse --after='Jan 19' --format='format:%h %an'
@alces
alces / check_keytabs.sh
Created January 7, 2020 12:36
Check all Kerberos keytabs in the current directory
#!/bin/bash
# Check all keytabs in the current directory
for kt in *.keytab
do
pr=$(klist -k $kt | tail -1 | awk '{print $2}')
echo -n "${kt}: "
kinit -kt $kt $pr > /dev/null 2>&1 && echo OK || echo FAILED
done
@alces
alces / get_java_rpm_version.py
Created December 31, 2019 14:00
Print Java RPM version (tested on RedHat 7)
import rpm
for pkg in rpm.TransactionSet().dbMatch('provides', 'java'):
print '%s:%s:%s:%s' % (pkg['name'], pkg['version'], pkg['release'], pkg['epoch'])
@alces
alces / md5_pass_encrypt.py
Created November 19, 2019 10:53
MD5 UN*X password encryption in Python
import crypt
crypt.crypt('my-secret-word', '$1$someSalt$')
@alces
alces / summarize_by_day.prometheus
Created November 6, 2019 05:13
Prometheus expression summarizing message count for a given Kafka topic by day
sum(increase(kafka_producer_topic_metrics_record_send_total{topic = "$my_topic_name"}[1d]))
@alces
alces / kafka_topics_delete.sh
Created October 30, 2019 05:56
Delete Kafka topics with matching names
TOPIC_NAME_REGEX='(CI|TST|IT)[0-9]'
ZOOKEEPER_ADDR=127.0.0.1:2181
for topic in $(kafka-topics --zookeeper $ZOOKEEPER_ADDR --list | egrep $TOPIC_NAME_REGEX)
do
kafka-topics --zookeeper $ZOOKEEPER_ADDR --delete --topic $topic
done
@alces
alces / Jenkinsfile
Created October 7, 2019 06:16
Ask for password in Jenkins pipeline
pipeline {
agent {
label 'Linux'
}
stages {
stage('ask') {
steps {
script {
def askpass = input(
message: 'Please enter the password',
@alces
alces / delete_old_schemas.py
Created September 19, 2019 07:51
Remove old schemes from Confluent Schema Registry
#!/usr/bin/env python
# Cleanup old schemas from schema registry
import httplib
import json
import re
DELETE_REGEX = 'IT6[0-6][0-9]-'
con = httplib.HTTPConnection('127.0.0.1', 8081)
@alces
alces / get_compressed_url.py
Created September 10, 2019 09:17
Fetch compressed content from an URL (e.g., usable with Lenses REST API)
#!/usr/bin/env python
# Get compressed URL content
import gzip
import StringIO
import urllib2
req = urllib2.Request('http://my.lenses.url/api/alerts',
headers = {
'Accept-encoding': 'gzip',
@alces
alces / check_srv.py
Created September 9, 2019 07:18
Check service availability from Python script
!/usr/bin/env python
# Check service availability
# Usage: $0 hostname port
import socket
import sys
if len(sys.argv) != 3:
sys.stderr.write("Usage: %s hostname port\n" % sys.argv[0])
sys.exit(2)