Skip to content

Instantly share code, notes, and snippets.

@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
@robertomiranda
robertomiranda / README.rdoc
Created August 26, 2011 16:33 — forked from woodie/README.rdoc
Rails 3 on App Engine

Rails 3.0.pre on App Engine

You can Rails 3 on App Engine, but it won’t be especially useful until bundler 10. You should try these instead:

Install the Development Environment

The gems for the development environment include a pre-release appengine-tools gem that provides a pre-release version of jruby-rack.

@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 / 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 / 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 / securing_rails_updates.md
Created March 5, 2012 19:15 — forked from peternixey/securing_rails_updates.md
How Homakov hacked GitHub and how to protect your application

##How Homakov hacked GitHub and the line of code that could have prevented it


Please note: THIS ARTICLE IS NOT WRITTEN BY THE GITHUB TEAM or in any way associated with them. It's simply hosted as a Gist because the markdown formatting is excellent and far clearer than anything I could manage on my personal Tumblr at peternixey.com.

If you'd like to follow me on twitter my handle is @peternixey


@robertomiranda
robertomiranda / elements.md
Created April 27, 2012 18:37 — forked from guilleiguaran/elements.md
Excerpts from The Elements of Programming Style. The source of this compilation is unknown.

The Elements of Programming Style

The following rules of programming style are excerpted from the book "The Elements of Programming Style" by Kernighan and Plauger, published by McGraw Hill. Here is quote from the book: "To paraphrase an observation in The Elements of Style by Strunk and White, the rules of programming style, like those of English, are sometimes broken, even by the best writers. When a rule is broken, however, you will usually find in the program some compensating merit, attained at the cost of the violation. Unless you are certain of doing as well, you will probably do best to follow the rules."

@robertomiranda
robertomiranda / users_controller.rb
Created July 19, 2012 21:47 — forked from guilleiguaran/users_controller.rb
Using attr_accessible: the right way
class UsersController < ApplicationController
include ActiveModel::MassAssignmentSecurity
attr_accessible :name, :age
attr_accessible :name, :age, :admin, :as => :admin
def create
@user = User.create!(user_params)
redirect_to @user
end
@robertomiranda
robertomiranda / chat.rb
Created October 13, 2012 20:15 — forked from rkh/chat.rb
Simple Chat Application using the Sinatra Streaming API
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
require File.expand_path(File.dirname(__FILE__) + '/neo')
# Project: Create a Proxy Class
#
# In this assignment, create a proxy class (one is started for you
# below). You should be able to initialize the proxy object with any
# object. Any messages sent to the proxy object should be forwarded
# to the target object. As each message is sent, the proxy should
# record the name of the method sent.
#