This file contains hidden or 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
| #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] |
This file contains hidden or 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
| # 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) |
This file contains hidden or 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
| 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 |
This file contains hidden or 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 'twitter/api/arguments' | |
| require 'twitter/cursor' | |
| require 'twitter/user' | |
| module Twitter | |
| module API | |
| module Utils | |
| DEFAULT_CURSOR = -1 |
This file contains hidden or 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
| ## | |
| # 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 |
This file contains hidden or 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
| 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"; |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| <%= 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) |
This file contains hidden or 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 'grackle' | |
| client = Grackle::Client.new(:auth=>{ | |
| :type =>:oauth, | |
| :consumer_key =>'xxx', | |
| :consumer_secret =>'xxx', | |
| :token =>'xxx', | |
| :token_secret =>'xxx' | |
| }) |
This file contains hidden or 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
| class Serializer < Struct.new(:object) | |
| def to_hash | |
| @hash ||= hash_object(object) | |
| end | |
| private | |
| def hash_object(object) | |
| hash = {} |
OlderNewer