Skip to content

Instantly share code, notes, and snippets.

View stve's full-sized avatar

Steve Agalloco stve

View GitHub Profile
/*
* a smart poller for jquery.
* (by github)
*
* simple example:
*
* $.smartPoller(function(retry) {
* $.getJSON(url, function(data) {
* if (data) {
* doSomething(data)
# 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
# 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
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
@stve
stve / gist:175739
Created August 26, 2009 19:19 — forked from defunkt/gist:175678
// replaced this
$(document).ready(function() {
if ($.fn.corner) $('.corner').corner()
})
// with this
.corner {
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
padding: 3px;
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
# 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/
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')
@stve
stve / gist:262974
Created December 24, 2009 02:30 — forked from ezmobius/gist:262085
require 'rubygems'
require 'redis'
require 'json'
require 'eventmachine'
class RedisLoop
class << self
attr_accessor :queues
def start(opts={}, &blk)
EM.run {
#!/usr/bin/env ruby
require 'socket'
host = ARGV[0] || 'localhost'
port = ARGV[1] || '6379'
trap(:INT) {
exit
}