Facebook API versioning

Facebook's Platform supports both versioning and migrations so that app builders can roll out changes over time. Goal of versioning: The goal for having versioning is for developers building apps to be able to understand in advance when an API or SDK might change. They help with web development, but are critical with mobile development because a person using your app on their phone may take a long time to upgrade (or may never upgrade). Faecbook recommends to use graph-api version 2: Older versions of Facebook's API will expire April 30, 2015 and there are some significant changes between the

passing an unsaved object in delayed_job

In our recent project , we came across one scenario, where we had to pass an unsaved record as argument in background job. As delayed_job doesn't allow unsaved AR objects as arguments ref: delayed_job issue when deserialising arguments we used serializing/deserialising approach for passing params. class PassingData def serialize(data) Base64.encode64(Marshal.dump(data)) end def deserialize(serialized_data) serialized_data = Base64.decode64(serialized_data) Marshal.load serialized_data end end user_details = PassingData.serialize @user where @user = user_data Mailer.delay.order_process("order confirm", user_details) #send mail in background #mailer method def order_process(

Translations using gettext_i18n_rails gem

Using as Gem: gem 'gettext_i18n_rails' Using as plugin: gem 'fast_gettext', '>=0.4.8' Add "gettext" if you want to find translations or build .mo files Add "ruby_parser" if you want to find translations inside haml/slim files gem 'gettext', '>=3.0.2', :require => false, :group => :development gem 'ruby_parser', :require => false, :group => :development Rakes: rake gettext:add_language[XX] This will also create the locale directory (where the translations are being stored) where XX is the ISO 639-1 2-letter code for the language you

MetricFu gem - code analysis tool

MetricFu is an aggregator of several static code analysis tools for Ruby. It displays code metrics from Flog, Flay, Saikuro, Churn, Reek, Roodi, Code Statistics, and Rails Best Practices (and optionally code coverage with RCov). With MetricFu, you get a combined HTML report of all the metrics. Installing gem: gem install metric_fu Running follwing command from your application root. metric_fu This will generate reports in metric_fu's output directory (tmp/metric_fu/output). By default, metric_fu will use the built-in html formatter to generate HTML reports for each metric with pretty graphs and output can be seen

Using OAuth2 gem

oauth2 - A Ruby wrapper for the OAuth 2.0 specification. gem install oauth2 Basics of OAuth2 is well explained here: Oauth2 basics Creating OAuth2::Client instance require 'oauth2' client = OAuth2::Client.new('client_id', 'client_secret', :site => 'https://example.org') OAuth2 provides four authentication grant types : Authorization Code Grant Implicit Grant Resource Owner Password Credentials Grant Client Credentials Grant In UN project, we have used Resource Owner Password Credentials Grant type token = client.password.get_token('username', 'password') In case if Credentials are not correct, OAuth2::Error will be raised. With correct credentials, it gives OAuth2::AccessToken instance which

Avoid Username and password while pushing git commits.

Avoid git prompt for password Locate the file ~/.netrc on linux based system (generally its hidden file in Home folder). Add following details in this file for github. machine github.com    login < username >    password < password > and save it On next git pull, git push, it will not prompt for username/password. Attached sample ~/.netrc file

Use syntax_fix gem to change old ruby hash style

Change old Ruby 1.8 hash syntax to new one in Rails app. syntax_fix gem changes the hash style from ':key => "value"' to 'key: "value"' Put this line in your Gemfile: gem 'syntax_fix' syntax_fix This command will check and rewrite all files with the new syntax. options: v <-- be verbose about the actions p [PATH] <-- specify the relative path to start actions from Reference: https://github.com/HeeL/syntax_fix

Check Unused CSS Code.

Dust-Me Selectors - Firefox plugin for checking unused css code. We can simply right click on page and do 'Spider this page'. It allows to view Unused selectors on the page. Download link: https://addons.mozilla.org/en-us/firefox/addon/dust-me-selectors/ More Info: http://www.pontikis.net/blog/remove-unused-css