Archive

Monthly Archives: March 2011

You can recover MySQL database server password with following five easy steps.
Step # 1: Stop the MySQL server process.

# sudo /etc/init.d/mysql stop

Step # 2: Start the MySQL (mysqld) server/daemon process with the –skip-grant-tables option so that it will not prompt for password.

# sudo mysqld_safe –skip-grant-tables &

Step # 3: Connect to mysql server as the root user.

# mysql -u root

Step # 4: Setup new mysql root account password i.e. reset mysql password.

mysql> use mysql;
mysql> update user set password=PASSWORD(“NEW-ROOT-PASSWORD”) where User=’root’;
mysql> flush privileges;
mysql> quit

Step # 5: Exit and restart the MySQL server.

# sudo /etc/init.d/mysql stop

# sudo /etc/init.d/mysql start
# mysql -u root -p

Web fonts allow you to step outside of the normal web-safe fonts by taking advantage of CSS’s @font-face rule. However, right now, browsers aren’t uniform in its implementation of @font-face. More specifically, web browsers differ in the types of font files they support (hopefully this will change with the WOFF standards). Additionally, you must be careful with the fonts you use since some of them might not be licensed for web use.

To sidestep the issues with @font-face, the Google Font API is here to the rescue. Here is an example of using the Cantarell font on elements that takes advantage of Google Fonts API. If you want to use the Cantarell font from Google Font API, first reference the remote stylesheet inside your tags as such:

href=”http://fonts.googleapis.com/css?family=Cantarell”

To use the font in h1 elements, simply use the font-family CSS property.

h1 {
font-family: ‘Cantarell’, Arial, serif;  /* Use a font stack, just in case. */
}

Loading data into Database reading from multiple files was never easy. I have been working on different projects lately, which required such exercise often. A general technique I followed to do that is explained here. In a gist, this is what it looks like:

require 'rubygems'
require 'fastercsv'

files.each do |key, value|
	file = "#{RAILS_ROOT}/db/drugsatfda/" + key
	recs = 0

	puts "Working with #{value.pluralize}.."
	FasterCSV.foreach(file, :headers => true) do |row|
		begin
			obj = value.constantize.new(Array.to_hash(row.headers, row.fields))
			obj.save

			recs += 1
		rescue => e
			puts "Rows processed: " + recs.to_s
			puts e
		end
	end
	puts "Loaded #{recs} #{value.pluralize}"
end

What do you think?