Skip to content

Instantly share code, notes, and snippets.

View fairchild's full-sized avatar

Michael Fairchild fairchild

  • Procore
  • California
View GitHub Profile
@fairchild
fairchild / cloud.rb
Created February 23, 2009 19:34
poolparty spec for poolparty website
# Basic poolparty template
require "poolparty_apache2_plugin"
pool :opensource do
instances 1..1
port 80
ami "ami-1cd73375" #Alestic's old base Ubuntu AMI
#ami "ami-7cfd1a15" #Alestic's Ubuntu 8.10 Intrepid base AMI
base_keypair_path ENV["EC2_CONFIG_DIR"]
keypair "poolparty_oncourse_atti"
# incomplete skeleton distributed hash table making use of DistributedKeyBasedRouter class
class DHT
BASE_DIR='./'
def self.put(value, key=sha1(value) )
msg = {:action=>'store', :value=>value}.to_yaml
DistributeKeyBasedRouter.new.route(key, msg )
end
def self.get(key)
@fairchild
fairchild / dht_api_sample.rb
Created February 27, 2009 21:16
proposed API for ditributed has table
# sample skeleton for a ruby API based on the ideas from http://www.oceanstore.org/publications/papers/pdf/iptps03-api.pdf
class DistributeKeyBasedRouter
def initialize(deliver_to_class, deliver_class_method = :delivered)
@delivery_callback_class = deliver_to_class
@delivery_callback_method = deliver_class_method
end
@fairchild
fairchild / object_graphvizer.rb
Created March 2, 2009 01:06
output a graphviz dot file to visualize objet space heirarchy
class String
def to_underscored
self.gsub(/::/, '_') #:: has special meaning in graphviz, so we replace it
end
def evaled
eval self
end
end
class ObjectGrapher
@fairchild
fairchild / dns_pinger.rb
Created March 6, 2009 18:23
DNS ping timer
#simple script to check the ping times of various DNS servers
results = Hash.new
dns_servers = %w(4.2.2.1
4.2.2.2
4.2.2.3
4.2.2.4
4.2.2.5
4.2.2.6
68.94.156.1
# Basic poolparty template
pool :clouds do
base_keypair_path ENV["EC2_CONFIG_DIR"]
keypair "poolparty_oncourse_atti"
instances 1..2
port 80
# Alestic's base ubuntu AMI
ami "ami-1cd73375"
class Box
def options(h={})
@options ||= self.class.options.merge(h)
end
def self.options(h={})
@class_options ||= h
end
@defaults={
:access_key => Base.access_key,
:secret_access_key => Base.secret_access_key
}
define_defaults(@defaults)
def self.defaults
@defaults
end
try it using instance variables
def define_defaults(ops={})
ops.each do |k, v|
next if k.to_s == 'options'
class_defaults[k.to_sym] = v
instance_variable_set "@#{k}", v
methods_to_define = {
:class_getter => "class << self; def #{k}; class_defaults[:#{k}]; end; end",
# :instance_get_and_set => "def #{k}(i=nil); i ? @__#{k} = i : __options[:#{k}]; end",
:attr_accessor => "attr_accessor :#{k}",
#TODO: rdoc: this defines methods on poolparty objects from a passed hash of options.
# For example, this is how instance.minimum_runtime is set. See base.rb line 12 for example of default options that are added as methods in this way.
module PoolParty
module Configurable
module ClassMethods
# Provides a class options hash to hold the values that will be set by define_defaults
def class_defaults(h={})
@defaults ||= h
end