Skip to content

Instantly share code, notes, and snippets.

View blasterpal's full-sized avatar

Hank Beaver blasterpal

View GitHub Profile
@blasterpal
blasterpal / find_modified_last_4_hours.sh
Created January 24, 2013 22:13
Find files in current directly modified in last 4 hours
find . -type f -mtime -4h -d 1
@blasterpal
blasterpal / check_slave_status.rb
Created January 23, 2013 21:11
Check MySQL Slave status from Shell using Ruby
#!/usr/bin/env ruby
@slave_status = Hash[%x(mysql -uroot -e 'SHOW SLAVE STATUS \\\G').split(/\s*\n\s*/).map { |e| spl = e.split(/\:\s*/); spl.size == 2 ? [spl.first, spl.last] : nil }.compact]
def slave_healthy?
@slave_status['Slave_IO_Running'] == 'Yes' &&
@slave_status['Slave_SQL_Running'] == 'Yes' &&
@slave_status['Seconds_Behind_Master'] != 'NULL' &&
@slave_status['Seconds_Behind_Master'].to_i < 1800
end
@blasterpal
blasterpal / httpclient-utf8-error-2.rb
Created January 17, 2013 18:58
Modified version of Encoding Error https://gist.github.com/4534675 Gist. That emulates FbGraph 2.6.2 fix.
#!/usr/bin/env ruby
#
# How to make Ruby httpclient throw Encoding::CompatibilityError with Image/IO object on EY Server.
# Use case is update a Facebook object with a parameter containing UTF-8 escaped strings and a file upload.
# Execute with 'bundle exec <script>' on a Gemfile containing httpclient or use system gem
# The problem lies in Encoding and the request.dump method used by FbGraph debug.
# On Engine Yard servers the POSTing with httpclient with multipart Content-Types ( a file upload + the UTF-8 body content) causes
# issue when reading the image from disk. If the image is a string, no problem.
@blasterpal
blasterpal / httpclient_utf8_error.rb
Last active December 11, 2015 02:59
How to make Ruby httpclient throw Encoding::CompatibilityError with Image/IO object. Use case is to update a Facebook object with a parameter containing UTF-8 escaped strings and a file upload.
#!/usr/bin/env ruby
#
# How to make Ruby httpclient throw Encoding::CompatibilityError with Image/IO object.
# Use case is update a Facebook object with a parameter containing UTF-8 escaped strings and a file upload.
# This has been duplicated on OSX 10.7 and Engine Yard, Gentoo.
# Execute with 'bundle exec <script>' on a Gemfile containing httpclient or use system gem
# The problem lies in Encoding and the request.dump method used by FbGraph debug.
# On Engine Yard servers the POSTing with httpclient with multipart Content-Types ( a file upload + the UTF-8 body content) causes
@blasterpal
blasterpal / fog_pull_s3_backup.rb
Last active December 10, 2015 21:38
Use fog to grab a file from S3 and save locally on server. Useful for transferring large backups from server to server where network prevents direct communication.
require 'fog'
# Fetch and save backup on TARGET
storage = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => ENV['AWS_KEY'], :aws_secret_access_key => ENV['AWS_SECRET']})
dir = storage.directories.get('<YOUR DIR>')
file = dir.files.get "<S3 PATH TO FILE>"
output = File.new "<LOCAL FILE PATH>", "w"
output.write file.body
output.close
@blasterpal
blasterpal / sidekiq-queue-names-being-processed.rb
Created January 7, 2013 20:20
Sidekiq - list of queues being processed currently
Sidekiq.redis {|conn| conn.smembers('workers').map{|w| msg = conn.get("worker:#{w}"); msg ? [w, Sidekiq.load_json(msg)] : nil; }.compact.map{|w| w[1]["queue"]}}
@blasterpal
blasterpal / sidekiq-active-worker-info.rb
Created January 7, 2013 20:19
Sidekiq - get info from active workers
Sidekiq.redis {|conn| conn.smembers('workers').map{|w| msg = conn.get("worker:#{w}"); msg ? [w, Sidekiq.load_json(msg)] : nil; }.compact}
@blasterpal
blasterpal / ssl-ssh-cheatsheet.txt
Created December 11, 2012 14:36
SSH - SSL Cheatsheet
1. Convert PEM into pub SSH key file:
ssh-keygen -e -f amazon-ec2-key.pem >> amazon-ec2-key.pem.pub
2. Generate a PEM from a SSH key:
openssl rsa -in my_tunneler -outform pem > my_tunneler.pem
@blasterpal
blasterpal / simple-init-script.sh
Created November 24, 2012 18:15
simple-init-script.sh
#!/bin/bash
# from http://ubuntuserverguide.com/2012/06/how-to-installing-nginx-with-php5-and-mysql-support-on-ubuntu-server-12-04-lts.html
PHP_SCRIPT=/usr/sbin/php-fastcgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
PID_DIR=/var/run/php-fastcgi
PID_FILE=/var/run/php-fastcgi/php-fastcgi.pid
RET_VAL=0
case "$1" in
@blasterpal
blasterpal / egrep_du_sum.sh
Created November 6, 2012 13:28
Calculate size of all files/directories that match pattern in Gb
ls | egrep -e '^[a-z0-9]{8}-.*' | xargs du | awk '{ SUM += $1} END {print SUM/1024/1024}'