mysqldump multiple/selected tables

June 23, 2009 at 4:27 am (mysql) (, , , , )

This post explains how to dump selected tables only.
The actual syntax being:

So, to dump the entire database use,

To dump only selected tables use,

Permalink 1 Comment

Mysql gem installation fix in rails

June 18, 2009 at 8:00 am (Uncategorized)

Today when i was trying to install mysql gem on the rails 2.2.2 + ruby 1.8.6 + gem 1.2.0 on FEDORA, i had the following error:
Building native extensions. This could take a while…
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb install mysql — —with-mysql-config=/usr/local/mysql/bin/mysql_config
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… yes
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.7/gem_make.out
ERROR: could not find gem — locally or in a repository
ERROR: could not find gem —with-mysql-config=/usr/local/mysql/bin/mysql_config locally or in a repository


The fix for it is:
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config

Tats it. Its working fine for me.
Hope it works 4 oder folks too.

If not, it means that a library called mysql-devel is missing.

So, install it by “sudo yum install mysql-devel” or “sudo apt-get install libmysql++-dev”
And then, install the mysql-gem. This should for sure fix it.

For further info, checkout: Rails Mysql wiki

Permalink Leave a Comment

Making python widgets work in KDE

June 17, 2009 at 1:38 pm (Uncategorized) (, , , , )

Today i have installed KDE on my fedora machine and am having all d fun at its UI and sexy look.
Every love story has an obvious villain, and in my case when i was installing some WIDGETS, especially python based, like:
1) Now do this
2) Gmail Notifier
I had this error:
missing python script-engine errors.
On looking around the web, i could this solution:
All u gotta do is : yum install kdebase-workspace-python-applet
Daz it.

For other Linux-flavours, the solutions are available at : KDE-LOOK

Permalink Leave a Comment

Undefining class at runtime

June 16, 2009 at 6:58 am (Model) (, , , , , , , )

This post explains undefining the class at runtime.

Im not gonna explain the live-cases where this might be used. Ask Uncle Google for that.

Lets jump in at d code directly.

When u create a new class, say “Person”, two things happen:

  1. A new object of type(class) Class is instantiated.
  2. A new constant called Person will be instantiated and will hold the value of the class-object created above.

Proof: Class Person;end;

Try, Person.class #=> Class. This means that the Person holds a value which is of class Class. (1 is proved).

Try, Person = 123 #=> Curses saying, Person is already initialized, which means Person is a constant. (2 is proved).

Now, All the constants(Person) and other are silently ducked into the class Object.

Proof: Object.class_eval{Person} #=> Person Class

So, we should understand by now that the newly created class Person resides as a constant of the class Object.

So if we could somehow remove that constant, then the class Person will also be removed.

There is a method called remove_const for the class Object.

So, try Object.remove_const : Person #=> Curses, NoMethodError: private method `remove_const’ called for Object:Class

This is becoz, remove_const is a private method of Object class.

So the worry now is, how to invoke a private method.

We have two solutions:

  1. Object.send(:remove_const , : Person)
  2. Object.class_eval{remove_const : Person}

Now try, # Curses, uninitialized constant Person

Voila, job done. Very rarely does an ERROR MESSAGE makes us feel happy. Well, kind of an article.

You can learn much about class_eval from this very good article by Khaled.

Permalink Leave a Comment

add attribute at runtime

June 16, 2009 at 6:23 am (Model) (, , , , , , )

I’m all excited abt this post.

Coz this is something i learnt just now, and consider it my best learning till now in RUBY.

Q: How to add attributes to a class at runtime?


class Class
def new_attr (attr_name)

class_eval {attr_accessor :"#{attr_name}"}

class_eval : Evaluates a string or a block in the context of the receiver, here the class.


1) We defined a new method to the CLASS called new_attr, which is intended to add new attributes at runtime.

2) This method needs the name of the new attribute to be passed.

3) In the definition, it calls class_eval, which means “DO SOMETHING AT THE CLASS LEVEL”

4) What to do is specified in the block after the class_eval, which says : attr_accessor “#{attr_name}”, which will become attr_accessor :name when we call new_attr(‘name’).

5) We know that attr_accessor is rails syntactic sugar to create the a specific instance variable, and its set/get (read/write) methods. So here, when we call new_attr(‘name’), its creating a new instance variable (@name) and 2 new methods ‘name” and “name=”.

Try this;

class Person; end;

This creates a bare class Person.

p =

Try,, it throws an error cursing “Undefined method name”.

Its fairly expected coz, Person has no attribute called name.

Now, say Person.new_attr(‘name’)

now try,, it will not curse you.

To check, try Person.singleton_methods.include?(“name”)

This says TRUE.

Hope this article comes handy.

Permalink 1 Comment