This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* a smart poller for jquery. | |
* (by github) | |
* | |
* simple example: | |
* | |
* $.smartPoller(function(retry) { | |
* $.getJSON(url, function(data) { | |
* if (data) { | |
* doSomething(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load config/paperclip.yml settings | |
if paperclip_cfg = YAML.load_file("#{Rails.root}/config/paperclip.yml")[Rails.env] | |
paperclip_cfg.symbolize_keys! | |
command_path = paperclip_cfg.delete(:command_path) | |
# Replace Attachment defaults with configuration ones | |
Paperclip::Attachment.default_options.merge!(paperclip_cfg) | |
# Adjust ImageMagick path to work with Passenger | |
Paperclip.options[:command_path] = command_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Overload Clearance's `deny_access` methods to allow authentication with HTTP-Auth for eg. API access | |
# Modeled after technoweenie's restful_authentication | |
# http://github.com/technoweenie/restful-authentication/blob/7235d9150e8beb80a819923a4c871ef4069c6759/generators/authenticated/templates/authenticated_system.rb#L74-76 | |
# | |
# In lib/clearance_http_auth.rb | |
module Clearance | |
module Authentication | |
module InstanceMethods | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Factory.define :application do |factory| | |
factory.attachment(:sample, "public/samples/sample.doc", "application/msword") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replaced this | |
$(document).ready(function() { | |
if ($.fn.corner) $('.corner').corner() | |
}) | |
// with this | |
.corner { | |
-moz-border-radius: 8px; | |
-webkit-border-radius: 8px; | |
padding: 3px; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scopes[:your_composite_scope_name] = proc{ Scope.new(your.combined.scopes.here, {}) } | |
def self.your_composite_scope_name(*args) | |
scopes[:your_composite_scope_name].call(self, *args) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :harmony do | |
desc "Munges the data" | |
task :munge => :environment do | |
docs_with_publish = Item.collection.find({'publish' => {'$exists' => true}}).to_a | |
puts "Item count: #{Item.count}" | |
puts "Items with publish key: #{docs_with_publish.size}" | |
docs_with_publish.each do |hash| | |
hash.delete('publish') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'redis' | |
require 'json' | |
require 'eventmachine' | |
class RedisLoop | |
class << self | |
attr_accessor :queues | |
def start(opts={}, &blk) | |
EM.run { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'socket' | |
host = ARGV[0] || 'localhost' | |
port = ARGV[1] || '6379' | |
trap(:INT) { | |
exit | |
} |