Tuesday, May 31, 2016

Using CORS with Amazon CloudFront

curl -I -s -X GET -H "Origin: www.rubyplus.com" https://cdn.rubyplus.com/assets/favicon-b73a7c5b51d68c8f821e1c0e44083c8b8762c977bd620995642c32fb074d2941.ico


$ curl -I -s -X GET -H "Origin: www.rubyplus.com" https://cdn.rubyplus.com/assets/favicon-b73a7c5b51d68c8f821e1c0e44083c8b8762c977bd620995642c32fb074d2941.ico
HTTP/1.1 200 OK
Content-Type: image/x-icon
Content-Length: 7406
Connection: keep-alive
Date: Wed, 01 Jun 2016 05:47:45 GMT
Server: Apache/2.2.22 (Ubuntu)
Last-Modified: Thu, 03 Mar 2016 08:51:13 GMT
Accept-Ranges: bytes
Cache-Control: max-age=31536000
Expires: Thu, 01 Jun 2017 05:47:45 GMT
X-Cache: Miss from cloudfront
Via: 1.1 aa96a51fedae85199c643eb5c8eca4e4.cloudfront.net (CloudFront)
X-Amz-Cf-Id: p697DTznUAZ_KZ11Xju2o7NvTcadsRVXDfZOnhluNFruy9ydoB66_w==

zepho-mac-pro:blog5 zepho$ curl -I -s -X GET -H "Origin: www.rubyplus.com" https://cdn.rubyplus.com/assets/favicon-b73a7c5b51d68c8f821e1c0e44083c8b8762c977bd620995642c32fb074d2941.ico
HTTP/1.1 200 OK
Content-Type: image/x-icon
Content-Length: 7406
Connection: keep-alive
Date: Wed, 01 Jun 2016 05:47:45 GMT
Server: Apache/2.2.22 (Ubuntu)
Last-Modified: Thu, 03 Mar 2016 08:51:13 GMT
Accept-Ranges: bytes
Cache-Control: max-age=31536000
Expires: Thu, 01 Jun 2017 05:47:45 GMT
Age: 23
X-Cache: Hit from cloudfront
Via: 1.1 f46e4d7bc5419470a70eb57aa9c935c8.cloudfront.net (CloudFront)
X-Amz-Cf-Id: n6-6jiHmOd25W16ws30v21U9odCOQ1y6xH70o5RMM9tbh91i-abF0w==

The response does not have:

Access-Control-Allow-Origin: *.example.com

The changes are still in progress on Amazon CDN. Wait for 30 minutes or so and test again.

Firefox errors:

Downloadable font: download failed (font-family: "OpenSans-Regular" style:normal weight:normal stretch:normal src index:0): bad URI or cross-site access not allowed
source: https://cdn.rubyplus.com/assets/OpenSans-Regular-e64e508b2aa2880f907e470c4550980ec4c0694d103a43f36150ac3f93189bee.ttf


Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://cdn.rubyplus.com/assets/OpenSans-Regular-e64e508b2aa2880f907e470c4550980ec4c0694d103a43f36150ac3f93189bee.ttf. This can be fixed by moving the resource to the same domain or enabling CORS.


CORS
Using CORS with CloudFront and S3

Tuesday, May 24, 2016

Better Errors & RailsPanel in Rails 5

Better Errors & RailsPanel  works fine in Rails 5. Here is the instructions to get it working in Rails 5:

rails g model project name
rails g model task name project:references completed_at:datetime
rake db:migrate

rails g controller projects index show new edit
rails g controller tasks


The routes:

  resources :projects
  resources :tasks
  root to: 'projects#index'

Everything works except:
 
http://localhost:3000/__better_errors

undefined method `cause' for nil:NilClass             

    def original_exception(exception)
      if @@rescue_responses.has_key?(exception.cause.class.name)
        exception.cause
      else
        exception

Rails Panel 

Top Links for May 30, 2016

Pointless Features Add to Browser Bloat and Insecurity

83 % of browser features are used by under 1 % of the most popular 10,000 websites. These features are also not used by the end users. 50 % of the JavaScript provided features in the web browser are never used by the top ten thousand most popular websites. Read this article to get an idea of what features to avoid using in your Rails apps to prevent your app getting blocked by blockers.

Streaming data with ActionController::Live

Rails 5 final release is almost here. The most exciting feature is the ActionCable. Why do we need ActionController::Live when we have ActionCable? The short answer is that Server Side Events are one-way, it goes from the server to the client, whereas ActionCable is two-way communication between client and server. Checkout this article to learn more.

 


Monday, May 23, 2016

Analytics Strategies for Rails

Analyze this... Analytics Strategies for iOS and Rails by Lance Gleason
Data-Driven Documents
D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG, and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.
D3.js Gallery


Sunday, May 22, 2016

Amazon CDN CORS problem in Rails App

Problem

Font from origin 'https://d1b5oz78c0udqh.cloudfront.net' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://rubyplus.com' is therefore not allowed access.

Solution

1. Point your subdomain to your AWS Cloudfront domain. Go to AWS Cloudfront control panel, select your Cloudfront distribution and enter your CDN subdomain into the Alternate Domain Names (CNAMEs) field. Something like cdn.myawesomeapp.com will do.

2. Create a CNAME for cdn.myawesomeapp.com pointing to sdf73n7ssa.cloudfront.net.

3. Test your new CDN domain by making sure assets served are from cloudfront.

curl -I http://cdn.myawesomeapp.com/assets/image.png

4. AWS supports SSL Server Name Indication (SNI). Upload your SSL certificate to AWS first.
   Install the AWS command line tool first (that’s easy). Once you have your AWS command line tool installed and configured with the AWS keys, you can upload your SSL certificate:
 
   aws iam upload-server-certificate --server-certificate-name my_certificate_name --certificate-body file://my_cert.crt --private-key file://my_key.key --certificate-chain file://intermediate_cert.pem --path /cloudfront/my_cert_name_here/
 
5. Head back to your CDN distribution on AWS Cloudfront and select “Custom SSL Certificate (stored in AWS IAM)” and “Only Clients that Support Server Name Indication (SNI)” options.  

6. Now you should be able to see your assets both on HTTP and HTTPS served from CDN. Test it with CURL:

curl -I https://cdn.myawesomeapp.com/assets/image.png

7. Change your config.action_controller.asset_host in your production.rb to //cdn.myawesomeapp.com

Reference

Cross Origin Resource Sharing (CORS) Blocked for Cloudfront in Rails

Thursday, May 19, 2016

How to find the location based on IP address

Use geocoder gem:

rails c
> Geocoder.search('209.249.19.172').first
 => #"209.249.19.172", "country_code"=>"US", "country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"Moraga", "zip_code"=>"94556", "time_zone"=>"America/Los_Angeles", "latitude"=>37.8381, "longitude"=>-122.1026, "metro_code"=>807}, @cache_hit=nil>

Uncaught Error: Bootstrap tooltips require Tether (http://github.hubspot.com/tether/)

Add this:

source 'https://rails-assets.org' do
  gem 'rails-assets-tether', '>= 1.1.0'
end

to Gemfile. Run bundle.

//= require tether

after jQuery in application.js.

Pinterest Clone in Rails 5

Pinterest Clone in Rails 5


Why Display Popular Articles?

It can help visitors to easily find more of your best content. This can help new visitors find your best articles, as soon as they arrive at your website. This will increase the time spent on your website, reduce bounce rate, and improve the number of page views per visit.

RubyPlus Podcast Episode 5

Wednesday, May 18, 2016

Elasticsearch::Transport::Transport::Errors::BadRequest

Error: [400] No handler found for uri [/_alias/articles_development] and method [GET]
Resolution : Make sure elasticsearch server is running.

Waiting for the day when the error messages are meaningful and the searchkick code becomes robust.

Autocomplete in Rails 5 Apps

Autocomplete using Typeahead and Searchkick in Rails 5

The Railscast episode #399 has been updated in the above article. Check it out.

Benefits of Search Suggest Systems

1. Spelling mistakes are avoided
2. Fewer keys need to be typed
3. Suggestions provide immediate feedback in terms of what queries are possible.

The absence of a suggestion could indicate that there many not be responses for the query. Will this affect collecting search terms that we may discover for creating new content?

Use auto-complete to:
  •     Facilitate accurate and efficient data entry
  •     Select from a finite list of names or symbols
Use auto-suggest to:
  •     Facilitate novel query reformulations
  •     Select from an open-ended list of terms or phrases
  •     Encourage exploratory search (with a degree of complexity and mental effort that is appropriate to the task). Where appropriate, complement search suggestions with recent searches

Use instant results to:

    Promote specific items or products
   

References  

Designing Search: As-You-Type Suggestions   
Search Auto Complete
Autocomplete as a Research Tool: A Study on Providing Search Suggestions

7 Factors to Consider when Evaluating a Library

Consider the following 7 factors when evaluating a third-party library.

1. Efficacy: How well does it work?
2. Performance: How well does it perform?
3. Reliability: Can I depend on it?
4. Ease of Use: How much effort does it require?
5. Flexibility: How many things does it do?
6. Aesthetic Appeal: How aesthetically pleasing is it?
7. Time Sink: How much time do I have to give up to maintain it?

How well is it written?
Can I customize it easily?
How responsive are the developers in fixing bugs?
Does it support the latest version of the language it is written?

I recently had to use Customer instead of User for using a Ruby gem. The assumptions made by this library was not applicable to my project. I sent an email to the author. He never responded. It is better to develop your own library if you can simplify the existing library code.

Tuesday, May 17, 2016

Railscast Episode 190 Upgrade Attempt to Rails 5

rails g model category name
rails g model product name price:decimal category:references description:text custom_url

rails g controller categories
rails g controller products

class Category < ApplicationRecord
  has_many :products
end

Rails.application.routes.draw do
  resources :products
  resources :categories
 
  root 'products#index'
end

Category.delete_all
['Electronics', 'Office Supplies', 'Toys', 'Clothing', 'Groceries'].each do |name|
  Category.create!(name: name)
end

Product.delete_all
categories = Category.all
words = File.readlines("/usr/share/dict/words")
lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
25.times do
  Product.create!(name: words.pop.titleize,
                  category: categories.sample,
                  description: lorem, price: [4.99, 9.99, 14.99, 19.99, 29.99].sample)
end


rails db:seed

Use SelectorGadget to find the CSS selector to use in the script.

rake fetch_prices rake task is broken because Walmart UI has changed.

Paperclip::Errors::NotIdentifiedByImageMagickError

identify Captain-America-2011-Movie-Poster-1.jpg
dyld: Library not loaded: /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libclparser.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

identify -version
dyld: Library not loaded: /System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries/libclparser.dylib
  Referenced from: /usr/local/bin/identify
  Reason: image not found
Trace/BPT trap: 5

This means ImageMagick is not installed on your machine. It would be useful if the paperclip gem makes the assumption explicit. If the pre-requisite software is not installed, ideally, it should throw an exception that identifies the cause of the problem and the resolution to inform the user on how to overcome that error.

You can do:

brew install imagemagick

If you get an error like this:

brew install imagemagick
Warning: Your Xcode (4.5.2) is outdated
Please install Xcode 4.6.2.
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing imagemagick dependency: jpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.lion.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring jpeg-8d.lion.bottle.1.tar.gz
Warning: Could not link jpeg. Unlinking...
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link jpeg'
==> Summary
🍺  /usr/local/Cellar/jpeg/8d: 18 files, 784K
==> Installing imagemagick
==> Downloading http://downloads.sf.net/project/machomebrew/mirror/ImageMagick-6.8.0-10.tar.gz
######################################################################## 100.0%
==> ./configure --disable-osx-universal-binary --without-perl --prefix=/usr/local/Cellar/imagemagick/6.8.0-10 --enable-shared --disa
==> make install
brew: superenv removed: -L/usr/X11/lib -L/usr/local/lib -O2
brew: superenv removed: -L/usr/X11/lib -L/usr/local/lib -O2
brew: superenv removed: -L/usr/X11/lib -L/usr/local/lib -O2
make[1]: *** [install-recursive] Error 1
make: *** [install] Error 2

READ THIS: https://github.com/mxcl/homebrew/wiki/troubleshooting

You can install it from the source. Download 

http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.0.3
./configure
make
sudo make install

The ImageMagick Installer for Mac  also failed for me on Mac OS 10.7.5.

Rails Upgrade from 3.2 to 4.2 Active Record Update Checklist

To migrate dynamic finders to Rails 4.1+:
  • find_all_by_... should become where(...).
  • find_last_by_... should become where(...).last.
  • scoped_by_... should become where(...).
  • find_or_initialize_by_... should become find_or_initialize_by(...).
  • find_or_create_by_... should become find_or_create_by(...).
https://github.com/rails/activerecord-deprecated_finders

Notes for Ahoy User Analytics Gem

Checking for a bot so that we can exclude it from the analytics

def bot?
  @bot ||= request ? Browser.new(request.user_agent).bot? : false
end

Location : Geocoder.search(@ip).first

Look at these classes:

RequestDeckhand
TechnologyDeckhand
TrafficSourceDeckhand
UtmParameterDeckhand

Dependent Gems

addressable, browser, geocoder, referer-parser, user_agent_parser, request_store, uuidtools, safely_block, rack-attack

How to Develop Moonshine Plugin

1. Create a new Rails 4.2.6 project
2. Add gem 'plugger' and run bundle
3. plugger install git://github.com/railsmachine/moonshine.git
4. rails g to list all available generators
5. rails g moonshine:plugin wordnet
6. rails g moonshine:plugin wordnet
      create  vendor/plugins/moonshine_wordnet/LICENSE
      create  vendor/plugins/moonshine_wordnet/README.markdown
      create  vendor/plugins/moonshine_wordnet/moonshine/init.rb
      create  vendor/plugins/moonshine_wordnet/lib/moonshine/wordnet.rb
      create  vendor/plugins/moonshine_wordnet/spec/moonshine/wordnet_spec.rb
      create  vendor/plugins/moonshine_wordnet/spec/spec_helper.rb
7. Automate these commands:

      cd /tmp
      curl -o wordnet.tar.gz http://wordnetcode.princeton.edu/3.0/WNprolog-3.0.tar.gz
      tar -zxvf wordnet.tar.gz
      mv prolog/wn_s.pl /var/lib

in lib/moonshine/wordnet.rb.





Reference:
 
Mongodb Moonshine Plugin:

exec 'install_mongodb',
        :command => [
          "wget http://downloads.mongodb.org/linux/mongodb-linux-#{arch}-#{options[:version]}.tgz",
          "tar xzf mongodb-linux-#{arch}-#{options[:version]}.tgz",
          "mv mongodb-linux-#{arch}-#{options[:version]} /opt/local/mongo-#{options[:version]}"
        ].join(' && '),
        :cwd => '/tmp',
        :creates => "/opt/local/mongo-#{options[:version]}/bin/mongod",
        :require => [
          file('/opt/local'),
          package('wget')
        ]

Top Links for May 17, 2016

[23 Years of Ruby with Matz (Yukihiro Matsumoto)](https://changelog.com/202 23 Years of Ruby with Matz)

Matz, the creator of Ruby discusses the origins of the Ruby programming language, its history and future, Ruby 3.0, Concurrency and Parallelism, Streem, Erlang, Elixir, and more.

[Rails 5.0.0rc1 Released – Is ActionCable Ready for Prime Time? ](https://www.clearvoice.com/rails-5-0-0rc1-released-actioncable-ready-prime-time/ 'Rails 5.0.0rc1 Released – Is ActionCable Ready for Prime Time? ') by clearvoice\

As the web evolves and users become more demanding, the need for web applications to be interactive and immediate grows. Rails 5.0 is now more than ready to play with. This is a quick introduction to getting it up and running and a very simple Action Cable example.


[How to Build a Simple Math Evaluation Engine](https://blog.codeship.com/build-math-evaluation-engine/ 'How to Build a Simple Math Evaluation Engine') by Jesus Castello

Early on in Ruby, you learn to evaluate a math expression in irb. What’s the magic behind this operation? Create your own evaluation engine and find out.

[Jeremy Daer's RailsConf 2016 Opening Keynote](https://www.youtube.com/watch?v=nUVsZ4vS1Y8 'Jeremy Daer RailsConf 2016 Opening Keynote')
Relaxed reflections on the history and meaning of Rails and Basecamp as a way to explain Rails' ongoing relevance. The final 10 minutes has the more feature-based/newsy stuff.

[Ruby on Google App Engine goes beta](https://cloudplatform.googleblog.com/2016/05/Ruby-on-Google-App-Engine-goes-betaruntime.html 'Ruby on Google App Engine goes beta')

Frameworks such as Ruby on Rails and Sinatra make it easy for developers to rapidly build web applications and APIs for the cloud. App Engine provides an easy to use platform for developers to build, deploy, manage, and automatically scale services on Google’s infrastructure.

[Don't Forget About Infinite Enumerators](http://aaronlasseigne.com/2016/05/11/dont-forget-about-infinite-enumerators/ 'Don't Forget About Infinite Enumerators') by AAaron Lasseigne

When was the last time you created an Enumerator? We use enumerables all over the place but it’s rare to see Enumerator.new. Sometimes you forget it’s an option. With finite enumerations you are immediately limiting where they can be used. They come with an extra expectation that must be addressed. Are there enough elements for me? When they’re infinite you can just go crazy.

[Notes from RailsConf 2016 opinion]( 'Notes from RailsConf 2016 opinion')
Kir Shatrov shares his thoughts and observations from this year’s RailsConf.

[WYSIWYG Editor with Trix](https://www.driftingruby.com/episodes/wysiwyg-editor-with-trix 'WYSIWYG Editor with Trix')

Compose beautifully formatted text in your web application. Trix is a WYSIWYG editor for writing messages, comments, articles, and lists.


[Rails Performance and the root of all evil](http://blog.scoutapp.com/articles/2016/05/09/rails-performance-and-the-root-of-all-evil 'Rails Performance and the root of all evil') By Sudara

This article talks about how to identify what matters in performance, measure twice : cut once, evil and non evil optimizations.

[Do You Need That Gem?](rightonruby.com/2015/do-you-need-that-gem-sam-phippen 'Do You Need That Gem') by Sam Phippen
Sam Phippen looks at the trials and tribulations of managing third party dependancies in our Ruby apps. It's a 18 minutes video. Checkout the podcasts section of rubyplus.com for the link.

[The Top Rails Code Smell To Avoid to Keep Your App Healthy](https://medium.com/planet-arkency/the-biggest-rails-code-smell-you-should-avoid-to-keep-your-app-healthy-a61fd75ab2d3#.xujqf0g9i 'The Top Rails Code Smell To Avoid to Keep Your App Healthy') by Marcin Grzywaczewski
Marcin ponders what common pattern in Rails causes the most pain and settles for ActiveRecord callbacks. Here he explains why.

[An Introduction to Rails Testing Antipatterns](http://code.tutsplus.com/articles/antipatterns-basics-rails-tests--cms-26011 'An Introduction to Rails Testing Antipatterns') by Ed Wassermann

An introduction to testing anti-patterns in Rails aimed at developers who want to pick up some valuable best practices.




[Allow accessing all helpers at the controller level](https://github.com/rails/rails/pull/24866 'Allow accessing all helpers at the controller level')
With this helper proxy, users can reuse helpers in the controller without having to include all the modules related to view context.

[Add ActiveModel::RangeError](https://github.com/rails/rails/pull/24835 'Add ActiveModel::RangeError')
When provided with large numbers, Active Model now fails with a new ActiveModel::RangeError that makes it easier to rescue from, and inherits from RangeError to maintain backward compatibility.

[Ensure compatibility between Rails Session and Rack Session](https://github.com/rails/rails/pull/24820 'Ensure compatibility between Rails Session and Rack Session')
Rails session is now compatible with other Rack frameworks like Sinatra that are mounted in Rails. They can also use session tooling of Rails without any issues now.

[RailsConf Talks on YouTube]
Confreaks has posted videos for each session on confreaks.tv.

elasticsearch-rails vs searchkick

I have implemented search feature using elasticsearch-rails and searchkick for rubyplus.com. Searckick requires less code, is elegant and makes it easy to implement fuzzy search that handles spelling mistakes. Search Feature using ElasticSearch in Rails 5 shows how to use elasticsearch-rails gem and Search Feature using Searchkick in Rails 5 show how to use searchkick.

How to Install ElasticSearch on Linode using Moonshine

1. Install elasticsearch mooonshine plugin.

plugger install git://github.com/railsmachine/moonshine_elasticsearch.git --force
2. Add the elasticsearch configuration in config/moonshine.yml:
:elasticsearch:
  :version: 0.90.12
  :cluster_name: mycluster
3.  Include the recipe in manifest file. 

recipe :elasticsearch
Deploy it using Capistrano. You can see a demo on rubyplus.com search feature.

Saturday, May 14, 2016

Integrating Twitter Bootstrap 4 with Rails 5

I have upgraded the movies database Rails app that uses Twitter Bootstrap 3 and Rails 4 developed by Mackenzie Child to Twitter Bootstrap 4 and Rails 5, check it out:
Integrating Twitter Bootstrap 4 with Rails 5

Install Nodejs on Linux

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

Friday, May 13, 2016

How to update git in Ubuntu

sudo add-apt-repository ppa:git-core/ppa -y
sudo apt-get update
sudo apt-get install git
git --version

How to debug httpparty gem


If you want to see the request and the body sent to the server, use debug_output method.

      include HTTParty
      debug_output $stdout

Thursday, May 12, 2016

How to style search form using Twitter Bootstrap 3 in Rails 4.2.6 Apps





Failed to open TCP connection to localhost:9200 (Connection refused - connect(2) for "localhost" port 9200)

sudo /usr/local/bin/elasticsearch

Full Text Search using ElasticSearch in Rails 5

Full Text Search using ElasticSearch in Rails 5

Learn how to use full text search using elasticsearch gems in Rails 5 apps.

Bounce Rate

What does high bounce rate mean?

It means landing pages are not relevant to your visitors.

How to Improve Bounce Rate?

1. Add links to more pages within your website in your content. Think about other pages that people interested in that piece of content will want to see, and link to them throughout the content and at the end in a “if you liked this, you’ll love this” kind of way.
2. Provide relevant content. Create landing pages tailored to each keyword and ad so that visitors can find what was promised.
3. Link to a glossary page that defines industry terms.
4. Place search function prominently. In the articles page, search box should have autocomplete and show relevant articles in the results.
5. Open external links in a new window.
6. Speed up page load.
7. Get rid of pop-up ads.
8. Keep the category list short (12 or less).

Tuesday, May 10, 2016

Trouble Shooting Psych::SyntaxError

I was getting:
Psych::SyntaxError:
       (): did not find expected key while parsing a block mapping at line 59 column 7
in the yml file.

To troubleshoot use Online YAML Parser  and check which line is having the problem and remove the line to get back to working version. Gradually introduce more text into the yml file to figure out the cause of the problem. 

How to listen to RubyPlus Podcast on Google Play using any Browser

You can listen to RubyPlus podcast that covers the latest news from Ruby and Rails community on Google Play. You can use any browser to listen to the episodes. Go to https://play.google.com/music and search for rubyplus podcast. You can click on any episode you want to listen to enjoy the podcast.

Monday, May 09, 2016

Preserving Exact Body Bytes in VCR

1. If you look at the VCR cassettes, you can see the response in JSON or Base64 encoded response.
2. Copy the Base64 encoded response and decode it using online Base64 decoder.
3. The result can be pasted on online JSON formatter and you will the JSON response.

Why does VCR do this for some requests?
What is the use of knowing this fact?

If you are having difficulty in making a test pass. You can change the string to a known input by encoding the known output for a given input in the VCR fixture file. This will make the test pass.

Saturday, May 07, 2016

Ruby Podcast Episode 4

Learn about the basic software development laws such as Linus's Law, Occam's Razor, Hanlon's Razor, The Pareto Principle, Postel's Law, Hofstadter's Law and The 90-90 Rule. Listen to RubyPlus Ruby Podcast 4 .

Wednesday, May 04, 2016

error: git-credential-osxkeychain died of signal 11

When I git push to my repository I got an error on Mac OS 10.7.5
>>>git push
error: git-credential-osxkeychain died of signal 11
There's a bug in git-credential-osxkeychain so simply replace that with new one on S3.
$which git git-credential-osxkeychain
/usr/local/git/bin/git-credential-osxkeychain
$curl -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 15520  100 15520    0     0   5446      0  0:00:02  0:00:02 --:--:-- 11014
$ sudo mv git-credential-osxkeychain /usr/local/git/binn
$ chmod 755 /usr/local/git/bin/git-credential-osxkeychain

RailsCast Episode 168

The name of the gem has been changed. Here is the same code from the gem home page.

gem install feedjira




url = "http://feedjira.com/blog/feed.xml"
feed = Feedjira::Feed.fetch_and_parse url
feed.title
entry = feed.entries.first
entry.title
entry.url