Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# Author => Jason Amster
# Email => jayamster@gmail.com
# Time.now => Thu Jul 16 17:33:50 -0400 2009
# Purpose => To get those friggin error codes off of Authorize.net and into somthing i can actually use
require 'rubygems'
require "activesupport"
require 'hpricot'
require 'open-uri'
def pph(hash, depth=0, output="")
if hash.is_a?(Hash)
carriage_return = depth > 0 ? "\n" : ""
output << carriage_return
hash.each do |key, val|
output << "\t" * depth + "#{key}\t=>\t#{pph(val, depth+1)}"
end
elsif hash.is_a?(Array)
return "["+hash.join(", ")+"]" +"\n"
else
User.find(:all, :conditions => "created_at BETWEEN '2004-01-01 12:00:00' AND 2005-01-01 12:00:00")
#!/bin/bash
echo "Setting up chef..."
sudo apt-get -y update
sudo apt-get -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert
cd /tmp
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
tar zxf rubygems-1.3.4.tgz
require "rubygems"
require "crack"
xml = <<-XML
<parent_node>
<content>
<item attr1="test">this is a string that ruins my life</item>
<item attr1="i am an attribute and i live nicely in the world of hashes" />
</content>
</parent_node>
XML
# Simple extension to string to cut out the middle and leave the beginning and end
class String
def middle_truncate(n, options={})
return self if self.length <= n
elipses = options.delete(:elipses) || 3
side = (n/2 - elipses/2)
left_side = (elipses % 2 == 0) ? side : side+1
left, right = self[0..left_side], self[(self.length-side+elipses)..self.length]
elipses_text = "." * elipses
return "#{left}#{elipses_text}#{right}"
# An extension to the Hash class to inspect what it is made of
class Hash
def whatami
keys.inject({}) do |hash, key|
hash[key] = case self[key].class.to_s
when "Hash"
self[key].whatami
when "Array"
self[key].map do |item|
# Removing libraries, and specifying plugins
config.frameworks -= [:action_controller, :action_view, :action_mailer, :active_resource]
config.plugins = [:acts_as_state_machine, :masochism, :resque]
# Taken and Modified from => \
# http://t-a-w.blogspot.com/2010/05/very-simple-parallelization-with-ruby.html
require "rubygems"
require "active_support"
require 'thread'
def Exception.ignoring_exceptions
begin
yield
1) Just getting the install process down....
a) bootstrapping a server is really confusing
- you need to install a bunch of libraries
- you need to install a bunch of gems
- you need to install chef-solo
- you need to tell chef-solo to turn into a chef-server
b) validation.pem
- so basically, you have to realize that this is a temporary key but you kind of have to manually install it on any new machine? No better way to do this?
2) Cookbooks, how do you manage them?
- I had difficulty in understanding that chef server is just a process (or group of them) and then you give it cookbooks to work with