Archive

Archive for April, 2011

RubyOnRails(RoR) on Ubuntu 10.10

April 14, 2011 Leave a comment

Recently I had installed RubyOnRails on Ubuntu 10.10. If you are a beginner, you would find very much confusing to understand why those components were required in the first place.All we need is just couple of commands as below to get RoR application up and running!

sudo apt-get install ruby
sudo apt-get install gems
sudo gem install rails
mkdir <Application Directory Path>

rails new <Application Directory Path>
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby
cd <Application Directory Path>

rails server

Installed Versions:
Ruby 1.8.7
RubyGems 1.3.7
Rails 3.0.6

Here are some tips and observations :

(1) Tried to install with ‘sudo gem install rails’ and it gave ‘File not found: lib’ error
$ sudo gem install rails
Successfully installed rails-3.0.6
1 gem installed
Installing ri documentation for rails-3.0.6…
File not found :lib

Solution:
sudo gem install rdoc-data
sudo gem rdoc –all –overwrite
Then run ‘sudo gem install rails’.

(2) sudo gem install rails hangs or takes too much time
When I ran the command, it seems like it was hanging, but apparently it came back with successful installation. So even though it seems like taking too much time, hang in there.

$ sudo gem install rails
Successfully installed rails-3.0.6
1 gem installed
Installing ri documentation for rails-3.0.6…
Installing RDoc documentation for rails-3.0.6…

(3) Dont forget to add the GEM path to PATH
$ gem env
RubyGems Environment:
– RUBYGEMS VERSION: 1.3.7
– RUBY VERSION: 1.8.7 (2010-06-23 patchlevel 299) [i686-linux]
– INSTALLATION DIRECTORY: /var/lib/gems/1.8
– RUBY EXECUTABLE: /usr/bin/ruby1.8
– EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
– RUBYGEMS PLATFORMS:
– ruby
– x86-linux
– GEM PATHS:
     – /var/lib/gems/1.8
– /home/testuser/.gem/ruby/1.8
– GEM CONFIGURATION:
– :update_sources => true
– :verbose => true
– :benchmark => false
– :backtrace => false
– :bulk_threshold => 1000
– REMOTE SOURCES:

$ export PATH = $PATH:/var/lib/gems/1.8/bin
(4) ‘Could not find sqlite3’ error while running “rails server” even after trying to install using sudo gem install sqlite3
$ rails server
Could not find gem ‘sqlite3 (>= 0, runtime)’ in any of the gem sources listed in your Gemfile.

Solution:
sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install sqlite3-ruby

Good Resource Link is here!.

Ubuntu 10.10 on Oracle VM VirtualBox 4.0.4 – Quick Tips

April 4, 2011 Leave a comment

Ubuntu 10.10 has tons of new built-in features with better look and feel, so if you’re using older versions, its  worth to upgrade.

If you have not installed or worked much in Ubuntu before, here are some quick tips… Here you go!
 
(1) How to make Ubuntu Full Screen?
(2) How to add new users in Ubuntu?
(3) How to install Perl Modules through CPAN on Ubuntu?

How to make Ubuntu Full Screen?

If you google it, many posts may come up, but this link I found to be more simple and straightforward! When you install “VirtualBox Guest Additions” following those steps and restart the VirtualBox, automatically you would see the screen becoming fullscreen in Ubuntu.

Go to Top

How to add new users in Ubuntu?

admin@ubuntu-VirtualBox:/$ sudo adduser ubuntu_user
Adding user `ubuntu_user’ …
Adding new group `ubuntu_user’ (1001) …
Adding new user `ubuntu_user’ (1001) with group `ubuntu_user’ …
Creating home directory `/home/ubuntu_user’ …
Copying files from `/etc/skel’ …
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for ubuntu_user
Enter the new value, or press ENTER for the default
Full Name []: Ubuntu User
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y

Go to Top

How to install Perl Modules through CPAN on Ubuntu ?

(1) Run sudo  apt-get install build-essential in ubuntu terminal to install all required packages for CPAN
(2) Run perl -MCPAN -e shell to invoke cpan command
(3) Now you can install any perl module using cpan> install < Module name >

(A) Installing CGI::Application Framework on Ubuntu

You can either install through CPAN or installing the package libcgi-application-plugins-perl as below.

admin@ubuntu-VirtualBox:~/cgi-bin$ sudo apt-get install libcgi-application-plugins-perl
[sudo] password for admin:
Reading package lists… Done
Building dependency tree
Reading state information… Done
…….

Go to Top

Categories: Ubuntu Tags: , , ,

How to search for pattern in a file and remove the previous 2 lines including the line with pattern ?

April 4, 2011 Leave a comment

How to search for the pattern in a file and remove the previous 2 lines including the line with pattern ?

#!/usr/local/bin/perl

my @buffer;
while ( ) {
if (!/pattern/) {
push @buffer, $_;
} else {
push @buffer, $_;
delete @buffer[-3..-1]; ## Remove 2 lines above including pattern!
}
}
print @buffer;

Categories: Perl, Perl - Examples Tags: ,

Perl Frameworks

April 4, 2011 Leave a comment

What’s the best way to write a CGI application in Perl?
Absolute answer is, using Perl Framework. There are many frameworks available with or without MVC architecture empowered. You can get a list with comparison in this link.

My personal choice is to go with CGI::Application since its very light-weight and easily maintainable. Templates can be designed using amazing perl module called HTML::Template. I found this framework magical mainly for AJAX calls using jQuery along with CGI-Application-Plugin-AutoRunmode module.
If you have existing perl code using CGI::Application and want to migrate the same to mod_perl environment, there is a CPAN module (CGI::Application::Plugin::Apache) available to do so.

You can refer to this tutorial to start using the CGI::Application. Enjoy coding!