Skip to content

Instantly share code, notes, and snippets.

require 'net/http'
class FeedDetector
# return the feed url for a url
# for example: http://blog.dominiek.com/ => http://blog.dominiek.com/feed/atom.xml
# only_detect can force detection of :rss or :atom
def self.fetch_feed_url(page_url, only_detect=:any)
url = URI.parse(page_url)
host_with_port = url.host
host_with_port << ":#{url.port}" unless url.port == 80
namespace :datarm do
desc "Run Trip Wires"
task :run_trip_wires => :environment do |rake_task|
proceed(rake_task) do
TripWireEngine.proceed_all_active
end
end
desc 'Empty action for report. Requirements: REPORT_ID'
task :empty_report => :environment do |rake_task|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title><%= yield :title || "Philtro" %></title>
<%= yield :head -%>
</head>
<body>
describe FooController do
describe "route generation" do
it "should map { :controller => 'foo', :action => 'index' } to /foo" do
route_for(:controller => "foo", :action => "index").should == "/foo"
end
end
describe "route recognition" do
it "should generate params { :controller => 'foo', action => 'index' } from GET /foo" do
params_from(:get, "/foo").should == {:controller => "foo", :action => "index"}
@olkeene
olkeene / noisy_protected_attribute_removal.rb
Created April 4, 2009 03:02
mass-assign errors display for dev env
if Rails.env.development?
ActiveRecord::Base.class_eval do
def log_protected_attribute_removal(*attributes)
raise "Can't mass-assign these protected attributes: #{attributes.join(', ')}"
end
end
end
@olkeene
olkeene / ajax_rescues.rb
Created April 4, 2009 03:05
ajax_rescues
class ActionController::Base
private
def rescue_action_in_public(exception)
respond_to do |want|
want.html {
super(exception)
}
want.js {
render :update do |page|
class ActionController::Base
private
def rescue_action_in_public(exception)
respond_to do |want|
want.html {
super(exception)
}
want.js {
render :update do |page|
module ActiveRecord
class Errors
# Redefine the ActiveRecord::Errors::full_messages method:
# E.g. validates_acceptance_of :accepted_terms, :message => 'Please accept the terms of service'
def full_messages
full_messages = []
@errors.each_key do |attr|
@errors[attr].each do |msg|
class Array
# does a kind of ZIP compression for integer arrays
# examples:
# [0,1,2,3].compress! => [[0, 4]]
# [1,2,3,8,9,10,11].compress! => [[1, 3], [8, 4]]
# [1,3,5].compress! => [1, 3, 5]
# [1,3,5,6].compress! => [1, 3, [5, 2]]
def compress!
compact!
return [] if empty?
@olkeene
olkeene / AppTasks.rake
Created May 4, 2009 17:47
Continuous Testing and Testing Single Methods in Ruby on Rails
# rake app:test:file file=sample_test,other_test,third_test,etc_test
# rake app:test:file file=sample name=method_to_test
# rake app:test:monitor
namespace :app do
namespace :test do
# accepts ARGV[1] as parameter for test file patterns. Format:
# ARGV[1] = "file=[pattern]" (pattern can be a comma list of multiple files)
# ARGV[2] = "name=[method]" name of method to run in test file
desc "Run a single test without preparing database first. Smart about finding the test file.\n Syntax: rake app:test file=[basename] where basename matches (globbed) test(s).\n Will accept multiple comma delimted file patterns. "