Friday, July 17, 2009

Thursday, July 16, 2009

How to replace space with comma in sed

test.txt :

Bugs Bunny
Daffy Duck

cat test.txt | sed -e 's/[ ]/,/g'

outputs:

Bugs, Bunny
Daffy, Duck

cat test.txt | sed -e 's/[ ]/,/g' | sed 's/$/,/'
will append comma to the end as well, so:

Bugs, Bunny,
Daffy, Duck,

Wednesday, March 04, 2009

How to load a specific version of gem

For some reason if you want to use specific version of gem installed on your system:

require 'rubygems'
gem 'activesupport', '=1.4.2'
require 'active_support'

Friday, February 27, 2009

How to check if CRON service is running

You can make sure the cron service is running by running 'sudo /sbin/service crond restart'.

Thursday, February 05, 2009

Tuesday, December 30, 2008

Getting MySQL to work with Rails 2.2.2 on Mac OS 10.5.6

Weird errors: dlsym(0x256ee10, Init_mysql): symbol not found - /usr/local/lib/ruby/gems/1.8/gems/mysql-2.7/lib/mysql.bundle

It turned out I had installed the x86_64 version of MySQL and it does not work with Ruby.

[BLATANT COPY/PASTE BEGIN]
0. In Terminal: ls -l /usr/local ## Showed that mysql was pointing to a PowerPC version instead of i686
1. EXPORT ALL DATABASES FROM CURRENT MYSQL
2. Downloaded MySQL 5.1.30 (I am on OS X 10.4.11 so I used Mac OS X 10.4 (x86))
3. Ran installation package (be sure to see the README first about stopping current server, etc)
4. In Terminal: sudo gem uninstall mysql
5. In Terminal: sudo gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
6. Started up my app's script/server
[BLATANT COPY/PASTE END]

Source: RailsForum

Saturday, December 20, 2008

Captcha in Rails 2.1.2

Simple Captcha plugin by Sur Max works great. Few things that has made life easier:

1. You can now install the RMagick on Linux and Mac OS X using gem install rmagick.
2. Just follow the readme file that comes with the plugin and things will work fine.

It still is in SVN repository. It's ok, just install it.

Thursday, November 20, 2008

Phusion Passenger Enterprise Ruby

If you're using Phusion Passenger (http://www.modrails.com),
and you want it to use Ruby Enterprise Edition, then edit your Apache
configuration file, and change the 'PassengerRuby' option:

PassengerRuby /opt/ruby-enterprise-1.8.6-20080810/bin/ruby

If you ever want to uninstall Ruby Enterprise Edition, simply remove this
directory:

/opt/ruby-enterprise-1.8.6-20080810

Tuesday, November 18, 2008

ssh keys setup - passwordless login from multiple machines

Append id_rsa.pub value in a new line (if there is already another entry) to the ~/.ssh/authorized_keys in the remote machine.

Thursday, November 06, 2008

no such file to load -- mysql (MissingSourceFile)

I followed the Hivelogic tutorial to install MySQL. I was getting that error message when I do:

sudo gem install mysql

To get this to work run:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib --with-mysql-include=/usr/local/mysql/include

[All in one line]

Tuesday, November 04, 2008

WARNING: RubyGems 1.2+ index not found for:

RubyGems will revert to legacy indexes degrading performance.

I was getting this error message while upgrading from Rails 2.1.1 to 2.1.2. Just add github as another gem source.

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

2. sudo gem install rails --version 2.1.2

Monday, November 03, 2008

Rails 2.1.1 Htmldoc 0.2.1 PDF generation

I was getting the error:

NoMethodError (undefined method `size' for false:FalseClass):
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.1.1/lib/action_controller/streaming.rb:123:in
`send_data'

Patch the file :
/usr/local/lib/ruby/gems/1.8/gems/htmldoc-0.2.1/lib/htmldoc.rb

with the following:

result.split("\n").each do |line|
+ line.strip!


Reference:

http://textmode.at/2008/5/14/ruby-htmldoc-gem-falseclass-error

Wednesday, October 29, 2008

Using HTTPS in RESTful authentication Rails 2.1.1

If you get the error message:

ActionController::UnknownAction (No action responded to show):

In the sessions controller make sure you have :

ssl_required :new, :create

This will now enable https when someone logins in to the site. All other details can be easily found via Google.

Monday, October 27, 2008

Tagging in Rails 2.1

I had to migrate from Acts As Taggable on Steroids to Acts As Taggable On plugin to get tagging working Rails 2.1.

One migration issue is that context column that is added by this plugin will be null for old data. It must be set to 'tags' for listing tags for a given model. This will make #tag_list display all the tags for that particular model.

Wednesday, October 01, 2008

Dream Machine

I got my Mac Pro 3.2 GHz 2 processor quad core with 16 GB RAM and RAID enabled 15000 rpm SAS drive on oct 29. I am experimenting with 3 monitor setup, two 30 inch Apple Cinema displays and one Samsung 22 inch display.

Let's see how much productivity I can get from this new setup. Only gripe is the hissing noise of the fan. I don't know if it has to do with the SAS drive. I will post my setup photo on rubyplus.org soon.

Thursday, September 11, 2008

Secret to a Developer's Success

In a interview with LinuxDevCenter.com, Matz was asked the "future plans for Ruby", he replied:

loop do
read and reply mails
write code
write document/article/book
write code
end

I think this is an excellent plan to succeed for a developer who is passionate about software development.

Tuesday, September 09, 2008

Integrate ActiveMerchant With Rails

I read the Integrate ActiveMerchant With Rails recipe in the book Enterprise Rails Recipes by Maik Schmidt. This recipe is basically a recipe for disaster.

In a real web application the user must be taken out of the loop as soon as possible. Having a spinner spining or disabling the button or saying don't click the button is a bad design. Take Amazon for instance the user experience on the site is a good example to follow.

As soon as you create an order, you must set it's initial state and process that order in the background. You can use run rake task using a CRON job that processes the orders. What happens if the Gateway is down? What will you recover from network errors? These things happen in the real world and your software that affect the bottom line must be able to handle it.