Skip to content

Instantly share code, notes, and snippets.

@chrisk
chrisk / copy_pivotal_members.rb
Created February 1, 2010 09:40
Copy Pivotal Tracker members to all projects
#!/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.
@chrisk
chrisk / compact_progress_bar_formatter.rb
Last active September 4, 2015 06:04
CompactProgressBarFormatter for RSpec 1
# 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'
@chrisk
chrisk / remove_empty_vendor_directories.rb
Created January 4, 2010 16:46
Rails initializers that clean up git-submodule droppings
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
@chrisk
chrisk / campfire.rb
Created December 10, 2009 22:49
Stateful version of the Integrity notifier for Campfire
# 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
@chrisk
chrisk / post_tweets_to_campfire.rb
Created December 10, 2009 22:29
Post tweets to Campfire
#!/usr/bin/ruby
require 'rubygems'
require 'twitter'
require 'httparty'
require 'json'
require 'action_view'
include ActionView::Helpers
@chrisk
chrisk / filtered-top.sh
Created December 10, 2009 22:23
Monitor the processes from a set of pid files in top
# 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/,$//)
@chrisk
chrisk / duration_helper.rb
Created November 5, 2009 07:00
DurationHelper#format_duration
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'] ] :
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 ||= []
# You can use newlines as delimiters for the various
# %-style string quoting syntaxes (like %{}, %Q{}, etc.)
>> %
%s
>> % %
bacon
>>
=> "bacon"
@chrisk
chrisk / hide_labels_in_pivotal_tracker_story_lists.user.js
Created March 2, 2009 23:48
Greasemonkey script to hide the labels in Pivotal Tracker's story lists
// ==UserScript==
// @name Hide labels in Pivotal Tracker story lists
// @namespace http://shiftcommathree.com
// @description Hides the small green labels before each story title
// @include http://www.pivotaltracker.com/projects/*
// @include http://pivotaltracker.com/projects/*
// @author Chris Kampmeier
// ==/UserScript==
function addGlobalStyle(css) {