Skip to content

Instantly share code, notes, and snippets.

View flakd's full-sized avatar

Flak DiNenno flakd

View GitHub Profile
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);
require 'rubygems'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("test")
end
class User
include Mongoid::Document
field :name
class Serializer < Struct.new(:object)
def to_hash
@hash ||= hash_object(object)
end
private
def hash_object(object)
hash = {}
@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'
})
<%= 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)
# 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
##
# 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
# 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)
#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]