Skip to content

Instantly share code, notes, and snippets.

View mattpolito's full-sized avatar

Matt Polito mattpolito

View GitHub Profile
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.'
task :routes => :environment do
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes
routes = all_routes.collect do |route|
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
verb = route.conditions[:method].to_s.upcase
segs = route.segments.inject("") { |str,s| str << s.to_s }
segs.chop! if segs.length > 1
reqs = route.requirements.empty? ? "" : route.requirements.inspect
{:name => name, :verb => verb, :segs => segs, :reqs => reqs}
# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
// only outputs if console available and does each argument on its own line
function log() {
if (window && window.console && window.console.log) {
var i, len;
for (i=0, len=arguments.length; i<len; i++) {
console.log(arguments[i]);
}
}
}
#!/usr/bin/env ruby
puts "looking for the gems to upgrade..."
gem_info = Struct.new(:name, :version)
to_reinstall = []
Dir.glob('/Library/Ruby/Gems/**/*.bundle').map do |path|
path =~ /.*1.8\/gems\/(.*)-(.*?)\/.*/
name, version = $1, $2
bundle_info = `file path`
to_reinstall << gem_info.new(name, version) unless bundle_info =~ /bundle x86_64/
end
# Delete unnecessary files
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/images/rails.png"
run "rm public/javascripts/prototype.js"
run "rm public/javascripts/effects.js"
run "rm public/javascripts/dragdrop.js"
run "rm public/javascripts/controls.js"
# Copy database.yml for distribution use
class Comment
include MongoMapper::EmbeddedDocument
include Gravatarable
key :name, String
key :email, String
key :url, String
key :body, String
key :created_at, Time
<html>
<head>
<title>reactionCONTROL - Course Correction in Progress</title>
</head>
<body id=”maintenance”>
<div id=”content”>
<p>Sir, a coordinate correction is currently underway.</p>
<p>We’re sorry but you’ll have to get back to your seat. Rest assured
we’ll be back on course shortly.</p>
</div>
@mattpolito
mattpolito / gist:740582
Created December 14, 2010 15:35
Invalid query that changed after upgrade to Rails 3.0.3 from 3.0.1 These seems to be a rouge set of single quotes around the second INNER JOIN
-- Rails 3.0.3 - No workie *Sad Face*
SELECT "presentations".* FROM "presentations" INNER JOIN "taggings" ON "presentations"."id" = "taggings"."taggable_id" AND "taggings"."taggable_type" = 'Presentation' INNER JOIN "tags" ON 'taggings.tag_id = tags.id AND taggings.context = ''tags''' ORDER BY created_at DESC
-- Rails 3.0.1 - Works fine *Hooray*
SELECT "presentations".* FROM "presentations" INNER JOIN "taggings" ON "presentations"."id" = "taggings"."taggable_id" AND "taggings"."taggable_type" = 'Presentation' INNER JOIN "tags" ON taggings.tag_id = tags.id AND taggings.context = 'tags' ORDER BY created_at DESC
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."