Skip to content

Instantly share code, notes, and snippets.

View gravis's full-sized avatar

Philippe Lafoucrière gravis

View GitHub Profile
# Some helpers for Rack-Test (http://github.com/brynary/rack-test)
# To use the helper, include RackTestHelper in your test class, then you can access
# session[:session_id] or whatever.
# Warning : this won't work if you're using more than one cookie, since I'm fetching the first available !
module RackTestHelper
#Returns the current session as a HASH
def session
Marshal.load(Base64.decode64(CGI.unescape(rack_mock_session.cookie_jar.to_hash.values.first))).with_indifferent_access
end
@gravis
gravis / god_resque.rb
Created March 15, 2010 20:37
God monitoring files for resque
# Copyright (c) 2010 Tech-Angels
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
@gravis
gravis / local-suhosin
Created February 10, 2010 21:28
logcheck rule to avoid php/sohosin annoying alerts
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ suhosin\[[0-9]+\]: ALERT - canary mismatch on efree() - heap overflow detected (attacker '[0-9a-f.:]{3,39}', file '/var/www/openx/www/delivery/[[:alpha:]]+\.php')$
@gravis
gravis / test_helper.rb
Created February 10, 2010 15:58
Don't enqueue Jobs in test, redis will fail fetching non-existing objects
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'authlogic/test_case'
class ActiveSupport::TestCase
[...]
end
module Resque
@gravis
gravis / resque_schedule_retry_job.rb
Created February 9, 2010 20:24
A resque job with retry on failure, dead simple. Needs resque-schedule plugin. the only caveat is that the first attempt is in the "events" queue, whereas retries are only visible in Delayed tab.
class GetEventResult
@queue = :events
def self.perform(event_id, attempt=0)
event = Event.find(event_id)
Rails.logger.info "Fetching results for event ##{event.id} (#{event.name})..."
begin
results = EventImporter.new(event.datetime.to_date).get_results(event)
rescue OpenURI::HTTPError
$ sudo gem list hanna
*** LOCAL GEMS ***
hanna (0.1.9)
$ sudo gem install justinfrench-formtastic
Successfully installed justinfrench-formtastic-0.2.4
1 gem installed
Installing ri documentation for justinfrench-formtastic-0.2.4...
$ cat .gemrc
---
:verbose: true
:benchmark: false
:sources:
- http://gems.rubyforge.org/
- http://gems.github.com
:update_sources: true
:backtrace: false
:bulk_threshold: 1000
# Open in the default browser the page being "seen" by webrat, when a cucumber feature fails:
# Credits go to Ben Mabey (cf http://groups.google.com/group/cukes/browse_thread/thread/c5c3c73e469382d6)
After do |scenario|
if scenario.failed? && scenario.exception.is_a?(Webrat::NotFoundError)
save_and_open_page
end
end
# Render a timestamp suitable for javascript substitution (jquery.timeago)
# Sorry for copyright, I can't remember where I found this piece of code ! Do not hesitate to claim it
def timeago(time, options = {})
options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.getutc.iso8601)) if time
end
# don't forget to add this to substitute times (HAML) :
# :javascript
# Fix the issue with domain cookie sessions in rails 2.3.
# Put this in your environment file (config/environment/staging.rb for me)
Rails.configuration.action_controller.session[:domain] = '.mydomain.net'
# instead of :
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:domain => ".mydomain.net")
# or
ActionController::Base.session_options[:domain] = ".mydomain.net"