Skip to content

Instantly share code, notes, and snippets.

View moritzheiber's full-sized avatar

Moritz Heiber moritzheiber

View GitHub Profile
@moritzheiber
moritzheiber / gist:2438021
Created April 21, 2012 16:05
foreverb calling foreverb
# foreverb master
# written in pseudo-code
Foreverb.run :queue => current_queue do
check_for_new_command_in_queue (start/stop workers)
start/stop worksers (as foreverb "sub"-workers)
before :each do
check_amqp_for_new_messages (using carrot or official client)
process_message
@moritzheiber
moritzheiber / checker.rb
Created October 10, 2012 08:04
ruby mysql checker
require 'rubygems'
require 'mysql2'
client = Mysql2::Client.new(:host => '127.0.0.1',:username => 'checker',:password => 'checker')
client.query("show slave status").each do |r|
lag = r['Seconds_Behind_Master']
io = r['Slave_IO_Running']
puts "row = #{r}"
puts "lag = #{lag}"
puts "io = #{io}"
@moritzheiber
moritzheiber / install_gem_chef.rb
Created November 12, 2013 10:08
Install a ruby gem from git with chef
# I had to do this once because a ruby gem's newer version wasn't officially released yet
# Thought it might come in handy once again
# Note: You will need to install all the required dependencies to compile/package your gem beforehand, i.e. build-essential/make and friends
include_recipe 'git'
git_repo_url = 'https://some.github.com/repository'
gem_name = 'name_of_my_gem'
tmp_gem_dir = "/tmp/#{gem_name}"
options = '--no-rdoc --no-ri' # usually you don't need those on a chef enabled machine
@moritzheiber
moritzheiber / sync-s3-bucket.rb
Last active January 1, 2016 04:59
Sync a very large (+1000000 objects) S3 bucket locally
#!/usr/bin/env ruby
#
# This script is intended for syncing very large S3 buckets (+1000000 objects)
# to a local storage. I couldn't find any other tools which wouldn't crap out
# because of the rather high number of objects to take care of (I'm looking at you,
# s3cmd!).
#
# What it does:
# - Takes a batch of #batch_size (it's 500 right now) of objects
# - Spawns 500 threads and downloads each one individually
@moritzheiber
moritzheiber / csv-add-password.rb
Created July 1, 2014 15:15
Adding a randomly generated password to the end of a CSV file
require 'csv'
require 'securerandom'
PASS_LENGTH = 16
raise "You need to specify a csv file" if ARGV[0].nil? || !File.exists?(ARGV[0])
csv_file = ARGV[0]
def password
@moritzheiber
moritzheiber / csv-import.rb
Created July 1, 2014 15:15
Importing users listed in a CSV file into a Samba4 AD
require 'csv'
SAMBA_TOOL='/usr/bin/samba-tool'
raise "You need to specify a csv file" if ARGV[0].nil? || !File.exists?(ARGV[0])
CSV::Converters[:blank_to_nil] = lambda do |field|
field && field.empty? ? nil : field
end
@moritzheiber
moritzheiber / duplicity-backup.sh
Last active October 27, 2022 05:37
Duplicity backup script
#!/bin/bash
#The MIT License (MIT)
#
#Copyright (c) 2014 Moritz Heiber <hello@heiber.im>
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
@moritzheiber
moritzheiber / renew_certs.sh
Created March 6, 2016 14:31
Renew domains with Let's Encrypt
#!/bin/bash
set -xeu
declare -a DOMAINS
DOMAINS=(enter your domains here) # separated by spaces
DIR="/tmp/letsencrypt-auto"
LETSENCRYPT="/home/moe/letsencrypt"
URL="https://acme-v01.api.letsencrypt.org/directory"
@moritzheiber
moritzheiber / docker_cleanup.sh
Created June 24, 2016 08:58
Cleaning up your Docker environment
#!/bin/bash
set -ex
# Remove containers
docker ps -q -f status=exited | xargs --no-run-if-empty docker rm
# Remove volumes
docker volume ls -qf dangling=true | xargs --no-run-if-empty docker volume rm
@moritzheiber
moritzheiber / crash.log
Created September 12, 2016 09:34
Terraform crash log
-----BEGIN PGP MESSAGE-----
hQEMA9X0O2Qy6nfzAQf/RTwCGoVX6uX+Hd6aRE4mjxR3cUIMuWhvEbNUHfNIZlF7
XD5CGx/3dC/bGVatS4g5MeWOz43Sb9jAuvrTYgsSuWRwIocZNRIhpQndBOORCTdb
IO4mp05KjpaXueg8YN/T7W8cCNnMfaexIlmh1ellcm8bHQglf1gQVyyfgJ7+Xv2m
v16B3a3sRvGACLyulXKwHf9xoEfE0OjEisxuU0NbiA/MQVo95hFhot+B9ArRhvhb
6+Iox6yF94wW9HbRESoxDS3Q+CajEfpGlFXmt+eSHUpqRpozauwECbLyXn+dTPW8
DYbQxUbFg9FWXMsX0NfdO4Y1cpP76L2cAPWMUBROMtLtAd7d9csinNDF+ZmFNi5V
xXLrc4ztgxHCedaZRkdbtdWj8dZGdznMLlnIufuN2u7LH3SaVd4NQoIvMMozuD2Z
yM5w1zNoxyP/TUJMvKnMdu5UahgZK7vYMEIRZb95VNzruayx0veFp4s+IuK3aRfH