Thursday, November 27, 2014
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Solution : Install : MySQL Server DMG Installer for Mac OS 10.9.4
An error occurred while installing libv8 (3.11.8.13), and Bundler cannot continue
I was getting that error on Mac 10.9.4. I had to update the gems :
gem 'libv8', '3.16.14.7'
gem 'therubyracer', '~> 0.12.0'
to fix this problem.
Reference : An error occurred while installing libv8 – Mavericks
gem 'libv8', '3.16.14.7'
gem 'therubyracer', '~> 0.12.0'
to fix this problem.
Reference : An error occurred while installing libv8 – Mavericks
Monday, November 24, 2014
Deploying a Rails App on Google App Engine
Deploying a Rails Webapp on GAE should be a piece of cake right? Due to lack of good documentation, it is not that easy. I had to dig around to find the versions of the software installed for Ruby Stack One-Click Deploy.
Here is some useful information to access installed software components.
Apache web server: Configuration directory: /etc/apache2 Default website directory: /var/www Command to start Apache web server: sudo service apache2 start Command to stop Apache web server: sudo service apache2 stop Passenger: Help command: passenger --help Install directory: /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.48 MySQL: Command to access MySQL: mysql -u root -p Command to start MySQL service: sudo service mysql start Command to stop MySQL service: sudo service mysql stop RVM, Ruby and Rails: RVM Help command: rvm Rails help command: rails -h RVM install directory: /usr/local/rvm Ruby install directory: /usr/local/rvm/src/ruby-2.1.1 Rails install directory: /usr/local/rvm/gems/ruby-2.1.1/gems/rails-4.1.4 Git: Help command: git --help
Saturday, November 22, 2014
bin/rails:6: warning: already initialized constant APP_PATH
I was getting this error in Rails 4.2 beta when I started the rails server. Solution: run : rake rails:update:bin from rails project directory.
Tuesday, November 18, 2014
Friday, November 14, 2014
Stripe API Capybara Test Failures
I was getting Stripe::InvalidRequestError: You must supply either a card or a customer id error. To fix this, make sure js is true in your integration test like this:
feature 'Guest Checkout' do
scenario 'Complete purchase of one product', js: true do
visit products_show_path
click_link 'Buy Now'
fill_in "Card Number", with: '4242424242424242'
page.select '10', from: "card_month"
page.select '2029', from: 'card_year'
click_button 'Buy Now'
expect(page).to have_content('Receipt')
end
end
feature 'Guest Checkout' do
scenario 'Complete purchase of one product', js: true do
visit products_show_path
click_link 'Buy Now'
fill_in "Card Number", with: '4242424242424242'
page.select '10', from: "card_month"
page.select '2029', from: 'card_year'
click_button 'Buy Now'
expect(page).to have_content('Receipt')
end
end
Thursday, November 13, 2014
Base Ball Player Statistics
Overview: For this scenario, we have been asked to write an application that will be used to provide information about baseball player statistics. Approach this problem as if it is an application going to production. We don't expect it to be perfect (no production code is), but we also don't want you to hack together a throw-away script. This should be representative of something that you would be comfortable releasing to a production environment. Also, spend whatever amount of time you think is reasonable. If you don't get all the requirements completed, that's ok. Just do the best you can with the time that you have available. You may use whatever gems, frameworks and tools that you think are appropriate, just provide any special setup instructions when you submit your solution.
Assumptions: All requests currently are based on data in the hitting file. Future requests of the system will require data from a pitching file as well. Consider this in the design.
Requirements: When the application is run, use the provided data and calculate the following results and write them to STDOUT.
1) Most improved batting average( hits / at-bats) from 2009 to 2010. Only include players with at least 200 at-bats.
2) Slugging percentage for all players on the Oakland A's (teamID = OAK) in 2007.
3) Who was the AL and NL triple crown winner for 2011 and 2012. If no one won the crown, output "(No winner)"
Formulas:
Batting average = hits / at-bats
Slugging percentage = ((Hits – doubles – triples – home runs) + (2 * doubles) + (3 * triples) + (4 * home runs)) / at-bats
Triple crown winner – The player that had the highest batting average AND the most home runs AND the most RBI in their league. It's unusual for someone to win this, but there was a winner in 2012. “Officially” the batting title (highest league batting average) is based on a minimum of 502 plate appearances. The provided dataset does not include plate appearances. It also does not include walks so plate appearances cannot be calculated. Instead, use a constraint of a minimum of 400 at-bats to determine those eligible for the league batting title.
Data: All the necessary data is available in the two csv files attached:
Batting-07-12.csv – Contains all the batting statistics from 2007-2012.
Column header key:
AB – at-bats
H – hits
2B – doubles
3B – triples
HR – home runs
RBI – runs batted in
Master-small.csv – Contains the demographic data for all baseball players in history through 2012.
Please note: We are looking for you to demonstrate you knowledge related to common software practices to include reusability, portability, and encapsulation – to name a few. Work submitted should be in project form and implemented as you were implementing any production solution.
Tuesday, November 11, 2014
How to share files between Virtual Box Ubuntu with Mac OS host computer
1. Create a folder in your Mac home directory, let's say ubuntu-sf.
2. Install guest additions. Click Devices -> Guest Additions and run the installer.
3. Reboot VM
4. Select the Ubuntu image on VM, go to Settings -> Shared Folders
5. Browse to the folder on your Mac you want to share (ubuntu-sf). Name the shared folder (ubuntu-sf)
6. On Ubuntu terminal, run : sudo adduser your-username vboxsf
7. On Ubuntu terminal run: sudo mount -t vboxsf ubuntu-sf /home/bparanj/ubuntu-sf
Here ubuntu-sf is the name of the shared folder we created in step 5. /home/bparanj/ubuntu-sf is the folder in the
Ubuntu.
References
How to share files between Virtual Box Ubuntu and host computer
How to automatically mount a folder and change ownership from root in virtualbox
2. Install guest additions. Click Devices -> Guest Additions and run the installer.
3. Reboot VM
4. Select the Ubuntu image on VM, go to Settings -> Shared Folders
5. Browse to the folder on your Mac you want to share (ubuntu-sf). Name the shared folder (ubuntu-sf)
6. On Ubuntu terminal, run : sudo adduser your-username vboxsf
7. On Ubuntu terminal run: sudo mount -t vboxsf ubuntu-sf /home/bparanj/ubuntu-sf
Here ubuntu-sf is the name of the shared folder we created in step 5. /home/bparanj/ubuntu-sf is the folder in the
Ubuntu.
References
How to share files between Virtual Box Ubuntu and host computer
How to automatically mount a folder and change ownership from root in virtualbox
some of the partitions you created are too small ubuntu 12.04 LTS Precise Pangolin
I was getting this error during installation of Ubuntu on Virtual Box. Solution: Increase the hard disk size from default 8GB to something higher. It worked for 45GB.
Tuesday, November 04, 2014
How to get web_console working in Rails 4.2.beta4 project
1. Add the gem to Gemfile.
group :development do
gem 'web-console', '2.0.0.beta3'
end
2. bundle
3. You can go to the web console by going to the URL : http://localhost:3000/console
You will also see the web console on the bottom of the browser. You can experiment with the Rails environment loaded.
4. You can add "<%= console %>" to any views and play with the web console.
If you restart the server. You need to reload the page to get a new active console session.
For more details : Web Console Ruby Gem
group :development do
gem 'web-console', '2.0.0.beta3'
end
2. bundle
3. You can go to the web console by going to the URL : http://localhost:3000/console
You will also see the web console on the bottom of the browser. You can experiment with the Rails environment loaded.
4. You can add "<%= console %>" to any views and play with the web console.
If you restart the server. You need to reload the page to get a new active console session.
For more details : Web Console Ruby Gem
Problem installing nokogiri on Mac OS 10.7.5
Problem: Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling.
Solution: bundle config build.nokogiri --use-system-libraries
Then run : bundle
Then run : bundle
libv8 and therubyracer installation problems on Mac OS 10.7.5
The error message is : Make sure that `gem install libv8 -v '3.16.14.7'` succeeds before bundling.
Solution: gem install libv8 -v '3.16.14.7' -- --with-system-v8
Make sure that `gem install therubyracer -v '0.12.1'` succeeds before bundling.
Solution : Change the Gemfile to specify the libv8 version:
gem 'libv8', '3.11.8.13'
and run bundle
Sunday, October 19, 2014
Copy to Clipboard in Linux
1. Install xclip : sudo apt-get install xclip
2. Copy test.txt to clipboard : cat test.txt | xclip
3. Acess the text from the clipboard: xclip -o
Reference:
1. Copy Output of a Command to Clipboard
2. Copy test.txt to clipboard : cat test.txt | xclip
3. Acess the text from the clipboard: xclip -o
Reference:
1. Copy Output of a Command to Clipboard
Wednesday, September 24, 2014
Changing PDF Meta Data in Ruby
According to the home page of pdf-toolkit gem :
pdf-toolkit allows you to access pdf metadata in read-write in a very simple way, through the pdftk commandline tool.
1. Install pdftk version 2.02
$ pdftk -version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2. gem install pdf-toolkit
3. Read or Write pdf meta data.
require 'pdf/toolkit'
pdf = PDF::Toolkit.open('tmux_p3_0.pdf')
#puts pdf.public_methods(false).sort
puts pdf.author
pdf.author='Daffy Duck'
if pdf.save
'PDF meta-data saved successfully'
else
'Failed to save pdf meta-data'
end
# save! to raise exception on failure
puts "after change"
puts "Author"
puts pdf.author
puts 'Title'
puts pdf.title
puts 'Subject'
puts pdf.subject
puts 'Page count'
puts pdf.page_count
puts 'Creator (Publisher)'
puts pdf.creator
puts 'Created At'
puts pdf.created_at
puts 'keywords'
puts pdf.keywords
puts 'producer'
puts pdf.producer
puts 'version'
puts pdf.version
puts 'Updated at'
puts pdf.updated_at
4. Verify the meta-data in Preview -> Tools -> Show Inspector. You will see the author, title, subject, producer, creator, creation date, updated date, number of pages etc.
5. Read the tests in the pdf-toolkit source code to see the available methods.
pdf-toolkit allows you to access pdf metadata in read-write in a very simple way, through the pdftk commandline tool.
1. Install pdftk version 2.02
$ pdftk -version
pdftk 2.02 a Handy Tool for Manipulating PDF Documents
Copyright (c) 2003-13 Steward and Lee, LLC - Please Visit: www.pdftk.com
This is free software; see the source code for copying conditions. There is
NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2. gem install pdf-toolkit
3. Read or Write pdf meta data.
require 'pdf/toolkit'
pdf = PDF::Toolkit.open('tmux_p3_0.pdf')
#puts pdf.public_methods(false).sort
puts pdf.author
pdf.author='Daffy Duck'
if pdf.save
'PDF meta-data saved successfully'
else
'Failed to save pdf meta-data'
end
# save! to raise exception on failure
puts "after change"
puts "Author"
puts pdf.author
puts 'Title'
puts pdf.title
puts 'Subject'
puts pdf.subject
puts 'Page count'
puts pdf.page_count
puts 'Creator (Publisher)'
puts pdf.creator
puts 'Created At'
puts pdf.created_at
puts 'keywords'
puts pdf.keywords
puts 'producer'
puts pdf.producer
puts 'version'
puts pdf.version
puts 'Updated at'
puts pdf.updated_at
4. Verify the meta-data in Preview -> Tools -> Show Inspector. You will see the author, title, subject, producer, creator, creation date, updated date, number of pages etc.
5. Read the tests in the pdf-toolkit source code to see the available methods.
Tuesday, September 23, 2014
Fast Typing, IDE shortcuts, Fast Coding
It does not matter how fast you type in the keyboard, know every short-cut in the IDE, never use the mouse or how fast you can code. Remember : It's garbage in, garbage out.
The quality of software depends on:
1. Quality of your thinking.
2. Learning from your mistakes. Did you learn from your own mistakes?
3. Are you making new mistakes or oblivious and making the same old mistakes over and over again?
4. Are you learning from the mistakes of others to minimize making mistakes in the first place?
5. Are you learning to master the best practices?
6. Are you reading books by : Martin Fowler, Alaister Coburn, Eric Evans, Robert Martin etc? Are you applying it to your projects?
The quality of software depends on:
1. Quality of your thinking.
2. Learning from your mistakes. Did you learn from your own mistakes?
3. Are you making new mistakes or oblivious and making the same old mistakes over and over again?
4. Are you learning from the mistakes of others to minimize making mistakes in the first place?
5. Are you learning to master the best practices?
6. Are you reading books by : Martin Fowler, Alaister Coburn, Eric Evans, Robert Martin etc? Are you applying it to your projects?
Friday, September 19, 2014
wrong number of parameters 2 for in stylesheet_link_tag rails
This error occurs with an ambiguous error message. It does not show the line number of the source where the cause of the problem resides. This happened due to sass-rails dependency on sass gem. Since the sass gem was not declared in the Gemfile, the sass-rails upgraded sass gem to 3.4.4 which broke the application layout. By locking the sass gem to a lower version in the Gemfile:
gem sass, "~ 3.2.1"
The sass-rails picked up this version that works.
gem sass, "~ 3.2.1"
The sass-rails picked up this version that works.
Monday, September 01, 2014
The Scientific Method of Troubleshooting
Notes from the presentation by Blithe Rocher.
Set of Techniques for Acquiring Knowledge.
Methodical
Systematic
1. Define the Problem
Expected behavior
Actual behavior
Criteria for success
2. Do Your Research
Know your environment
Read the literature
Discussions
Make it fail
3. Establish a Hypothesis
4. Design the Experiment
Divide and conquer
Limit the variables
Try something weird
Hierarchy of Blame
4. Gather Data
Current status
Read the error message
5. Analyze Your Results
Problem Solved?
Learn anything?
Understand the Why
Future Experiments
Embrace the Success
6. Keep a Good Lab Notebook
You won't remember
Logs aren't enough
Commit messages
Update the docs
Contribute
Blog it
Share the knowledge
Set of Techniques for Acquiring Knowledge.
Methodical
Systematic
1. Define the Problem
Expected behavior
Actual behavior
Criteria for success
2. Do Your Research
Know your environment
Read the literature
Discussions
Make it fail
3. Establish a Hypothesis
4. Design the Experiment
Divide and conquer
Limit the variables
Try something weird
Hierarchy of Blame
4. Gather Data
Current status
Read the error message
5. Analyze Your Results
Problem Solved?
Learn anything?
Understand the Why
Future Experiments
Embrace the Success
6. Keep a Good Lab Notebook
You won't remember
Logs aren't enough
Commit messages
Update the docs
Contribute
Blog it
Share the knowledge
Friday, August 22, 2014
How to play with ActiveModel validators in the rails console
1. bundle open activemodel
2. Open the validator.rb file.
3. You can see the comments that shows you how to mixin the validators. Once you mixin, you can add any validator and define a dummy method for the attribute to play with it in the irb:
class Person
include ActiveModel::Validations
SSN_REGEX = /your ssn regex goes here/
validates_format_of :ssn, with: SSN_REGEX
def ssn
111-11-1111
end
end
4. Change the ssn method to invalid ssn to test your regex.
2. Open the validator.rb file.
3. You can see the comments that shows you how to mixin the validators. Once you mixin, you can add any validator and define a dummy method for the attribute to play with it in the irb:
class Person
include ActiveModel::Validations
SSN_REGEX = /your ssn regex goes here/
validates_format_of :ssn, with: SSN_REGEX
def ssn
111-11-1111
end
end
4. Change the ssn method to invalid ssn to test your regex.
Thursday, August 21, 2014
How to install Exception Notification gem in Rails 4.1
1. Add the gem to Gemfile:
gem 'exception_notification'
bundle install
2. In config/environments/production.rb:
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier"},
:exception_recipients => %w{exceptions@example.com}
}
3. Configure ActionMailer, in config/environments/production.rb:
I am using Sendgrid SMTP API so:
config.action_mailer.delivery_method = :smtp
If you have sendmail installed on the production server:
config.action_mailer.delivery_method = :sendmail
4. In production.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
gem 'exception_notification'
bundle install
2. In config/environments/production.rb:
Whatever::Application.config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[Whatever] ",
:sender_address => %{"notifier"
:exception_recipients => %w{exceptions@example.com}
}
3. Configure ActionMailer, in config/environments/production.rb:
I am using Sendgrid SMTP API so:
config.action_mailer.delivery_method = :smtp
If you have sendmail installed on the production server:
config.action_mailer.delivery_method = :sendmail
4. In production.rb:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
Subscribe to:
Posts (Atom)