Skip to content

Instantly share code, notes, and snippets.

View flakd's full-sized avatar

Flak DiNenno flakd

View GitHub Profile
#Deploy and rollback on Heroku in staging and production
task :deploy_staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
task :deploy_production => ['deploy:set_production_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
task :staging_migrations => [:set_staging_app, :push, :off, :migrate, :restart, :on, :tag]
task :staging_rollback => [:set_staging_app, :off, :push_previous, :restart, :on]
# Here is a little recursive method that pulls in all Twitter friends using recursion
require 'rubygems'
require 'twitter'
def get_twitter_friends_with_cursor(cursor, list, client)
# Base case
if cursor == 0
return list
else
hashie = client.friends(:cursor => cursor)
@flakd
flakd / GetTwitterFriends
Created July 2, 2013 12:19
Getting a list of your Twitter friends in Ruby/Rails while avoiding the Twitter rate limit error
First create the following definition.
def get_cursor_results(action, items, *args)
result = []
next_cursor = -1
until next_cursor == 0
begin
t = @client.send(action, args[0], args[1], {:cursor => next_cursor})
result = result + t.send(items)
next_cursor = t.next_cursor
@flakd
flakd / gist:5908894
Created July 2, 2013 12:34
Twitter gem (sferik/twitter) lib/twitter/api/utils.rb
require 'twitter/api/arguments'
require 'twitter/cursor'
require 'twitter/user'
module Twitter
module API
module Utils
DEFAULT_CURSOR = -1
##
# Below is a template for implementing the "OAuth Dance" with Twitter using the Ruby OAuth gem in a Rails app.
# Ruby OAuth gem is required by grackle and is found here: http://github.com/oauth/oauth-ruby
##
# Step 1: User clicks "Sign in with Twitter" button
# Step 2: User is routed to your controller action that looks like the method below
def start_oauth
Using oAuth you are able to make calls to get user info from your TwitterOAuth object.
e.g if $oauth = new TwitterOAuth([keys here])
$credentials = $oauth->get('account/verify_credentials');
echo "Connected as @" . $credentials->screen_name ."\n";
# http://rails-bestpractices.com/posts/48-use-openstruct-when-advance-search
class Tableless
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
def initialize(props = {})
props.each do |name, value|
send("#{name}=", value)
end
<%= form_for OpenStruct.new(:message => ''), :url => ... do |f| %>
<%= f.text_field :message %>
<% end %>
# config/initializers/open_struct_extensions.rb
class OpenStruct
def respond_to?(symbol, include_private = false)
@flakd
flakd / gist:5950366
Last active December 19, 2015 11:49
Handling large requests/responses with Grackle
require 'grackle'
client = Grackle::Client.new(:auth=>{
:type =>:oauth,
:consumer_key =>'xxx',
:consumer_secret =>'xxx',
:token =>'xxx',
:token_secret =>'xxx'
})
class Serializer < Struct.new(:object)
def to_hash
@hash ||= hash_object(object)
end
private
def hash_object(object)
hash = {}