Skip to content

Instantly share code, notes, and snippets.

View flakd's full-sized avatar

Flak DiNenno flakd

View GitHub Profile
#container {position:absolute;}
#controls, #mf_frame {display:table-cell; vertical-align:top;}
#controls {top:0;}
#mf_frame {overflow:scroll};
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
@flakd
flakd / gist:6063395
Created July 23, 2013 15:38
JS - angular.js - get function parameter names dynamically
Below is the code taken from AngularJS which uses the technique for its dependency injection mechanism.
And here is an explanation of it taken from http://docs.angularjs.org/tutorial/step_05
Angular's dependency injector provides services to your controller when the controller is being constructed. The dependency injector also takes care of creating any transitive dependencies the service may have (services often depend upon other services).
Note that the names of arguments are significant, because the injector uses these to look up the dependencies.
/**
* @ngdoc overview
@flakd
flakd / gist:6063382
Last active December 20, 2015 03:28
JS get parameter names dynamically
RIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function getParamNames(func) {
var funStr = func.toString();
funStr = funStr.replace(STRIP_COMMENTS, '');
return funStr.slice(funStr.indexOf('(')+1, funStr.indexOf(')')).match(/([^\s,]+)/g);
}
Example usage:
getParamNames(getParamNames) // returns ['func']
getParamNames(function (a,b,c,d){}) // returns ['a','b','c','d']
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
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";