Skip to content

Instantly share code, notes, and snippets.

View webmat's full-sized avatar

Mathieu Martin webmat

View GitHub Profile
@webmat
webmat / gist:15920
Created October 9, 2008 22:15
Check out the values of all instance variables in object 'o'
# Check out the values of all instance variables in object 'o':
o.instance_variables.inject({}) {|memo,v|
memo.merge!(v=>s.instance_eval(v))
}
#!/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
membership_of_favourite_club:
joined_on: <%= 3.weeks.ago.to_s(:db) %>
club: moustache_club
member: groucho
favourite: true
type: Membership
# 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.
#
#!/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
#
#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
# 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"
# 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
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"
# 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