Skip to content

Instantly share code, notes, and snippets.

@softwaregravy
softwaregravy / global_request_logging
Created March 7, 2011 15:45
the code I use to log all requests and responses (watch out not to log html)
# inside Application controller
around_filter :global_request_logging
def global_request_logging
http_request_header_keys = request.headers.keys.select{|header_name| header_name.match("^HTTP.*")}
http_request_headers = request.headers.select{|header_name, header_value| http_request_header_keys.index(header_name)}
logger.info "Received #{request.method.inspect} to #{request.url.inspect} from #{request.remote_ip.inspect}. Processing with headers #{http_request_headers.inspect} and params #{params.inspect}"
begin
yield
@softwaregravy
softwaregravy / validate_phone_number.rb
Created March 1, 2011 13:56
Accepting any 10 digit number in a string as a phone number
class XXX < ActiveRecord::Base
before_validation :format_phone
validates_presence_of :phone
validates_length_of :phone, :is => 10
attr_accessible :phone
@softwaregravy
softwaregravy / api.feature
Created February 26, 2011 20:27 — forked from guenter/api.feature
I prefer symbols to strings when accessing hash. So make the looks with_indifferent_access
Feature: API
In order to use the service from third party apps
As a user
I want to be able to use an API
Background:
Given a user exists # Pickle
And I login as the user using basic auth
Scenario Outline: Get a ticket
@softwaregravy
softwaregravy / myads_sample.rb
Created January 26, 2011 20:40
Getting an image into Base64
We couldn’t find that file to show.