Tuesday, July 27, 2010

undefined method `visit' for cucumber

Fix: Include the following configuration in features/support/env.rb

require 'webrat'
require 'webrat/core/matchers'

Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end

World(Webrat::Methods)
World(Webrat::Matchers)

This also fixes the error : "no such file to load -- action_controller/integration"

Saturday, July 24, 2010

Getting RSpec Book Rails app working on Rails 3.0 Beta 4

1. Create a new Rails app called blog, skip test unit since we will be using RSpec
rails new blog --skip-testunit

2. Edit gem file :

group :test do
gem 'rspec-rails', '>= 2.0.0.beta.10'
gem 'webrat'
gem 'selenium-client'
gem 'database_cleaner'
gem 'rspec-rails'
gem 'cucumber'
gem 'cucumber-rails'
gem 'rspec'
end

3. From app's root directory, run:

bundle install

4. rails g rspec:install

5. rails g cucumber:install

6. rails g cucumber:skeleton --rspec --webrat

7. rails g cucumber:feature

8. script/cucumber --tag @focus

9. script/cucumber -t @focus

10. rails g model movie showtime_date:date showtime_time:time
11. rake db:migrate
12. rake db:test:prepare
13. cucumber -t @focus
14. cucumber

Reference:

Rails 3, RSpec, and Cucumber

Monday, July 19, 2010

How to add a source to Ruby gems

gem sources -a http://gems.github.com

To remove a source:

gem sources -r http://gems.github.com

Run:
gem env

to see the sources that is currently in your Ruby gems.

Monday, July 12, 2010

Extremely Simple Alternative to AutoTest

I am reading the Rails 3 in Action by Yehuda. To run the sample code I customized the stakeout.rb to output the results of the test when specs get run whenever the file is changed.

1. Copy the source to a directory that is in your path:

#!/usr/bin/env ruby
if ARGV.size < 2
puts "Usage: stakeout.rb [files to watch]+"
exit 1
end

command = ARGV.shift
files = {}

ARGV.each do |arg|
Dir[arg].each { |file|
files[file] = File.mtime(file)
}
end

loop do

sleep 1

changed_file, last_changed = files.find { |file, last_changed|
File.mtime(file) > last_changed
}

if changed_file
files[changed_file] = File.mtime(changed_file)
puts "=> #{changed_file} changed, running #{command}"
puts system(command)
puts "=> done"
end

end

2. chmod +x stakeout.rb

3. To run:

stakeout.rb "spec bacon_spec.rb" **/*

This will run the spec called back_spec.rb whenever any files found recursively from the current file is changed.

Reference:

Faster TDD with Stakeout.rb

Problem Installing Sqlite3-ruby on Snow Leopard

I was getting this error when I started the server. I had installed RVM, Ruby 1.9.1, Rails 3.0 Beta 4:

.rvm/gems/ruby-1.9.1-p378/gems/sqlite3-ruby-1.3.1/lib/sqlite3/sqlite3_native.bundle: dlopen(.rvm/gems/ruby-1.9.1-p378/gems/sqlite3-ruby-1.3.1/lib/sqlite3/sqlite3_native.bundle, 9): no suitable image found. Did find: (LoadError)
.rvm/gems/ruby-1.9.1-p378/gems/sqlite3-ruby-1.3.1/lib/sqlite3/sqlite3_native.bundle: mach-o, but wrong architecture - .rvm/gems/ruby-1.9.1-p378/gems/sqlite3-ruby-1.3.1
/lib/sqlite3/sqlite3_native.bundle


Resolution:

Uninstall sqlite3-ruby (1.3.1)
1. gem uninstall sqlite3-ruby

Install sqlite3-ruby version 1.2.5
2. gem install sqlite3-ruby --version 1.2.5

If you get the error:

no such file to load -- sqlite3

when running rake db:migrate

Edit the Gemfile for the line sqlite3-ruby as :

gem 'sqlite3-ruby', :require => 'sqlite3'

Installing Ruby 1.9.2 using RVM on Snow Leopard

When I tried to install Ruby 1.9.2
rvm install 1.9.2

I got :

error: Error running 'make ', please check /Users/bparanj/.rvm/log/ruby-1.9.2-rc2/make*.log
error: There has been an error while running make. Aborting the installation.

Steps to Resolve :

1. Install libxml

curl -O ftp://xmlsoft.org/libxml2/libxml2-2.7.7.tar.gz
tar zxvf libxml2-2.7.7.tar.gz
cd libxml2-2.7.7
./configure --with-python=/System/Library/Frameworks/Python.framework/Versions/2.3/
make &
sudo make install

2. Install libxslt

curl -O ftp://xmlsoft.org/libxslt/libxslt-1.1.26.tar.gz
tar xvzf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure
make
sudo make install

3.
rvm install 1.9.2-head -C --enable-shared,--with-readline-dir=/opt/local,--build=x86_64-apple-darwin10

Reference:

Installing Ruby 1.9.2 with RVM on Snow Leopard

Tips:

#1 :
rvm 1.9.2-head --default

to make it 1.9.2 when you open new terminal or after reboot.

#2 :
To revert to system installed Ruby:

rvm system --default

Thursday, July 08, 2010

uninitialized constant Mysql while running rake db:create

1. Uninstall the mysql gem

bparanj$ sudo gem uninstall mysql

Successfully uninstalled mysql-2.8.1

2. Installing the gem the right way on Snow Leopard
bparanj$ sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed

3. Edit the gemfile and include the line:

gem 'mysql'

4. Run bundle install from the rails project directory:

mbp2:blog bparanj$ bundle install
Fetching source index from http://rubygems.org/
Using rake (0.8.7) from system gems
Using abstract (1.0.0) from system gems
Using activesupport (3.0.0.beta4) from system gems
Using builder (2.1.2) from system gems
Using i18n (0.4.1) from system gems
Using activemodel (3.0.0.beta4) from system gems
Using erubis (2.6.6) from bundler gems
Using rack (1.1.0) from bundler gems
Using rack-mount (0.6.6) from system gems
Using rack-test (0.5.4) from system gems
Using tzinfo (0.3.22) from system gems
Using actionpack (3.0.0.beta4) from system gems
Using mime-types (1.16) from system gems
Using polyglot (0.3.1) from system gems
Using treetop (1.4.8) from system gems
Using mail (2.2.5) from system gems
Using actionmailer (3.0.0.beta4) from system gems
Using arel (0.4.0) from system gems
Using activerecord (3.0.0.beta4) from system gems
Using activeresource (3.0.0.beta4) from system gems
Using bundler (0.9.26) from system gems
Using mysql (2.8.1) from system gems
Using thor (0.13.7) from bundler gems
Using railties (3.0.0.beta4) from system gems
Using rails (3.0.0.beta4) from system gems
Using sqlite3-ruby (1.3.0) from bundler gems
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

5. rake db:create will now work
mbp2:blog bparanj$ rake db:create
(in /Users/bparanj/projects/blog)
db/test.sqlite3 already exists

Friday, June 25, 2010

Include Vs Extend in Ruby

Include vs Extend

Include

Classes and modules can include modules and reuse the methods defined in the module. The method in the module is available as an instance method. The constants, methods and module variables are available once the module is mixed in.

Extend

You can extend an instance of any class with module. The method in the module is available as an instance method.

The difference is extend is only applicable for that particular instance which was extended. Where as the include is applicable to any instance of the class.

Screen cast IncludeExtend.mov

Addition to IncludeExtendRuby.mov

module Talkable
def talk
p "hi"
end
end

class Foo

end

Foo.extend Talkable

Foo.talk


If extend is used on the class instead of the object, the method becomes available as class method. The extend can be used inside the class or outside the class. Refer the screencast to see how it works.

Thursday, June 24, 2010

Upgrading Snow Leopard to Rails 3.0 Beta 4

1. gem env

should be 1.3.6 or above

2. gem update --system

Update Ruby gems to the latest version

3. sudo gem install i18n tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n bundler

Install required gems for Rails 3.0

4. sudo gem install rails --pre

Installs Rails 3.0 Beta 4

5. sudo mkdir /usr/local/lib/ruby/gems/1.9.1/gems/rails-3.0.0.beta4/lib

Create the lib directory to resolve the following error

ERROR: While executing gem ... (Errno::ENOENT)
No such file or directory - lib

Installing Ruby 1.9.2 on Snow Leopard

1)

Install Readline:

curl -O ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz
tar -xvzf readline-6.0.tar.gz
cd readline-6.0
./configure --prefix=/usr/local
make
sudo make install

I ignored the message: install: you may need to run ldconfig

2)

Install Ruby 1.9.2

curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-rc1.tar.gz
tar -xvzf ruby-1.9.2-rc1.tar.gz
cd ruby-1.9.2-rc1
./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local --enable-shared
make
sudo make install
sudo make install-doc


I ignored the message: configure: WARNING: unrecognized options: --with-readline-dir

3) Update ~/.bash_profile with
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

in the last line

Open a new window and check Ruby version: ruby -v
ruby 1.9.2dev (2010-07-02 revision 28524) [x86_64-darwin10.4.0]

Wednesday, May 05, 2010

Tracking Referrals

From Google Analytics Tracking for Mobile Apps page:

The Android 1.6 OS release supports the use of a referrer URL parameter in download links to the Android Market. The Google Analytics SDK for Android uses this parameter to automatically populate referral/campaign information in Google Analytics for your application. This enables the source of the application install to be recorded and associated with future pageviews and events.

When is Steve going to provide this feature to developers for iPhone OS?

Thursday, April 22, 2010

How to convert .wav to .mp3

Use iTunes to import the .wav files. Go to preferences and change Import Settings -> Import Using to MP3 Encoder. Select all the .wav files to convert to .mp3 and go to Advanced -> Create mp3 version. Now just select one of the .wav file and go to "File -> Show in Finder", you will find all the converted mp3 files in the same folder.

You have to use iTunes to convert because the command line tool afconvert does not have the ability to convert to mp3.You will get the error Error: ExtAudioFileSetProperty ('cfmt') failed ('fmt?')

Tuesday, April 20, 2010

How to view only starred emails in Gmail

Type the following in the search box and hit search:

in:Starred in:Inbox

Migraine leaves British woman speaking with Chinese accent

"I spoke to my stepdaughter on the phone from hospital and she didn't recognize who I was. She said I sounded Chinese. Since then, I have had my friends hanging up on me because they think I'm a hoax caller ... The first few weeks of the accent was quite funny, but to think I am stuck with this Chinese accent is getting me down. My voice has started to annoy me now. It is not my voice."

Learn to speak in British Accent iPhone app:

More at National Post

Monday, April 12, 2010

How to reduce caf file size

afconvert -f caff -d LEI16@22100 -c 1 ./test.mp3 ./test.caf

I kept reducing the sampling rate from 44100 to 13100. Anything below 22100 seems to affect the quality of the audio.

You can also convert a caf file with a given sampling rate to another caf file with different sampling rate:

afconvert -f caff -d LEI16@22100 -c 1 ./test.caf ./test2.caf

Tuesday, April 06, 2010

Analyzing Your App Store Sales Statistics - Part II

AppStore Sales Vs AppViz

Clearly AppViz is the winner. Provides nice charts and downloads 13 weeks of data to your desktop and provides a clear interface.

Heartbeat Signed up for this site. After I login I don't see anything. Not easy to use or figure out how to generate reports. It takes too much time than it saves. If you have a different opinion do let me know.

Tap Mini from TapMetrics. I watched the demo. It seems to allow import. I don't like the drilling into different levels to view my data.

4 ways to capitalize on Google's real-time search results

Following tips to be tested for iPhone / iPad apps that is already in the app store.

From iMedia Connection:

To take advantage of the new real-time search results -- and minimize any potential negatives -- here are four fundamental steps for marketers:

* Keep positive messages about your brand or products alive in the online news media. Issue frequent press releases with positive news about your company and create positive viral content related to your brand or product that has the potential to be mentioned frequently on popular social networking sites and even featured in news stories.


* Be active on sites like Twitter, Facebook, MySpace, FriendFeed, Jaiku, and Identi.ca. Create positive messages about your brand or products in the online social media sites likely to appear in Google results. Promote positive news stories published on mainstream news sites that result from your press releases or viral content promotions, as well as positive viral content that you created yourself.


* Maintain an active presence in social networking and microblogging sites. Cultivate relationships and interact with influential users to enlist their help in spreading your positive message. In addition, be responsive to both positive and negative mentions of your brand or product to mitigate any negative press that may occur. (Note: This is not a job for an intern. Ensure you are represented on these sites by a professional with social media and public relations savvy.)


* Closely monitor news and real-time buzz sites for mentions of your brand or product so you can react if necessary. That means setting up accounts with Google Alerts, Yahoo Keyword News Alert, and Twitter Alerts and following them.

Monday, April 05, 2010

Analyzing Your App Store Sales Statistics

App Figures provides reporting of app sales. The graphing does not update when you change the period. Emailed the tech support. No progress has been made after a week. I do like the daily and weekly report email feature. I can set up so that all my partners get the reports emailed. The pricing seems to be reasonable: $5 / mo for 2 apps. $1.5 for each additional app that you want to track. It provides ranking of your app also.

App Sales Mobile This is available on Github. I downloaded it and ran it on Simulator. Not bad for something that is free. Nice charts and reports.

My App Sales I paid $27.70 (20 Euros) for this today. It's ok. It has lot more features. Provides data export and the option of creating html reports. I had to save the instruction to try the advanced features. The advanced features are not just one click from the app.

Friday, April 02, 2010

How to use Active Support Rails library in Ruby scripts

#!/usr/bin/ruby
require 'rubygems'
require 'active_support/inflector'

puts Inflector.singularize('inflections')

Thursday, April 01, 2010

British Accent Training iPad App is now live!

The first Accent Reduction training iPad app in the app store. British Accent Training is a great tool to help you learn British Accent. You can practice your accent, pronunciation and intonation.

Taught by a native British English speaker Alison Pitman. It gives you enough time to record, playback and to repeat the lesson.

The best solution is to practice with a computer. I tried a simple sound recorder on a computer as well as a tape recorder, and it did not work - too complicated, involves too much button pressing.

You need a program which plays a phrase, then records you repeating it, then repeats the native speaker, then plays your recording, and does it all over again in a loop until you are satisfied.

You can hear your mistakes and you feel that you are correcting them.

This training will allow you to record and hear your own voice. Record your voice every week you use the training to see the transformation in your accent.

The app demonstrates each pronunciation with practice words and sentences which are simple and easily understood. More content will be added in later releases. If you buy at current price you will get updates for free. When more content is included the price will go up. BUY NOW.