Tuesday, May 05, 2009

Save Webpage as image or PDF

Do you want a full snapshot of a webpage you are visiting as an image or as a PDF file? Here is a firefox addon which helps you with that.

https://addons.mozilla.org/en-US/firefox/addon/7528

Here are the options it supports.



I tried it on one of my websites and I'm impressed with the results. Good tool if you ever want to print your website on paper for promotional purposes!

Monday, May 04, 2009

Renaming mysql database

Mysql version 5.1.7 to 5.1.23 had "RENAME TO ". It was later removed because of a finding that it can lead to data loss. The easiest way to achieve this now is to dump the contents of the existing database to another newly created one.

echo "create database new_database;" | mysql -u <username> -p <enter password>

mysqldump --user=<name> --password=<password> <old_database> | mysql -D new_database -p <enter password>

Now you can drop the old database ( after making sure you have all the contents on the new database). Ofcourse you need to recreate the user permissions for the new database.

Monday, April 20, 2009

Joomla v1.5 and Google Adsense

If you have a website built using joomla (version 1.5) and want to place google adsense ads there, there are modules available. But I wanted an easier native joomla solution. So I hacked up one myself. The main problem with joomla and placing the adsense code is, joomla filters out the script or treats them as html text.

To work around this issue you need to think outside of joomla. Here is what I did.

1) Created a new module using mod_html
2) Noted down the id of the module.
3) Logged in to the backend mysql database and put the adsense code in the module I just created. This way I bypassed all the filtering.

use <joomla_database> ;

update jos_modules set content = '<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxx";

google_ad_slot = "xxxxxxxxxxx";
google_ad_width = 180;
google_ad_height = 150;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>' where id = <module_id> ;


Just remember not to edit this module again from Joomla!

Saturday, April 18, 2009

Unicode utf-8 in Mysql,perl DBI,MIME::Lite

I have a database which stores unicode text. Periodically I need to get the stored text and mail to a mailing list. Initially the text received through the mail was unreadable. After several tries and spending sometime multiple documentation pages, I found all the right settings.

For the mysql DBI you have specifically enable utf8 processing of the strings. There are other ways to achieve this like converting each string. But it will quickly become tedious. This is the easiest.


use DBI;
my $dbh = DBI->connect("DBI:mysql:${database}:${hostname}", $username, $password)
or die "DB Connection not made: $DBI::errstr";
$dbh->{'mysql_enable_utf8'} = 1;
$dbh->do('SET NAMES utf8');


For sending the mail, you tell MIME::Lite the charset(utf8) and encoding(8bit).


my $msg = MIME::Lite->build(
From => 'user@sample.com',
To => $recipient_emailid,
Subject => "=?UTF-8?B?" .
encode("utf-8", $subject) ."?=",
Type => 'TEXT',
Encoding=> '8bit',
Charset => 'utf-8',
Data => $body
);
$msg->attr("content-type.charset" => "utf-8");

$msg->send;