Monday, October 29, 2012

Rails Error: Unable to access log file. Please ensure that


log/development.log exists and is chmod 0666. The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.

Resolution: 

Change the line : config.log_level = Logger::INFO
    to : config.log_level = :info
in development.rb, production.rb etc.

Tuesday, October 23, 2012

constant ActiveSupport::Dependencies::Mutex (NameError)


Problem:
.rvm/gems/ruby-1.8.7-p299@global/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:55: uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

Ruby gems version 1.8.14

Resolution:

Downgrade gems. gem update --system 1.5.3

Friday, October 19, 2012

The following SSH command responded with a non-zero exit status.


Problem:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` v-root /vagrant

Resolution:

1. On your Mac:
$ vagrant gem install vagrant-vbguest
Since I installed Vagrant as a package (dmg) otherwise do : gem install vagrant-vbguest
2. vagrant up

The gem will automatically install the update. If VM is already running just do : vagrant halt

Reference:

Automatically download and install VirtualBox guest additions in Vagrant

Move to the end of the file in vi


$ then A

Monday, October 15, 2012

Upgrading GIT on Ubuntu 10.04


  • sudo add-apt-repository ppa:git-core/ppa
  • sudo apt-get update
  • sudo apt-get install git
Notes from stackoverflow. This works.

Thursday, October 04, 2012

Testing Cookies

Notes from Rails Cookbook:

To fully test cookies, you need to test that your application is not only setting the cookies, but also correctly reading them when passed in with a request. To do that create Cookie object and add that to the simulated test Request object, which is setup before every test in the setup method.

Rails cookie tests : https://github.com/rails/rails/blob/master/actionpack/test/dispatch/cookies_test.rb

Securing Your Server by Closing Unnecessary Ports

I am getting rid of Rails Cookbook dead tree copy I bought in 2007. Notes that are valid for any Rails version.

$ netstat -an

will list all network daemons and the ports they are listening on. This will not show you the service name. To find out do:

$ less /etc/services

This will list the service name and the port number it is running. Diable the service based on your Linux flavor and reboot server to make sure it does not get restarted automatically on reboot.

Debugging Rails Applications

Notes from Rails Cookbook. Since the book is based on Rails 1.2 only some of the recipes are still applicable to Rails 3.2.

1. Ruby syntax checker:
     $ ruby -cw test.rb
        w - warn about questionable code
        c - check syntax

       In vim you can check the syntax quickly while editing by doing:
        :w !ruby -cw

2.  Dump environment info in views:
     <%= debug(headers) %>
     <%= debug(params) %>
     <%= debug(request) %>
     <%= debug(response) %>
     <%= debug(session) %>
     <%= debug(request.env) %>

3. Use rails any_object.to_yaml in your controller's action method.

4. Filter development logs:
    logger.warn "### something went wrong: #{obj.inspect}"

    Show only messages beginning with ### :
    $ tail -f log/development.log | grep "^###"

   This tip combined with Tagged logging feature in Rails 3.2 is powerful debugging tool.

5. Use Firebug console tab to inspect the client server interaction when making AJAX calls.

6. Use Live HTTP Headers to inspect HTTP traffic.


Saturday, September 29, 2012

Solving Programming Problems

1. Write down your question.
       This makes you think and clarify your thoughts.
2. Design an experiment to answer that question.
       Keep the variables to a minimum so that you can solve the problem easily.
3. Run the experiment to learn.

Wednesday, August 29, 2012

Eliminating if else statement using Blocks in Ruby


def foo(a)
  if a == 1
    yield
  else
    42
  end
end

The above method customizes by using a block like this:

result = foo(1) do
  98
end

p result

Wednesday, August 22, 2012

How to stop continuous running fan in MacBook Pro

My MacBook Pro with 8 GB 1067 MHz DDR3 RAM and 3.06 GHz Intel Core 2 Duo was running the fan continuously for couple of weeks. To fix it, I ran:

$ top

in the terminal. I found two ruby processes had been running for 160 hours continuously and were taking up 93% of the CPU usage. I killed them by doing:

$ kill -9 [process-id]

As soon as those two stray processes were killed, laptop became quiet again.


How to install tmux 1.6 on Mac OS

I was having difficulty installing the version 1.6, the older 1.4 version was being picked up. The fix:

1. /opt/bin should be in the path. You can append this to your path by editing the ~/.profile file. Mine looks like this:

##
# Your previous /Users/bparanj/.profile file was backed up as /Users/bparanj/.profile.macports-saved_2010-06-07_at_22:52:52
##

# MacPorts Installer addition on 2010-06-07_at_22:52:52: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:/opt/bin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

2. curl -OL http://downloads.sourceforge.net/project/levent/libevent/libevent-2.0/libevent-2.0.19-stable.tar.gz

3. tar xzf libevent-2.0.19-stable.tar.gz

4. cd libevent-2.0.19-stable

5. ./configure --prefix=/opt

6. make

7. sudo make install

8. tar xzf tmux-1.6

9. cd tmux-1.6

10. LDFLAGS="-L/opt/lib" CPPFLAGS="-I/opt/include" LIBS="-lresolv" ./configure --prefix=/opt

11. make && sudo make install

12 which tmux 

showed that the older 1.4 version was being picked up from /opt/local/bin, I deleted it by : sudo rm /opt/local/bin/tmux


How to check tmux version

$ tmux -V

Saturday, August 11, 2012

Rails 3.2 Errno::EACCES Permission Denied when uploading files

1. Make sure the directory has the right permission:

   chmod -R 777 uploads

2. The uploads directory is at the same level as app directory. You can change the upload location from the public folder to any folder by customizing the store_dir in your uploader class:


 def store_dir
     "#{Rails.root}/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

3. You also have to define cache_dir in your uploader class, otherwise it will still throw exception.


  def cache_dir
    "#{Rails.root}/tmp/uploads/cache/#{model.id}"
  end


Monday, July 16, 2012

Error: This transaction cannot be processed due to an invalid merchant configuration.

ActiveMerchant 1.26, Rails 3.2

Resolution:


1. Create your selling test account using the Preconfigured option.
2. Under Account Type, select Website Payments Pro.
3. My Account --> Profile --> API access to get API username, API Password and Signature

Remember the API credentials are different from the test login account. You have to save the login password to the Sandbox account in Step 1 above. There is no way to go back and view the login password to the Sandbox account.

Sunday, July 08, 2012

remove github prompt when checkin

Change the url that has https to :


url = git@github.com:your_github_username/your_project.git

Saturday, June 23, 2012

TDD Screencasts by Kent Beck

1. Test for remove operation does not fail. He writes a test and does not run it, he goes to the implementation and implements. Then he runs the test and it passes.
2. Interesting to see how he uses the debugger to learn about the API and uses that information to write a test.

Wednesday, June 06, 2012

github push is prompting for username and password

I was getting this error for https://github.com/bparanj/mongodb_specs repo. Fix :


$git config remote.origin.url git@github.com:bparanj/mongodb_specs.git