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
| function asanaRequest($methodPath, $httpMethod = 'GET', $body = null) | |
| { | |
| $apiKey = 'ASANA_API_KEY_HERE'; /// Get it from http://app.asana.com/-/account_api | |
| $url = "https://app.asana.com/api/1.0/$methodPath"; | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_URL, $url); | |
| curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ; | |
| curl_setopt($ch, CURLOPT_USERPWD, $apiKey); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 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
| require 'rubygems' | |
| require 'mongoid' | |
| Mongoid.configure do |config| | |
| config.master = Mongo::Connection.new.db("test") | |
| end | |
| class User | |
| include Mongoid::Document | |
| field :name |
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 = {} |
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
| <%= 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
| # 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
| ## | |
| # 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
| # 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
| #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] |