Skip to content

Instantly share code, notes, and snippets.

View mitchellh's full-sized avatar
👻
Building.

Mitchell Hashimoto mitchellh

👻
Building.
View GitHub Profile
@mitchellh
mitchellh / gist:1556811
Created January 3, 2012 20:37
Vagrant 0.9 Forwarded Ports
# Forwarded port configurations were changed so that they no longer
# require a unique name:
# Before
config.vm.forward_port "http", 80, 8080
# After
config.vm.forward_port 80, 8080
# After (if you still want to name it you can, optionally)
@mitchellh
mitchellh / mri.txt
Created January 11, 2012 01:15
Ruby vs. Rubinius Startup on Mac OS X 10.7
Last login: Tue Jan 10 17:14:06 on ttys004
foo → ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
foo → time ruby test.rb
HELLO!
real 0m0.022s
user 0m0.017s
sys 0m0.005s
foo → time ruby test.rb
foo → ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
foo → time vagrant -h
Tasks:
vagrant box # Commands to manage system boxes
vagrant destroy # Destroy the environment, deleting the created virtual machines
vagrant halt # Halt the running VMs in the environment
vagrant help [TASK] # Describe available tasks or one specific task
vagrant init [box_name] [box_url] # Initializes the current folder for Vagrant usage
vagrant package # Package a Vagrant environment for distribution
b7b9867e7de60dbc0b8dd2151ec5bca82297d38c094a2e56c61a8d34bb859972
671ff0e7b1f416c3b04ab80e0a9d14d07b28fc598d29ac7926ef73672477780d
@mitchellh
mitchellh / gist:1792217
Created February 10, 2012 19:54
Prune old clients.
#!/usr/bin/env ruby
require 'set'
def knife_list(type)
Set.new(`knife #{type} list`.split("\n").map { |a| a.strip.chomp })
end
nodes = knife_list(:node)
clients = knife_list(:client)
vm.channel.execute("tail -f /some/growing/fail") do |type, data|
# type is one of [:stdout, :stderr, :exit_status]
# data is a string for stdout/stderr and an int for exit status
end

Y U NO PACKAGE veewee WITH VAGRANT INSTALLERS

  1. Packaging veewee with Vagrant gives the end-user the expectation that Vagrant will also support VeeWee, which isn't true (more on this in a sec).
  2. Packaging veewee with Vagrant requires I make sure it works with Vagrant at all times (or at least at that point I package). I'm not willing to do this. Again, more on this in a sec.
  3. Vagrant 1.1+ (that is: experimental builds heading towards 2.0) will merge in VeeWee functionality in an officially supported way. Finally, Vagrant will be able to build its own boxes from ISOs. I'm not sure the name will remain veewee but the functionality will be the same and I've talked to @patrickdebois about this already.
# Get the directory where this script is. This will also resolve
# any symlinks in the directory/script, so it will be the fully
# resolved path.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
# Useful variables
EMBEDDED_DIR=${DIR}/../embedded
# A method for configuration based on partial convergence in Chef.
#
# Assuming you have knowledge that Chef is two-phased (compilation then convergence),
# then this solves the problem where you need to pass data into a resource where the
# data comes from a place that requires some convergence to have occurred. Most often
# this happens for me in templates.
#
# Below is a general pattern I use when this is necessary (it is rare). Basically, I
# use an OpenStruct to assign some data to it via `ruby_block` (which is processed at
# convergence), and then I use that data in the resource that depends on it. Then in the