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
# Bash alias to open Github page for project in current working directory. | |
# Will use the current active branch if it exists remotely, or falls back to master. | |
alias github='br=$(git branch --contains HEAD | sed -En "s/^\* //p"); if ! git ls-remote . | grep -q -e "refs/remotes/.*/${br}"; then br="master"; fi; open $(git config -l | sed -En "s%remote.origin.url=git(@|://)(github.com)(:|/)(.+/.+).git%https://\2/\4/tree/${br}%p")' |
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
# Lighter -- Campfire from the command line | |
# usage: ruby lighter.rb subdomain "Main Room" macournoyer@gmail | |
require "rubygems" | |
require "tinder" | |
require "readline" | |
require "highline/import" | |
class Lighter | |
def initialize(room) | |
@room = room |
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
# Neater Github gem dependencies for Rails | |
module GithubGem | |
def github_gem(gem_name, opts={}) | |
lib_name = gem_name.split('-', 2)[1] | |
self.gem gem_name, {:lib => lib_name, :source => 'http://gems.github.com'}.merge(opts) | |
end | |
end | |
Rails::Initializer.run do |config| |
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
usage = <<DESC | |
Use mysql to expire sessions without loading the Rails environment, so we | |
can call this task from cron without it being unnecessarily expensive. | |
Takes path to Rails app and desired RAILS_ENV as arguments. | |
DESC | |
namespace :db do | |
namespace :sessions do | |
desc usage |
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
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
env['REQUEST_METHOD'] = "POST" | |
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
namespace :db do | |
desc 'Open a MongoDB console with connection parameters for the current Rails.env' | |
task :console => :environment do | |
conn = Mongoid.master.connection | |
args = [] | |
args << "--username=#{conn.username}" if conn.username rescue nil | |
args << "--password=#{conn.password}" if conn.password rescue nil | |
args << "--host=#{conn.host}" | |
args << "--port=#{conn.port.to_s}" | |
args << Mongoid.master.name |
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
# .irbrc to log goodies like SQL/Mongo queries to $stdout if in Rails 3 console | |
if defined?(Rails) && Rails.respond_to?(:logger) | |
require 'logger' | |
Rails.logger = Logger.new($stdout) | |
if defined?(Mongoid) | |
Mongoid.logger = Rails.logger | |
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
# Basic tagging system for mongoid documents. | |
# jpemberthy 2010 | |
# | |
# class User | |
# include Mongoid::Document | |
# include Mongoid::Document::Taggable | |
# end | |
# | |
# @user = User.new(:name => "Bobby") | |
# @user.tag_list = "awesome, slick, hefty" |
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
# Nice idea from: | |
# http://kpumuk.info/ruby-on-rails/my-top-7-rspec-best-practices/ | |
# | |
# ~/test$ rake -T spec:suite | |
# | |
# (in /Users/kpumuk/test) | |
# rake spec:suite:acl # Run all specs in access control spec suite | |
# rake spec:suite:amazon # Run all specs in Amazon libraries spec suite | |
SPEC_SUITES = [ |
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
# TextMate added these variables to cope with changes in ERB handling | |
# in different versions of Rails -- for instance, Rails 3 automatically | |
# strips whitespace so that it's no longer necessary to use a form like | |
# <% end -%>, but if you're still maintaining Rails 2 projects, you | |
# can't omit the minus sign and get the same behavior. | |
# | |
# The following regex replace substitutes the function below for the | |
# TextMate variable references after the snippets are converted: | |
# | |
# /\v\$\{(TM_RAILS_TEMPLATE_([^_]+)_RUBY_([^_\s]+))\}/`!p textmate_var('\1', snip)`/g |
OlderNewer