Fedora: Install essential packages in Fedora using EasyLife

Posted by Randika on July 25, 2010

easyLife” is an automated installation and configuration tool for Fedora. It’s really helpful for the new linux users (like me), because it helps to install and configure some essential packages with few clicks.

What I like most about easylife is, it supports for the Nvidia driver installation pretty well. Installing the nvidia video drivers on fedora is kind of a nightmare, specially if you don’t know the required dependencies. But easyLife is smart enough to automate all these works. Just try it out yourself.

Download and install the rpm at: http://sourceforge.net/projects/easylife-linux/

Just added the theme package.

now wobble works too :)

How to unzip bz2 files 1

Posted by Randika on June 18, 2010

tar –use-compress-program bzip2 -xvf your-file-name.tar.bz2

Fedora: Accidentally deleted Gnome desktop panels, how to restore?

Posted by Randika on June 15, 2010

I accidentally deleted the entire panels at the bottom and the top of the my fedora Gnome installation. Start menu, the clock, desktop switchers, workspaces and everything are gone now.

After googling for few minutes I found a fix for this. Here is what I did.

[randika@localhost ~]$ mkdir bak
[randika@localhost ~]$ mv -rf {.gnome*,.gconf*} bak/

As you can see I moved (I really don’t recommend deleting configuration files) all the gnome configuration files from my account to another directory named

/home/randika/bak/

then I restarted the OS. Done, now I have the default settings back on my screen.

Ruby on Rails: How to bypass Model validation 3

Posted by Randika on April 09, 2010

In my recent application I have these two models (User, BusinessAccount) with some data validation which works well with their respective controllers.

While keeping these models with their data validation as it is, I wanted to create another Controller (SignupController) which save both model data at once. But  I wanted to bypass the original model validation when saving the data from SignupController.

Here is what I did to achieve it with save_with_validation(perform_validation = false) , hope this will help someone else who looking for the same.

JavaScript: trim() Function

Posted by Randika on February 09, 2010

Where is the trim() function to remove leading and trailing whitespaces of strings? Actually Javascript String object doesn’t natively support it. But there is a workaround for this with regular expressions.

Ruby on rails: how to install ruby 1.8.7 on windows 5

Posted by Randika on January 11, 2010

I couldn’t find the very famous ruby one-click-installer for ruby 1.8.7, after trying various ways I ended up with a solution for this. Here is what I did to get ruby 1.8.7 installed on windows.

First download the ruby 1.8.7 from this link: http://www.ruby-lang.org/en/downloads/ (I took Ruby 1.8.7-p72 Binary)

extract this to c:\ruby (or somewhere else you prefer but avoid using spaces on directories for your own safety)

Now update your PATH environment variable with appending c:\ruby\bin and verify the status of the installation by typing ruby -v in the command line prompt.

C:\Users\Randika>ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-mswin32]

Ok now we need some dependencies packages which doesn’t bundle with ruby 1.8.7

Download libiconv package from here
http://sourceforge.net/projects/gettext/files/
find the libiconv-1.9.1.bin.woe32\bin\iconv.dll and place it inside c:\ruby\bin\

Download zlib package from here
http://www.zlib.net/zlib123-dll.zip
extract it and find the zlib1.dll and place it inside inside c:\ruby\bin\

OK, now we can install rubygems
Get it from here rubygems-1.3.5.zip and extract to wherever you prefer. And then run ruby setup.rb

D:\gems\rubygems-1.3.5>ruby setup.rb

by now gems should be ready to use with. Now you can update gems with

gem update --system

finally install rails

D:\>gem install rails
.....
...
D:\>rails -v
Rails 2.3.5

UPDATE: (20100422)
There is a Release Candidate (RC) of Ruby 1.8.7 (Ruby 1.8.7-p249 (RC2)) at http://rubyinstaller.org/download.htm
You can try that instead of what I have told in this post. Anyway I didn’t try it myself yet.

Most wanted ruby on rails code snippets, tips and tricks

Posted by Randika on November 30, 2009

I keep forgetting all those fancy ruby on rails commands and the important code snippets always. I better keep them documented some where I can find easily. So I’m going to write down as much as code snippets, command lines, tips tricks where I need. Anyway this looks messy as I update this page time to time, hope you also can contribute for the list. I hope this will help someone else too.

How to add/remove new columns to table (models) ?
you can specify columns you want to add/remove in your migration by passing attribute:type pairs to the migration generator command line. here is an example to add the mobile number to existing user model.

[randika@localhost MyApp]$ script/generate migration AddMobileToUser mobile:string

and run the rake db:migrate command. This will create the migration schema for you as:

class AddMobileToUser < ActiveRecord::Migration
  def self.up
    add_column :users, :mobile, :string
  end
 
  def self.down
    remove_column :users, :mobile
  end
end

Similarly when you need to remove a column try using below command, followed by the the rake db:migrate

[randika@localhost MyApp]$ script/generate migration RemoveMobileFromUser mobile:string

How to create dynamic drop down menu from a another model

<%= f.select :country_id, Country.all.collect {|country| [ country.name, country.id ] } %>

this will output:

<select id="country_country_id" name="country[country_id]">
<option value="1">Country A</option>
<option value="2">Country B</option>
<option value="3">Country C</option>
</select>



How to find the configuration settings, versions of the development environment

  • To determine the version of Rails that you are running, you can issue rails -v at a command prompt.
  • $rails -v
  • To determine the Rails installation path type which rails at a command prompt. (only on linux)
  • $which rails
  • To determine the list of gems installed type gem list
  • $gem list



How to print the month name from a month number


Putting this code in a view, will print “December” as the output.

<%= Date::MONTHNAMES[12] %>

How to assign a css class to link_to method in Ruby on Rails

How to install/start mongrel http server

$ sudo gem install mongrel
$ cd yourrailsapp
$ mongrel_rails start -d



How to stop mongrel http server

$ mongrel_rails stop

Cakephp Tips: Routing an Admin dashboard 3

Posted by Randika on September 09, 2009

I had some issues today with the admin routes of my XYZ :) cakephp app. I want the administrator to be able to type domainfoo.bar/admin and be directed to a log in. Then right after the authentication I want them to be redirected to admin_index of  the dashboards_controller (Admin’s Dashboard), So here is what I did for redirection.

1
$this->redirect(array('controller'=>'dashboards','action'=>'admin_index'));

But the problem is that I get the following error:

Private Method in DashboardsController

Error: DashboardsController::admin_index() cannot be accessed directly.

Notice: If you want to customize this error message, create app\views\errors\private_action.ctp

The issue is when using,

1
$this->redirect(array('controller'=>'dashboards','action'=>'admin_index'));

it tries to access the admin_index() function directly which is private as the URL goes domainfoo.bar/dashbords/admin_index

Instead we should set it as:

1
$this->redirect(array('controller'=>'dashboards','action'=>'index','admin'=>true));

or

1
$this->redirect(array('controller'=>'dashboards','action'=>'index','prefix'=>'admin'));

Hope this will help someone one day.

Reusable code blocks in CakePhp 2

Posted by Randika on July 16, 2009

Many web applications has code blocks such as header areas, footer areas, navigation menus that need to be repeated from page to page. In Cake These reusable parts are called Elements. This short tutorial demonstrates how to create and reuse code block in cakephp.

All you needs do first is, find the /app/views/elements/ directory from your cakephp web app and create a new file with the .ctp extension. oh if you are using .thtml as your views extension no matter you can use it.

For this example I’m creating footer block for my cake app. in /app/views/elements/footer.ctp
Then add the codes that requires for the footer in that page.

and from my other views, now i can call for this block as

echo $this->element('footer');

Yeah, It’s that simple. Also you can pass data to an element through the element’s second argument:

echo $this->element('footer', array("var_foo"=>"bar"));

On your element now you can get that variable, as this variable is available as members of the parameter array.

echo $var_foo; //this will print "bar" as the output.

Favorite Quotes

Posted by Randika on July 04, 2009

Here are few quotes that I like, and I’ll update this page constantly when I find more. anyway most of the quotes you find here are computer-related. please contribute to the list by providing your favorite quotes as well.

“To have a great idea, have a lot of them.”
-Thomas Alva Edison

“The value of an idea lies in the using of it.”
- Thomas Alva Edison


“What I hear I forget, what I see I remember, what I do I understand.”

Confucius (Chines philosopher 551 BC – 479 BC)

“There are 10 kinds of people in the world, those that understand binary and those that don’t.”

“Good judgement comes from experience; experience comes from bad judgement.”

“Some people want it to happen, some wish it would happen, others make it happen.”
–Michael Jordan (American professional basketball player (NBA) born February 17, 1963)

“There are two ways of constructing a software design.  One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”
–C.A.R. Hoare

“The function of good software is to make the complex appear to be simple.”
–Grady Booch

“Any fool can use a computer.  Many do.”
–Ted Nelson

“Live as if you were to die tomorrow. Learn as if you were to live forever.”
– Mahatma Gandhi