Instantly share code, notes, and snippets.

View Dockerfile
FROM alpine
ENV MYENV="THIS IS AN ENV VARIABLE"
ARG MYARG="THIS IS A BUILD ARGUMENT"
RUN echo "BUILD MYENV: '$MYENV' MYARG: '$MYARG'"
CMD echo "RUN MYENV: '$MYENV' MYARG: '$MYARG'"
View service-checklist.md

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
View gist:5216957
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "opscode-centos63"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
View iam.md

Installation and Setup

Install the AWS IAM tools:

Homebrew:

brew install aws-iam-tools
View fix_shitty_csv.rb
#!/usr/bin/env ruby
require 'pp'
require 'csv'
require 'logger'
def join_and_quote ( a )
a.to_csv(:row_sep => "\r\n", :quote_char => '"')
end
View gist:4001420

Some tips on debugging ERB Templates

Convert the template to a ruby file

$ erb -x -T - file.erb > file.rb

Open the file. At the bottom, you'll see:

; _erbout
View gist:3707263

HTTP/1.0 request

$ curl  -sv0IH 'Accept-Encoding: gzip' -H 'Host: www.ideeli.com' http://www.ideeli.com/welcome?MuttAndJeff=1
* About to connect() to www.ideeli.com port 80 (#0)
*   Trying 208.39.105.3...
* connected
* Connected to www.ideeli.com (208.39.105.3) port 80 (#0)
> HEAD /welcome?MuttAndJeff=1 HTTP/1.0
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
> Accept: */*
View hashsub.rb
#!/usr/bin/env ruby
require 'pp'
class Hash
def subtract (h)
result = {}
self.each do |k,v|
result[k] = (self[k] - h[k]) if h[k]
end
result
View count_queries.rb
#!/usr/bin/env ruby
require 'pp'
h = { :select => 0, :insert => 0, :delete => 0, :update => 0}
ARGF.each do |line|
case line
when /SELECT.*FROM/i then
h[:select] += 1
when /INSERT.*INTO/i then
View gist:2966320
def get_volumes (mount = nil)
return [] unless @ec2_instance_id
mount ||= @datadir
vols = []
devs = get_devs(mount)
instance = @ec2.instances[@ec2_instance_id]
vols = instance.block_device_mappings.map { |dev,attach| attach.volume.id if devs.include?(dev) }.compact
return vols
end