Skip to content

Instantly share code, notes, and snippets.

View bodsch's full-sized avatar

Bodo Schulz bodsch

View GitHub Profile
@bodsch
bodsch / get_latest_release.sh
Created June 1, 2018 20:56 — forked from lukechilds/get_latest_release.sh
Shell - Get latest release from GitHub
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Usage
# $ get_latest_release "creationix/nvm"
# v0.31.4
@bodsch
bodsch / vercomp
Last active May 29, 2018 13:45
compare two strings in dot separated version format in Bash
#!/bin/bash
# https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash
vercomp() {
[[ $1 == $2 ]] && return 0
v1=$(echo "$1" | sed -e 's|-|.|g')
v2=$(echo "$2" | sed -e 's|-|.|g')
local IFS=.
@bodsch
bodsch / find-duplicate-files.bash
Last active February 8, 2019 20:39 — forked from OndraZizka/find-duplicate-files.bash
Finds duplicate files. An alternative to `fdupes -r -S .`
find -type f -size +3M -print0 | while IFS= read -r -d '' i; do
#echo $i
echo -n '.'
if grep -q "$i" md5-partial.txt; then
echo -n ':'; #-e "\n$i ---- Already counted, skipping.";
continue;
fi
#md5sum "$i" >> md5.txt
MD5=`dd bs=1M count=1 if="$i" status=none | md5sum`
MD5=`echo $MD5 | cut -d' ' -f1`
@bodsch
bodsch / bash_sockets.sh
Created April 19, 2018 07:52 — forked from CMCDragonkai/bash_sockets.sh
Bash: Socket Programming (Alternative to using Netcat)
#!/usr/bin/env bash
# consider if the server is passing a file like
while true; do nc -l 10000 <<<"hi"; done
# on our client side, we can consume this using nc
nc 10.0.0.1 10000
@bodsch
bodsch / whisper-calculator.py
Created April 17, 2018 14:59 — forked from jjmaestro/whisper-calculator.py
whisper-calculator.py: Calculates the size of the whisper storage for the given retention (in frequency:history format)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def archive_to_bytes(archive):
def to_seconds(s):
SECONDS_IN_A = {
's': 1,
'm': 1 * 60,
'h': 1 * 60 * 60,
@bodsch
bodsch / git-tag-delete-local-and-remote.sh
Created March 23, 2018 14:16 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@bodsch
bodsch / mass-aggregation-change.sh
Created January 26, 2018 15:07 — forked from kirbysayshi/mass-aggregation-change.sh
quick examples of how to change many many wsp (graphite/whisper) files settings
for f in $(find $1 -iname "*.wsp"); do
if [ -a $f ];
then /opt/graphite/bin/whisper-set-aggregation-method.py $f max;
fi;
done
@bodsch
bodsch / dns_check.rb
Created January 21, 2018 09:33 — forked from colszowka/dns_check.rb
Ruby DNS Check
require 'resolv'
class DnsCheck
attr_reader :host
def initialize(host)
@host = host
end
def a
@a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A)
@bodsch
bodsch / cirqle_queue_and_fifo.rb
Created December 11, 2017 13:16 — forked from prepor/cirqle_queue_and_fifo.rb
Simple ruby implementation of Cirqle Queue and FIFO
class CircleQueue
include Enumerable
class Head
attr_accessor :first, :last
def initialize
self.first = self
self.last = self
end
@bodsch
bodsch / gist:1b78bfa81512694ad63a23e8c2b15386
Created November 24, 2017 14:44
icinga2 extract api calls
#!/bin/bash
set -e
ICINGA_HOST=${ICINGA_HOST:-localhost}
ICINGA_API_PORT=${ICINGA_API_PORT:-5665}
ICINGA_API_USER=${ICINGA_API_USER:-root}
ICINGA_API_PASSWORD=${ICINGA_API_PASSWORD:-icinga}
types=