Skip to content

Instantly share code, notes, and snippets.

View gravis's full-sized avatar

Philippe Lafoucrière gravis

View GitHub Profile
@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
@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 / 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 / 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:
# 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
#! /usr/bin/env ruby
# Typhoeus::Multi bug demo
require 'rubygems'
require 'typhoeus'
e = Typhoeus::Easy.new
e.url= "https://www.google.com"
e.method = :post
e.headers = {:TEST => "TEST"}
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:include schemaLocation="./include/CJCommon.xsd" />
<xs:element name="OUVINFOPERSO">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="1">
<!-- Entete -->
<xs:element minOccurs="1" maxOccurs="1" ref="IDOper" />
<xs:element minOccurs="1" maxOccurs="1" ref="DateEvt" />
<xs:element minOccurs="1" maxOccurs="1" ref="IDEvt" />
#! /usr/bin/rackup
#\ -w -p 8765
map '/' do
run Proc.new {|env|
req = Rack::Request.new(env)
if req.params['PARAM1'] and req.params['PARAM2'] and req.params['PARAM3'] and req.params['PARAM4'] and req.params['PARAM5'] and env['HTTP_HEADER1'] and env['HTTP_HEADER2']
[200, {"Content-Type" => "text/html"}, ["Data Sent"]]
else
puts req.params
# in config/environment.rb:
config.action_controller.session = {
:key => '_myapp_session',
:secret => 'super_very_long_key_more_than_30_chars'
}
# in config/environment.rb :
config.action_controller.session = {
:key => '_myapp_session',
:secret => 'super_very_long_key_more_than_30_chars',
#:secure => true, # Only enable secure here if your dev env is using ssl, which is certainly not the case
:expire_after => 3600 # 1 hour
}