Skip to content

Instantly share code, notes, and snippets.

View moritzheiber's full-sized avatar

Moritz Heiber moritzheiber

View GitHub Profile
@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 / 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 / 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 / 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 / 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