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
| #container {position:absolute;} | |
| #controls, #mf_frame {display:table-cell; vertical-align:top;} | |
| #controls {top:0;} | |
| #mf_frame {overflow:scroll}; |
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
| 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 |
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
| 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'] |
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
| 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"; |
NewerOlder