Skip to content

Instantly share code, notes, and snippets.

tmp
log
doc
daemon
*.swp
module VerboseJob
module ClassMethods
def wrap_perform!
class << self
def perform_with_verbose(*args)
JobLogger.verbose { perform_without_verbose(*args) }
end
alias_method_chain :perform, :verbose \
unless instance_method(:perform) == instance_method(:perform_with_verbose)
@craigmcnamara
craigmcnamara / respond_to.rb
Created November 10, 2012 05:42
Respond To
def respond_with(*resources, &block)
raise "In order to use respond_with, first you need to declare the formats your " <<
"controller responds to in the class level" if self.class.mimes_for_respond_to.empty?
if collector = retrieve_collector_from_mimes(&block)
options = resources.size == 1 ? {} : resources.extract_options!
options[:default_response] = collector.response
(options.delete(:responder) || self.class.responder).call(self, resources, options)
end
end
class SpecialResponderController < ActionController::Base
protected
def self.responder
lambda do |controller, resources, options|
if controller.is_special?
SpecialResponder.call(controller, resources, options)
else
super.call(controller, resources, options)
end
end
@craigmcnamara
craigmcnamara / inline_css_helper.rb
Created August 3, 2011 07:05
Css inliner using Nokogiri and css_parser
require 'nokogiri'
require 'css_parser'
module InlineCSSHelper
include CssParser
# Takes a string of HTML and inlines any css blocks in it.
def inline_css(message)
css_parser = CssParser::Parser.new
doc = Nokogiri::HTML(message)
require 'yaml'
YAML::ENGINE.yamler= 'syck'
@craigmcnamara
craigmcnamara / gist:1051796
Created June 28, 2011 18:19
Testing a signed faecbook request
module FacebookSession
def parse_signed_request(secret_id,request)
encoded_sig, payload = request.split('.', 2)
sig = ""
urldecode64(encoded_sig).each_byte { |b|
sig << "%02x" % b
}
data = JSON.parse(urldecode64(payload))
if data['algorithm'].to_s.upcase != 'HMAC-SHA256'
raise "Bad signature algorithm: %s" % data['algorithm']
@craigmcnamara
craigmcnamara / gist:1051579
Created June 28, 2011 16:53
FB request params
def do_fbjs_create
post :create, :contact => @fb_contact, :fb_sig_is_ajax => 1, :page_slug => @landing_page.slug
end
def do_fbml_create
post :create, :contact => @fb_contact, :fb_sig => 43243243214321, :page_slug => @landing_page.slug
end
@craigmcnamara
craigmcnamara / nginx.conf
Created June 17, 2011 19:13 — forked from cmrosado/nginx.conf
the passenger file
user _www;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@craigmcnamara
craigmcnamara / Example Pagelander Template
Created April 7, 2011 19:42
This is a Liquid template with access to a Page object and fb_page and fb_user information
<div id="fb-root">
<div style="background-color:#FFFFFF; margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;min-height:750px;">
<link rel="stylesheet" type="text/css" href="{{page.host_path}}/screen.css" />
<div id="cny-home-expo-01">
<img src="{{page.host_path}}/cny-home-expo_01.gif" width="520" height="109" alt="">
</div>
<div id="cny-home-expo-02">
<img src="{{page.host_path}}/cny-home-expo_02.gif" width="253" height="362" alt="">
</div>
<div id="cny-home-expo-03">