Monday, February 27, 2017

Mac OS 10.10.5

Type gcc in a terminal, install GCC by clicking the popup window.

Install Brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew install gnupg gnupg2

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3


\curl -sSL https://get.rvm.io | bash

Rails 5.1 and Webpack Tutorial

https://medium.com/@gauravtiwari/hey-bp-strange-is-webpack-dev-server-installed-5c1ec83517e8#.fci5ohl22
 
brew update
brew install yarn 
yarn add webpack-dev-server
 
 

Friday, February 24, 2017

Learning to be awesome at anything you do, including being a leader | Tasha Eurich

Step 1 is to know thyself.
Then on the right hand side for each skill, on a scale of 1 to 10,
I want you to imagine that you only got better at that,
and then rate how much more awesome you would be.
Start with the highest number and work your way down.
So, you know yourself, you've got your one thing.
What makes someone exceptional is that they earn it through daily practice.
Everyday on his way to work he'd think about what he was trying to improve,
and he'd make a plan to practice it.
Then on the way home, he would think about how he did,
and maybe some ideas for what he would the next day.
In sum total, Steve probably spent less than 30 minutes a week doing this,
and he saw massive returns.
So, everyday, I want you to jump out of bed and say,
"Today is the day I'll get better at my one thing!"
But every day you'll learn, and every day you'll get better.
Know thyself. Pick one thing. Practice daily.

Friday, February 17, 2017

Horrible Coding by Amazon Developers

If you do not have Internet connectivity, it will crash with meaningless error:

Users/bparanj/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/net/http.rb:933:in `connect_nonblock': SSL_connect returned=1 errno=0 state=error: certificate verify failed (Seahorse::Client::NetworkingError)

This can also happen if you do not click on agree button when you are on starbucks coffee shop.

If you provide a invalid file in a s3 bucket, aws-sdk version 2 will crash with meaningless error message:

 # []>>
ArgumentError: expected params[:key] to be a String, got value []> (class: Rake::FileTask) instead.

You must provide a valid file name. The library is not capable of telling you the cause of the problem and how to fix it. It will crash inside aws-sdk-core with an ugly stack trace:

/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/param_validator.rb:28:in `validate!'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/param_validator.rb:13:in `validate!'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/param_validator.rb:20:in `call'
/gems/aws-sdk-core-2.7.0/lib/seahorse/client/plugins/raise_response_errors.rb:14:in `call'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/s3_sse_cpk.rb:19:in `call'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/s3_dualstack.rb:24:in `call'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/s3_accelerate.rb:34:in `call'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/idempotency_token.rb:18:in `call'
/gems/aws-sdk-core-2.7.0/lib/aws-sdk-core/plugins/param_converter.rb:20:in `call'
/gems/aws-sdk-core-2.7.0/lib/seahorse/client/plugins/response_target.rb:21:in `call'
/gems/aws-sdk-core-2.7.0/lib/seahorse/client/request.rb:70:in `send_request'
/gems/aws-sdk-core-2.7.0/lib/seahorse/client/base.rb:207:in `block (2 levels) in define_operation_methods'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/request.rb:24:in `call'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/operations.rb:41:in `call'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/operations.rb:61:in `call'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/resource.rb:147:in `load'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/resource.rb:120:in `data'
/gems/aws-sdk-resources-2.7.0/lib/aws-sdk-resources/resource.rb:223:in `block in add_data_attribute'

/gems/railties-4.2.7/lib/rails/commands/console.rb:110:in `start'
/gems/railties-4.2.7/lib/rails/commands/console.rb:9:in `start'
/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:68:in `console'
/gems/railties-4.2.7/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
/gems/railties-4.2.7/lib/rails/commands.rb:17:in `'





AWS SDK Ruby


Aws::Errors::MissingRegionError
Aws::Errors::MissingCredentialsError (unable to sign request without credentials set). In aws sdk version 2:

    Aws.config = {
      region: 'us-east-1',
      credentials: Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
    }

Tuesday, February 14, 2017

Ruby Gems Naming Convention

How does the gem name and the require relate to each other? Should I use underscore of the gem name? Should I use / ?

The screenshot shows the rubygems recommendation for naming conventions and how developers can require a ruby gem. This also makes it clear how the directory structure is related to the require of the gem. You can see whether it is a class or module and how the namespace relates to requiring a gem.

Sunday, February 12, 2017

Readline was unable to be required, if you need completion or history install readline then reinstall the ruby.

1. brew install openssl --force


2. rvm requirements
Checking requirements for osx.
Updating Homebrew...
Installing requirements for osx.
Updating system.....
Installing required custom packages: homebrew/versions.
Installing required packages: zlib, zlib, gcc46, openssl.............
Somehow it happened there is no executable 'openssl',
run 'brew doctor' and make sure latest '' is installed properly.
RVM autolibs is now configured with mode '4' =>
  'Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X).',
please run `rvm autolibs enable` to let RVM do its job or run and read `rvm autolibs [help]`
or visit https://rvm.io/rvm/autolibs for more information.

Requirements installation failed with status: 12.

3. rvm pkg install readline
Beware, 'rvm pkg ...' is deprecated, read about the new autolibs feature: 'rvm help autolibs'.

rvm reinstall all --force


Twitter Bootstrap 4 Testimonials


Friday, February 10, 2017

How to migrate your RSS feed in Rails

I am migrating from libsyn to save $40 / month. I host all the videos on S3 saving lot of money. If you go live with your RSS feed pointing to libysyn when you switch over to your Rails rss feed, you must add:

xml.itunes :"new-feed-url", 'https://www.rubyplus.com/episodes.rss'

in index.rss.builder inside the channel tag to migrate successfully. This is in addition to logging in to your libshit account and changing the RSS feed to point to your new feed generated by your Rails app.

Thursday, February 09, 2017

How to set default date in date_select of Rails 5

You can use the selected option to specify the default date.

    <%= f.date_select :published_at, order: [:month, :day, :year], start_year: Date.current.year - 5, end_year: Date.current.year + 1, selected: @date %>

In my case, I set it in the controller to today's date:

@date = Date.today


Tuesday, February 07, 2017

Rails Assets


$ is not defined error in Rails

I followed the Google Page Speed Guidelines and made the javascript load asynchronously to speed up rubyplus.com. The problem was that I was getting the $ is not defined error. I had included the javascript tag before the jQuery script that hides the notice. Eventually, I came across this post:
Rails 4 Gotcha Asynchronous Loading of Javascript that finally fixed the problem. The fix is:

Change:

  <%= javascript_include_tag "application", "data-turbolinks-track" => true, async: true %>

to

  <%= javascript_include_tag "application", "data-turbolinks-track" => true, async: Rails.env.production? %>

I know this is a quick hack. Ideally, we should define a configuration variable to read and set the flag value in development.rb and production.rb. That's for another iteration and deploy. It works in development, now, I will see how it works in production for some time.

RubyPlus Download Stats


Sunday, February 05, 2017

DataTables using Twitter Bootstrap 4


No database selected

Provide the database name using --database switch when you want to import data into your database in MysSQL.

mysql -u root --database=your-db < data.dump.sql

Saturday, February 04, 2017

Friday, February 03, 2017

brew update fails

$ brew update

error: Your local changes to the following files would be overwritten by merge:
README.md
Please, commit your changes or stash them before you can merge.
Aborting
Error: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master

Fix:

cd `brew --prefix`
git remote add origin https://github.com/mxcl/homebrew.git
git fetch origin
git reset --hard origin/master

How to Install Clang on Mac Without XCode

I was getting:

configure: error: clang version 3.0 or later is required

when installing ruby 2.3.3 using rvm. Download the Command Line Tools from here:
http://devimages.apple.com/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg

and install the clang 4.2. I had old 2.1version of clang on my Mac 10.7.5

$ which clang
/usr/bin/clang

clang -v
Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix