Skip to content

Instantly share code, notes, and snippets.

require 'yaml'
def spit_context context, level=0
spaces = " " * level
puts "#{spaces}context '#{context[0]}' do"
puts "#{spaces} setup do\n#{spaces} end\n\n"
spit_specs(context[1], level)
puts "#{spaces}end\n\n"
end
// TODO
// show spinner on loading
//
// element.identify() is a prototype function -- remove it so
// there are less methods to overwrite when switching backend
// also: addClassName / RemoveClassName
//
// clean up the namespace -- instead of long function names in the window
// have descriptive names in their own class
//
require 'irb/completion'
require 'irb/ext/save-history'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:SAVE_HISTORY] = 100
if ENV['RAILS_ENV']
rr = IRB.conf[:LOAD_MODULES].detect{|x| x =~ /environment$/}.gsub(/config\/environment$/, '')
IRB.conf[:HISTORY_FILE] = File.join(rr, '.irb_history')
else
IRB.conf[:HISTORY_FILE] = File.join(ENV['HOME'], '.irb_history')
require 'yaml'
require 'rubygems'
gem 'twitter'
require 'twitter'
class AutoRetweet
def initialize search_phrase, config_file_name = 'config.yml'
@phrase = search_phrase
@config_file = config_file_name
# examples of using before_render
# http://github.com/xtoddx/before_render
class HiController < ApplicationController
before_render :hook_it_up
before_render :double_hooked, :if => lambda{|x| false}
before_render :cool_action, :only => [:index]
before_render :lousy_action, :except => [:index]
# just the page
#!/usr/bin/env ruby
print "MESSAGE> "
message = gets.gsub(/\s/, '').split(//)
print "PAD> "
pad = gets.gsub(/\s/, '').split(//)
message.zip(pad) do |mc, pc|
puts "#{mc} | #{pc} | #{'%2i' % (nm = mc[0] - ?a)} | #{'%2i' % (np = pc[0] - ?a)} | #{'%2i' % ((nm + np) % 26)} | #{(((nm + np) % 26) + ?a).chr}"
require 'test/unit'
#
# The goal for this exercise is to get the test to pass while not returning the
# expected value.
#
# CompTest may be renamed, as may CompEntry, so don't rely on names.
#
class CompEntry
def add addend_a, addend_b
@xtoddx
xtoddx / nova-screen.sh
Created February 9, 2011 17:48
Run nova components in a screen
#!/bin/bash
# This script runs all nova components in windows of a singe screen.
# Arguments: [nova.conf] [novarc]
function locate_binary {
# Called with the basename of a binary, like nova-api
# If we are in a nova checkout, use the bin/* version.
# Otherwise, get whatever is in ${PATH} for system wide nova
bin_name=${1}
@xtoddx
xtoddx / vagrant-nova-branch.rb
Created February 10, 2011 22:17
Branch a specific nova version in a vagrant box.
$HOME=File.expand_path(File.join(Dir.pwd, '..'))
Vagrant::Config.run do |config|
ip = "10.0.0.5"
aptdir = "#{$HOME}/aptcache/"
checkout = "#{$HOME}/openstack-cookbooks"
config.vm.box = "base"
config.vm.box_url = "http://images.ansolabs.com/vagrant/maverick64.box"
config.vm.network ip
config.vm.share_folder("v-apt", "/var/cache/apt", aptdir)
config.vm.provision :chef_solo do |chef|
@xtoddx
xtoddx / test_fog.rb
Created June 16, 2011 01:42
Using fog with Rackspace apis to control OpenStack.
#!/usr/bin/ruby
$: << 'fog/lib'
require 'fog'
# Get your api key / token `keystone-mange token list`
compute = Fog::Compute.new(:provider => 'Rackspace',
:rackspace_auth_token => '887665443383838',
:rackspace_management_url => 'http://127.0.0.1:8774/v1.0/',
:rackspace_username => 'joeuser',