This file contains hidden or 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 out the values of all instance variables in object 'o': | |
o.instance_variables.inject({}) {|memo,v| | |
memo.merge!(v=>s.instance_eval(v)) | |
} |
This file contains hidden or 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 | |
# An improved GitHub gemspec checker. | |
# GitHub accepts YAML dumps for the gemspecs, which helps keep your gem generation tasks DRY | |
if ARGV.size < 1 | |
puts "Usage: github-test.rb my-project.gemspec" | |
exit | |
end | |
This file contains hidden or 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
membership_of_favourite_club: | |
joined_on: <%= 3.weeks.ago.to_s(:db) %> | |
club: moustache_club | |
member: groucho | |
favourite: true | |
type: Membership |
This file contains hidden or 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
# For the queasy, this is MIT licensed. See comment at the end. | |
module ExceptionMacros | |
# Make sure a block raises an exception. | |
# Call with optional arguments :instance_of/:kind_of and :message | |
# If :instance_of or :kind_of is specified, assert on the given type. | |
# Otherwise only assert that an exception is raised. | |
# Note: The shorthand should_raise(LoadError) is equivalent to should_raise(:instance_of => LoadError) | |
# If :message is specified, will assert that exception.message =~ :message. | |
# |
This file contains hidden or 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 | |
# Filename: mdc | |
# You put it in your path, then install Maruku, the awesome markdown gem. | |
# Maruku has awesome warning and isn't buggy. | |
# Usage: | |
# mdc article.md | |
# #=> article.html | |
# |
This file contains hidden or 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
#console | |
sudo gem install ruby_parser | |
#irb | |
require 'rubygems' ; require 'ruby_parser' ; require 'pp' | |
pp RubyParser.new.parse "class C | |
def meth(arg) | |
arg * 2 | |
end |
This file contains hidden or 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
# IRB prompt that looks like code samples | |
IRB.conf[:USE_READLINE] = true | |
IRB.conf[:AUTO_INDENT] = false | |
my_conf = IRB.conf[:PROMPT][:COPY] = {} | |
my_conf[:PROMPT_N] = "" | |
my_conf[:PROMPT_S] = "" | |
my_conf[:PROMPT_I] = "" | |
my_conf[:PROMPT_C] = "" | |
my_conf[:RETURN] = "#=> %s\n\n" |
This file contains hidden or 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
# Rubygems 1.3.1 incompatible with rbx. Missing constant EACCESS | |
# Either with the dev's bin/ in the path or rbx symlinked in the path, | |
# I get the following error: | |
$ rbx gem install rack --no-rdoc --no-ri | |
ERROR: While executing gem ... (NameError) | |
Missing or uninitialized constant: EACCESS | |
# Note: Yeah, I should SUDO |
This file contains hidden or 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
class String | |
# Return everything after the given string | |
# or nil if the substring can't be found | |
def after(prefix) | |
match = self.match Regexp.new(Regexp.escape(prefix) + "(.*)") | |
match && match[1] | |
end | |
end | |
dir = "/Users/mat/Desktop/wordpress-1" |
This file contains hidden or 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
# Our deployment tags are s or p followed by YYmmdd-HHMMSS | |
namespace :deploy do | |
namespace :pending do | |
desc "Show the list of new migrations since the last deployments to staging and production" | |
task :migrations do | |
tags = run_locally("git tag").split | |
staging = tags.grep(/\As\d{6}-\d{6}\Z/).sort.last | |
production = tags.grep(/\Ap\d{6}-\d{6}\Z/).sort.last | |
%w(staging production).each do |stage| | |
puts '', stage |
OlderNewer