Skip to content

Instantly share code, notes, and snippets.

@mikedemers
mikedemers / unshredder.rb
Created November 12, 2011 04:08
image unshredder for instagram engineering challenge
#!/usr/bin/env ruby
#
# image unshredder for instagram engineering challenge:
# <http://instagram-engineering.tumblr.com/post/12651721845>
#
# author: @mikedemers <[email protected]>
#
# t-shirt size: large :)
require 'rubygems'
@mikedemers
mikedemers / imagemagick.rb
Created April 6, 2012 18:45
Homebrew recipe for ImageMagick 6.6.0
# some credit to https://github.com/maddox/magick-installer
require 'formula'
def ghostscript_srsly?
ARGV.include? '--with-ghostscript'
end
def ghostscript_fonts?
File.directory? "#{HOMEBREW_PREFIX}/share/ghostscript/fonts"
end
@mikedemers
mikedemers / ghetto-histo.rb
Created July 16, 2012 23:57
ghetto histo
#!/usr/bin/env ruby
def histogram(h, width=40)
max_key_size, max_value = 0, 0
h.each_pair do |k,v|
s = k.to_s.size
max_key_size = s if s > max_key_size
max_value = v if v > max_value
end
@mikedemers
mikedemers / archiver.rb
Created March 20, 2013 18:36
Ruby script that sends a file to an S3 bucket
#!/usr/bin/env ruby
require 'rubygems'
require 'aws/s3'
bucket = ARGV[0].to_s.strip
filepath = ARGV[1].to_s.strip
filename = ARGV[2] ? ARGV[2].to_s.strip : File.basename(filepath)
AWS::S3::Base.establish_connection!(
@mikedemers
mikedemers / backup-db.sh
Created March 20, 2013 18:37
Shell script that dumps a database and uses archiver.rb to send to an S3 bucket. I run this from cron.
#!/bin/bash
BUDIR="/home/mike/backup/db"
UN="username"
PW="password"
DB="database_name"
BUCKET="bucket-name"
ARCHIVER="/home/mike/backup/bin/archiver.rb"
@mikedemers
mikedemers / backup-logs.sh
Created March 20, 2013 18:39
Shell script that compresses log files and uses archiver.rb to send them to an S3 bucket. I run this from cron.
#!/bin/bash
# TODO: this needs to be updated to work with logrotate...
BUDIR="/home/mike/backup/logs"
BUCKET="APPNAME-full-logs"
ARCHIVER="/home/mike/backup/bin/archiver.rb"
GZIP="/bin/gzip"
@mikedemers
mikedemers / gmail-archiver.rb
Created October 4, 2013 04:03
Archive all email in a google mail account
#!/usr/bin/env ruby
require 'rubygems'
require 'gmail'
require 'fileutils'
username = ''
password = ''
root = Dir.pwd
@mikedemers
mikedemers / serve.rb
Created February 18, 2014 19:51
serve.rb
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
# add custom MIME types
HTTPUtils::DefaultMimeTypes.store('swf', 'application/x-shockwave-flash')
port = rand(1000) + 4000
path = File.expand_path((ARGV[0].nil?) ? File.dirname(__FILE__) : ARGV[0])