How to dump or export all the table definitions in a MySQL database

So you have  a database with loads of tables. You want the table definitions of all of them. You don’t really need the data. mysqldump to the rescue!

mysqldump -u USERNAME --password=PASSWORD --no-data --opt DB1 > DUMPFILE

That’s it! Easy as a pie :) The key here is the –no-data option. It dumps all the table definitions, but not the table data.

Want to do this for multiple databases? No problem.

mysqldump -u USERNAME --password=PASSWORD --no-data --opt --databases DB1 DB2 > DUMPFILE

The –databases option allows you to add multiple databases.

mysqldump -u USERNAME --password=PASSWORD --no-data --opt --all-databases > DUMPFILE

The –all-databases option allows you to dump all the databases.

mysqldump -u USERNAME --password=PASSWORD --no-data --opt DB1 --ignore-table DB1.TABLENAME1 --ignore-table DB1.TABLENAME2 > DUMPFILE

–ignore-table option allows you to skip dumping certain tables. Do not forget to specify the databasename when using this option.

 

Know any more tricks? Let us know in the comments below :)

How I recovered my Thunderbird mail from backup

So the best way to backup your mails from Thunderbird is to copy your complete profile directory. Follow these steps for restoring your mail.

The fool that I am, instead of copying the full profile directory I ended up backing up just the Mail subdirectory in the profile directory. It took me a while to figure out how to restore the backup, so I thought I would share it with you.

The first thing you do is install Thunderbird (if you haven’t already). Now Run( Windows : Start->Run or press Win key+r ; Mac/Linux – you’re smart enough to know :P ) this command “thunderbird.exe -profilemanager”. Create a dummy profile – just have some dummy email address in there. Now exit Thunderbird.

Next step is to find your newly created profile directory. Locate the Mail directory in there. Now you have to copy 2 files from your backup – both have the same name. One has a .msf extension and the other has no extension. I had created a separate thunderbird mail folder with a filter and I needed to backup just that one alone. So I just copied those 2 files (from the Inbox.sbd directory) and put them in the Local Folders subdirectory in the Mail directory (which already had empty files like Trash and Trash.msf).

The file without extension – this is the actual mail file. It’s in the mbox format. The other is an index file.

Acknowledgements :

I posted a question on Aardvarkhttp://vark.com/t/eee11d. I got replies from Shel and Moez. I would like to thank both of them for helping me out.

Techcrunch site “hacked”

Some content below may not be safe for work (wink wink) :D

So TechCrunch got broken into/”hacked”/cracked. Apparently because someone was pissed off by the ads shown. Heh heh.

So here’s a screenshot before they fix things.

 

TechCrunch

TechCrunch hacked

This is the text inserted into the TechCrunch page

So Arrington, how much did all the media coverage yesterday brought you in trough the welcome.html ad you
forced
people to? What a fucking retarded move was that you twat. You should be thanking me and sucking on my fucking ballsack for not deleting everyone on the box and publishing the mysql, if that’s what you want O.K, I can do that. Also, you fucking dickwads from sites like Yahoo!, BBC and plenty more, where the FUCK do you see adult content on
http://dupedb.com/
???????? I mean honestly, are you fucktards also in just for the money?!?!?!
So Arrington, how much did all the media coverage yesterday brought you in trough the welcome.html ad you
forced
people to? What a fucking retarded move was that you twat. You should be thanking me and sucking on my fucking ballsack for not deleting everyone on the box and publishing the mysql, if that’s what you want O.K, I can do that. Also, you fucking dickwads from sites like Yahoo!, BBC and plenty more, where the FUCK do you see adult content on
http://dupedb.com/
???????? I mean honestly, are you fucktards also in just for the money?!?!?!

 

Update : TechCrunch has posted on this issue and promised to update the post with info as it comes along.

Firebug opens automatically for all pages

Faced this bizzare issue today in Firefox. Firebug was opening automatically for all pages. Even on closing firebug, all I had to do was click on a new link in the same tab for it to appear again. This happened for all tabs.

Turns out I had accidently turned on “On for all Web Pages” option. Right clicked on the Firebug icon to turn it off. Problem solved :D

Right click Firebug

Right click Firebug to disable "On For All Web Pages"

Booking tatkal tickets on IRCTC the supercool way

This article is a short demo to using Firefox’s Autofill Forms extension to book tatkal tickets. First step is to go to https://addons.mozilla.org/en-US/firefox/addon/4775 and install the extension. You’ll need to restart Firefox for the extension to take effect.

Now that it’s done, head to the IRCTC website and login. Now head to the Quick Book page. You can fill in the details.quick book on IRCTC
If you do not know the train number, you can get it from the “Plan My Travel” page. Now that you’ve filled up all the details you want to, right click on one of the form textboxes. Click on the “Add complete form as profile” option.add complete form as profile

A new window like this will now open up

Autofill forms profile

You can close the window and reload the QuickBook page. Press the Alt+j key combination to autofill the form. You can reload the page as many times as you want and press Alt+j to autofill.

 

This post is dedicated to my good friend Dhanya.

Edit : OK, I’m giving into blackmail from someone crafty and cunning(not my words) :P

@gjoos : i want my name included in that blogpost if you want me to TRY booking tickets for you tomorrow !!! :P

So, Divya chechi.. this post is dedicated to you as well :P

Update : Wondering what CKWL means? Check out my blog post on CKWL status on Tatkal railway ticket.

CKWL on Tatkal railway ticket

So the other day I booked a tatkal ticket online from IRCTC. After the usual 500 errors and multiple tries I came to the “Congratulations!” page where they gave me the ticket details. And this is what I found in the ticket’s status “CKWL 23″. I wondered what the heck it was. Googling did not help. I shot off a mail to the IRCTC customer care and within half an hour I got their reply. Reproducing their reply below -

Dear Customer,

Kindly note that CK stands for Tatkal CKWL means Tatkal Wait list Ticket.

Thanks & Regards

So there it goes. Official reply from IRCTC. CKWL is the waiting list for the tatkal quota. It’s just like the “WL” you get on the normal ticket, except it’s on the tatkal quota. No idea what CK stands for though.

Although the reply wasn’t exactly Shakespeare, I was impressed that they got back to me so soon. It’s nice to see the Railways doing good stuff. There’s still room to improve though.

Have you had a similar experience with IRCTC? Frustrating one? Good one? The comment form is right below :)

Update : Found something in the IRCTC site in the ngpay FAQ. It says(in point 9)

Booking can be done against general (GN), ladies (LD) and tatkal (CK) quota berths/seats only.

 

. What this means is that GNWL is General Quota Waiting list, LDWL is Ladies Quota Waiting List and CKWL is Tatkal Quota Waiting list.

If you’re looking to improve the time it takes to book tatkal tickets, you can try the Autofill forms extension. Check out my blog post on how to use the Autofill forms addon.

Comparison of Google Public DNS and Open DNS response

Google announced that it’s making 2 DNS servers available publicly. The servers are 8.8.8.8 and 8.8.4.4 . They’ve also given configuration instructions on their DNS page. I configured my /etc/resolv.conf to refer to Google’s DNS. Before this I ran some quick tests using dig to compare it with OpenDNS.

$ dig @208.67.222.222 gingerjoos.com

; <<>> DiG 9.4.2 <<>> @208.67.222.222 gingerjoos.com
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1273
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gingerjoos.com.                        IN      A

;; ANSWER SECTION:
gingerjoos.com.         14400   IN      A       208.113.199.196

;; Query time: 751 msec
;; SERVER: 208.67.222.222#53(208.67.222.222)
;; WHEN: Fri Dec  4 09:13:58 2009
;; MSG SIZE  rcvd: 48

$ dig @8.8.8.8 gingerjoos.com

; <<>> DiG 9.4.2 <<>> @8.8.8.8 gingerjoos.com
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2594
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gingerjoos.com.                        IN      A

;; ANSWER SECTION:
gingerjoos.com.         14400   IN      A       208.113.199.196

;; Query time: 616 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Fri Dec  4 09:14:09 2009
;; MSG SIZE  rcvd: 48

$ dig @8.8.4.4 gingerjoos.com

; <<>> DiG 9.4.2 <<>> @8.8.4.4 gingerjoos.com
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34741
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;gingerjoos.com.                        IN      A

;; ANSWER SECTION:
gingerjoos.com.         14321   IN      A       208.113.199.196

;; Query time: 123 msec
;; SERVER: 8.8.4.4#53(8.8.4.4)
;; WHEN: Fri Dec  4 09:15:28 2009
;; MSG SIZE  rcvd: 48

Dig allows you to directly query a DNS server and get its reply. It shows stats from that query – response. The stat we’re interested in is this one

;; Query time: 123 msec

The IP 208.67.222.222 is the address of the OpenDNS server. Let’s try one more query


$ dig @208.67.222.222 mec.ac.in

; <<>> DiG 9.4.2 <<>> @208.67.222.222 mec.ac.in
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44308
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;mec.ac.in.                     IN      A

;; ANSWER SECTION:
mec.ac.in.              604800  IN      A       210.212.232.132

;; Query time: 389 msec
;; SERVER: 208.67.222.222#53(208.67.222.222)
;; WHEN: Sat Dec  5 12:38:57 2009
;; MSG SIZE  rcvd: 43

$ dig @8.8.8.8 mec.ac.in

; <<>> DiG 9.4.2 <<>> @8.8.8.8 mec.ac.in
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56600
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;mec.ac.in.                     IN      A

;; ANSWER SECTION:
mec.ac.in.              160448  IN      A       210.212.232.131

;; Query time: 121 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sat Dec  5 12:39:06 2009
;; MSG SIZE  rcvd: 43

You can try more queries and see for yourself. At least as of now Google DNS seems to be faster.

Gravatar support in Drupal

If you’ve been using Wordpress you probably know about Gravatar. Gravatar is an abbreviation for “Globally Recognized Avatar”. It’s a service which provides an avatar across sites. While Gravatar support is built-in in Wordpress, it requires an external module to be installed in Drupal. Recently I had to use the module in a Drupal 5 instance.

The module provides a gravatar only for comments. You can have the module insert the gravatar into the comment body itself or have it provide a field in the comment object ($comment->gravatar) which can be used by the theme. It does this by using the hook_comment() .

In our case though, we needed it to show the gravatar instead of the user picture if the user had not uploaded any. This was very easy to do. The key function here is _gravatar_get_gravatar(). You can provide it any or all of these parameters – mail, default, size or rating. Mail is the email id of the user. Gravatar can supply a unique generated avatar in case the email id you send them is not that of a registered Gravatar user. This can be of many types – identicon, wavatar or monsterid. Which of these are what you want, is specified in the default parameter. The size is of course, the size. The gravatars uploaded come with a rating – G, PG, R or X. You can specify a maximum rating with the rating parameter. You can read more about the gravatar parameters.

You can pass whichever of these parameters you want to _gravatar_get_gravatar() and it will return to you the url of the gravatar. Now pass this to the theme_gravatar() function in the gravatar module.

$picture = theme('gravatar',$gravatar_url,$username,$url);

You have to do all of this in the theme_user_picture function of your theme. If your theme is something like -

function THEMENAME_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    if ($account->picture && file_exists($account->picture)) {
      $picture = file_create_url($account->picture);
    }
    else if (variable_get('user_picture_default', '')) {
      $picture = variable_get('user_picture_default', '');
    }

You could change it to something like -

function THEMENAME_user_picture($account) {
  if (variable_get('user_pictures', 0)) {
    if ($account->picture && file_exists($account->picture)) {
      $picture = file_create_url($account->picture);
    }
    else if (user_access('use gravatar', $account) && (!user_access('disable own gravatar', $account) || !isset($account->gravatar) || $account->gravatar)) {
      $picture = _gravatar_get_gravatar(array('mail' => $account->mail));
      return theme('gravatar',$picture,$account->name,'');
    }
    else if (variable_get('user_picture_default', '')) {
      $picture = variable_get('user_picture_default', '');
    }

You could even rewrite the default theme_gravatar provided by the gravatar module with your own THEMENAME_gravatar theme function.

vimdiff – the cool way to diff for vim users

Some of you using the vim editor may not know about a tool that comes with vim called vimdiff. Vimdiff is an awesome way to diff files if you are a vim nut. It gives you the power of vim + the power of diff.

How’s this different from opening 2 files in vim (with -O option) you ask ? The difference is that vim will highlight the diff for you.

Fire it up by giving the 2 filenames, say

$vimdiff old new

This will bring up a screen like this -

vimdiff

vimdiff

Now you can move around the 2 parts of the screen with your regular vim commands. For eg. use (Ctrl+w) + right arrow to move to the right half of the screen.

vimdiff with cursor on right half of screen

vimdiff with cursor on right half of screen

You can copy paste as well. Go to the 2nd line in the left half and press the y key twice to copy that line. Use (cntrl + w) + right arrow to move cursor to the 1st line in the right half of the screen. Press p to paste the copied line below the 1st line.

vimdiff with copy paste

vimdiff with copy paste

You can go to the first line and delete the two words “a new” by moving the cursor to “a” and hitting d2w key combo.

vimdiff deletes words

vimdiff deletes words

Insert “an old” there by going to insert mode(press i key) and then typing the two words. You’ll see that vimdiff does not highlight anything. This means that there is no difference between the two files.

two files with no difference in vimdiff

two files with no difference in vimdiff

Vimdiff is the same as bringing up vim with the -d option. You could do the same things you did above by using

$vim -d old new

Bonus :
You can also diff 2 URLs directly with vimdiff
Try
$vimdiff 'http://www.google.co.in/search?q=vimdiff' 'http://www.google.co.in/search?q=vim'
You’ll first see something like this coming on screen

:!curl -o '/tmp/v959288/1' 'http://www.google.co.in/search\?q=vimdiff'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
"/tmp/v959288/1" 4L, 5289C
:!curl -o '/tmp/v959288/2' 'http://www.google.co.in/search\?q=vim'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
"/tmp/v959288/2" 4L, 5253C
Press ENTER or type command to continue

Now press the ENTER key to see the diff

vimdiff also works directly with URLs

vimdiff also works directly with URLs

You can throw in ssh into the mix as well. Try something like this
$vimdiff old <(ssh user@host cat ~/new)

If you're a vim/vimdiff ninja and know some more tricks, do post them below :)

Happy hacking...

User agent GTB or GTB5 is the Google Toolbar

Was checking out this blog’s visitor stats recently when I came across this User Agent "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5".  I was wondering what GTB5 was. Some googling and testing later I found out that GTB is in fact the Google Toolbar. To compare, here’s the UA of a Firefox browser with Google Toolbar installed :

"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5"

And here’s another Firefox without it :

"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"

Also, if you plan to capture the UA string in the Apache logs, make sure that feature is turned on. Your LogFormat directive must have something like \"%{User-Agent}i\" in it. For eg,

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

You can check the Apache documentation on custom log formats for more info. If you’re using XAMPP/LAMPP, you might want to comment out

CustomLog logs/access_log common

line in your httpd.conf and uncomment

CustomLog logs/access_log combined

line.