Skip to content

Instantly share code, notes, and snippets.

View gbuesing's full-sized avatar

Geoff Buesing gbuesing

View GitHub Profile
@gbuesing
gbuesing / rack_honeypot.rb
Created April 29, 2009 19:42
Rack::Honeypot
# Returns a blank 200 OK response for any form posts that include a value for the honeypot field
module Rack
class Honeypot
def initialize(app, field_name)
@app = app
@field_name = field_name
end
ActionController::Base.class_eval do
protected
# BACKPORT OF CHANGE FROM 3.0 EDGE: http://github.com/rails/rails/commit/256b0ee8e3c1610967dfc89f864e24b98ed3c236
# Returns true or false if a request is verified. Checks:
#
# * is the format restricted? By default, only HTML requests are checked.
# * is it a GET request? Gets should be safe and idempotent
# * Does the form_authenticity_token match the given token value from the params?
def self.verified_request?
!protect_against_forgery? ||
@gbuesing
gbuesing / ugly couchrest hacks.rb
Created March 20, 2009 22:11 — forked from will/ugly couchrest hacks.rb
Hash hacks so that CouchRest::Document plays nice with Rails routes
# Hacks so that CouchRest::Document, which descends from Hash,
# doesn't appear to Rails routing as a Hash of options
class Hash
def self.===(other)
return false if other.is_a?(CouchRest::Document)
super
end
end