This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ShouldaContextExtensions | |
def self.included(base) | |
base.class_eval do | |
alias_method_chain :build, :fast_context | |
alias_method_chain :am_subcontext?, :fast_context | |
end | |
end | |
def fast_context(name, &blk) | |
@fast_subcontexts ||= [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DurationHelper | |
# Takes a number of seconds as input and returns a formatted string. See | |
# tests for examples. | |
def format_duration(seconds, options = {}) | |
return "0 seconds" if seconds.floor == 0 | |
options.reverse_merge!(:parts_to_show => 4, :word_style => :short, :specific_end => false) | |
description = (options[:word_style] == :short) ? | |
[ ['sec', 60], ['min', 60], ['hr', 24], ['day'] ] : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monitor the processes from a set of pid files in top | |
# This doesn't work on OS X, because its top doesn't have -p. | |
top -p $(cat /var/run/*.pid | tr '\n', ',' | sed s/,$//) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'twitter' | |
require 'httparty' | |
require 'json' | |
require 'action_view' | |
include ActionView::Helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A stateful version of the Integrity notifier for Campfire. It only pings the room | |
# when the build is broken or when it's just been fixed. This is nice when you already | |
# have a post-receive hook posting every commit to the same room. | |
require 'rubygems' | |
require 'integrity' | |
require 'tinder' | |
require 'action_view' | |
module Integrity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module EmptyDirectoryHelper | |
def self.dir_contains_files?(dir) | |
entries = Dir.entries(dir).reject { |entry| entry == '.' || entry == '..' } | |
entries.any? { |entry| !File.directory?(File.join(dir, entry)) || dir_contains_files?(File.join(dir, entry)) } | |
end | |
def self.empty_vendor_dirs | |
Dir.glob(Rails.root.join("vendor/{gems,plugins}/*")).reject { |dir| dir_contains_files?(dir) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Originally by Nicholas A. Evans. See LICENSE.txt | |
# | |
# Note: includes modifications by Chris Kampmeier to use '=' for the progress | |
# bar mark and keep the cursor from hopping all around during the animation | |
# | |
# This version is compatible with RSpec 1.2.9 and ProgressBar 0.9.0 | |
require 'spec/runner/formatter/base_text_formatter' | |
require 'progressbar' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# This script uses Pivotal Tracker's API to generate a list of unique members | |
# from all of your projects; it then iterates over each project, adding any of | |
# those members who are missing. That way, everyone has access to everything. | |
# | |
# It only acts on projects belonging to accounts called ACCOUNT_NAME below. | |
# | |
# By default, the script doesn't proceed with the modifications, so you can | |
# double-check the pending changes. Run it again with --no-dry-run to proceed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check an email address domain's validity using MX records | |
require 'resolv' | |
def known_email_domain?(email) | |
domain = email.match(/\@(.+)/)[1] | |
Resolv::DNS.open { |dns| dns.getresources(domain, Resolv::DNS::Resource::IN::MX) }.any? | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/cucumber_fakeweb_hook.rb | |
# If this looks like a test server process, make its FakeWeb available to other | |
# processes via DRb. That way the test runner (which runs in a separate process) | |
# can dynamically register stubs for this server to use. | |
if Rails.env.cucumber? && defined?(PhusionPassenger) | |
require 'drb' | |
require 'fakeweb' | |
DRb.start_service("druby://localhost:30010", FakeWeb) |