Skip to content

Instantly share code, notes, and snippets.

View wr0ngway's full-sized avatar

Matt Conway wr0ngway

View GitHub Profile
#!/usr/bin/env ruby
require 'date'
require 'rexml/document'
include REXML # so that we don't have to prefix everything with REXML::...
blogger_id = "111111111111"
blog_title = "my blog"
author_name = "my name"
author_email = "noreply@blogger.com"
blog_id = "222222222222222"
require 'rubygems'
require 'oauth'
require 'oauth/client'
require 'oauth/token'
require 'oauth/consumer'
require 'activeresource'
require 'pp'
module OAuth
module Rails
#!/usr/bin/env ruby
# Simple lighthouse export
require 'lib/lighthouse'
include Lighthouse
Lighthouse.account = "sml"
#### You can use `authenticate` OR `token`
# TB usage at which pricing changes
s3_tiers = %w{50 100 500 1000 5000 1000000000}.collect {|x| x.to_f}
# Cost per GB/month for each of the above tiers
s3 = %w{0.15 0.14 0.13 0.105 0.08 0.055}.collect {|x| x.to_f}
s3_reduced = %w{0.1 0.093 0.087 0.07 0.053 0.037}.collect {|x| x.to_f}
# ebs is always 0.10/GB per month
ebs = %w{0.1 0.1 0.1 0.1 0.1 0.1}.collect {|x| x.to_f}
#!/bin/sh
# Sets up auto-tracking of a remote branch with same base name.
# Can set up "git track" so it feels built-in:
# git config --global --add alias.track '!git-track'
#
branch=$(git branch 2>/dev/null | grep ^\*)
[ x$1 != x ] && tracking=$1 || tracking=${branch/* /}
git config branch.$tracking.remote origin
# origin of work
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://posterous.timocracy.com/the-trouble-with-bash-colored-prompts-munging
function parse_git_dirty {
status=`git status 2> /dev/null`
bits=''
if [[ "${status}" =~ "Changed but not updated" ]]; then
bits="${bits}*"
fi
@wr0ngway
wr0ngway / gist-bundler.rb
Created February 8, 2012 15:53
Using gist to achieve self contained bundled gems within a single ruby script
require 'tmpdir'
require 'fileutils'
# scope bundling for this script to a directory based on its path
tmpdir = "#{Dir.tmpdir}/script_bundler/#{File.expand_path(__FILE__).gsub(/\W+/, '_')}"
FileUtils.mkdir_p(tmpdir)
gemfile = "#{tmpdir}/Gemfile"
gemfile_lock = "#{gemfile}.lock"
@wr0ngway
wr0ngway / gist-util.rb
Created February 8, 2012 16:11
Utility script to archive and cleanup old gists
#!/usr/bin/env ruby
# Add your gems here
#
gemfile_contents = <<-EOF
source "http://rubygems.org"
gem 'clamp'
gem 'iniparse'
gem 'rest-client'
gem 'json'
@wr0ngway
wr0ngway / backup_sdb.rb
Created March 20, 2012 20:25
script to backup all simpledb tables from a given aws account
#!/usr/bin/env ruby
# Add your gems here
#
gemfile_contents = <<-EOF
source "http://rubygems.org"
gem "fog"
gem "yajl-ruby"
EOF
@wr0ngway
wr0ngway / gc-cow.rb
Created March 23, 2012 17:46
test to see if GC in ruby 2 is truly copy on write friendly
#!/usr/bin/env ruby
rss = '.+?Rss:\s+(\d+)'
share = '.+?Shared_Clean:\s+(\d+)'
share << '.+?Shared_Dirty:\s+(\d+)'
priv = '.+?Private_Clean:\s+(\d+)'
priv << '.+?Private_Dirty:\s+(\d+)'
MEM_REGEXP = /\[heap\]#{rss}#{share}#{priv}/m
def mem_usage_linux