Skip to content

Instantly share code, notes, and snippets.

@robertomiranda
robertomiranda / factories.rb
Created January 6, 2012 20:32 — forked from anonymous/factories.rb
Simulate Paperclip Attachments With FactoryGirl
Factory.define :item do |f|
include ActionDispatch::TestProcess
f.name "Macbook Pro 15"
f.price_in_dollars 1500
f.photo Rack::Test::UploadedFile.new(File.join(Rails.root, 'spec', 'support', 'rails.png'), 'image/png')
end
@robertomiranda
robertomiranda / gist:1353365
Created November 9, 2011 22:36 — forked from gerson/gist:1353362
Tracking facebook friends with me app permission
def suggested_rivals_facebook
friend_user_ids = []
if authentications.size > 0 && authentications.map(&:provider).include?("facebook")
auth = authentications.where(:provider => 'facebook').map.first
friends_application = FbGraph::Query.new("SELECT uid FROM user WHERE is_app_user=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = #{auth.uid})").fetch("#{auth.access_token}")
friends_application.collect! {|par| par["uid"].to_s}
friend_user_ids = User.where("authentications.provider" => "facebook").any_in("authentications.uid" => friends_application).not_in("_id" => rivals.map(&:competitor)).map
end
friend_user_ids
end
@robertomiranda
robertomiranda / heroku_autoscaler.rb
Created November 2, 2011 15:15 — forked from jfgomez86/heroku_autoscaler.rb
Quick Dirty Heroku AutoScaling script that may save you money. Works with Delayed Job.
# Inspired by http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
module HerokuAutoscale
module Scaler
class << self
@@heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS'])
def workers
@@heroku.info(ENV['HEROKU_APP'])[:workers].to_i
end
@robertomiranda
robertomiranda / README.rdoc
Created August 26, 2011 16:33 — forked from woodie/README.rdoc
Rails 3 on App Engine
@robertomiranda
robertomiranda / tweet.rb
Created July 29, 2011 16:13 — forked from jfgomez86/tweet.rb
Finding latest tweets by unique users
##
# Find latest *n* tweets, but don't repeat tweets by users.
# Example:
#
# If we have the following table:
#
# id | user_id | created_at
# 1 | 1 | 3 days ago
# 2 | 2 | 3 days ago
# 3 | 1 | 2 days ago