Skip to content

Instantly share code, notes, and snippets.

View jqr's full-sized avatar

Elijah Miller jqr

View GitHub Profile
# Preloads models in a subdirectory of RAILS_ROOT/app/models so STI can find
# them properly.
Dir.glob(File.join(RAILS_ROOT, 'app', 'models', '**/*.rb')) do |file|
require file
end
before "deploy:symlink", "deploy:check_app_dependencies"
namespace :deploy do
desc "Checks for required dependencies by starting the application"
task :check_app_dependencies, :roles => :app do
app_env = fetch(:rails_env, "production")
run "cd #{release_path}; RAILS_ENV=#{app_env} ./script/runner ''"
# TODO: anything required for rollback?
end
end
Benchmark = function(description, timed_function) {
var start = new Date()
timed_function();
console.debug(description + ': ' + (new Date() - start) + 'ms');
}
# An array of String subclasses does not sort using <=> on the subclass, WTF?
class StringSubclass < String
def <=>(other)
puts "using <=> in #{self.class}: #{caller.first}"
super
end
end
StringSubclass.new <=> StringSubclass.new
def render_optional_error_file(status)
begin
code = ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE[status]
render :template => "/statics/#{code}"
rescue
super
end
end
# Given I have the following projects:
# | short_description |
# | Feed Dante |
# | Walk my dogs |
Given /^I have the following projects:$/ do |table|
table.hashes.each do |project_hash|
@current_user.projects.create!(project_hash)
end
end
irb(main):001:0> thing
NameError: undefined local variable or method `thing' for main:Object
from (irb):1
irb(main):002:0> defined? thing
=> nil
irb(main):003:0> thing = thing
=> nil
irb(main):004:0> thing
=> nil
irb(main):005:0> defined? thing
@jqr
jqr / heroku.rake
Created April 24, 2009 13:24
Automatically Generate the Heroku gems manifest from gem dependencies
namespace :heroku do
desc "Generate the Heroku gems manifest from gem dependencies"
task :gems do
RAILS_ENV='production'
Rake::Task[:environment].invoke
list = Rails.configuration.gems.collect do |g|
command, *options = g.send(:install_command)
options.join(" ") + "\n"
end
<script type="text/python">
def pyFunc():
window.alert("hi, i'm python")
</script>
<script type="text/ruby">
def rubyFunc
pyFunc
end
</script>
<script>
class A
def initialize
puts "A initialized"
end
end
class B < A
alias :original_initialize :initialize
def initialize