Saturday, August 22, 2009

BASH Script to copy a particular file to different directories having the same pattern folder structure

One of the module which was done has to be copied to many directories say roughly around 50 inner directories. I did that by replicating it, but when i tested it i found that I have to change a file in all the 50 directories. I knew there is definitely a way out which can do this job easily and did some googling and used the bash script to write a small program which will do a small wonder for me.

The below bash script will loop thru all the directories (eg., abc, def, mmm ) and copies a file from turn/site/newfile.txt to all site directories which has been looped thru now.

for directory in abc def mmm
  echo $directory
  cp trunk/site/newfile.txt $directory/site/somefile.txt

Note: While reading some sites, I found interesting bash shell script: copy only files modifed after specified date

Hope this might help you to save time.

Friday, August 21, 2009

ER Diagram Tool for Mac

Have you ever did an ER Diagram for the Tables ? hmm, I hope yes, you might have did in your schoolings. Did you thought at that time how much it will be useful later ? Ok, Ok, coming straight to the point, I was figuring out any tool which might do the ER Diagram easily without straining too much. Atlast I found one for Mac.

SQLEditor for Mac

I have downloaded the 30 Day trial and tested it and works fine. I was in search for this which accepts the MySQL exported SQL file and it draws the ER Diagram for it.

Thursday, August 20, 2009

Easy Steps to remove "Read More" , Published by author - Drupal 6

One of the ticket raised in Drupal community was, how to remove the "Read More" link & "Published by Author" with date for a story / page while listing the stories in the website. I just digged the code for exactly 1 min and found an easy solution. Drupal 6 is as good as you think good. But really speaking its really damn good. I went to the garland folder present in the themes folder. I just removed the below two blocks and saved the node.tpl.php file.

<?php if ($submitted): ?>
<span class="submitted"><?php print $submitted; ?></span>
<?php endif; ?>

<?php if ($links): ?>
<div class="links"><?php print $links; ?></div>
<?php endif; ?>

I definitely hope that this might have solve his issue who has raised it in Drupal Themes community. If you feel any issues, please let me know I will try to help as much as possible.

Wednesday, August 19, 2009

Clear Cache in Mac OS X might increase fast bootup

Last week I went to a service center to ask why my Mac book is slow only while booting. One of the suggestion was that RAM present in the Mac to be increased which might cost little expensive. This was definite but spending money would mean that we need to think really is that needed ? Anyway I also asked him is there any other way without spending money really much. He suggested two ways which help to improve the Mac performance better.

a) To clear the caches

To clear the cache you need to move all the files from /Library/Caches to Trash
Also Move all the files from /Users//Library/Caches to Trash

b) Need to have 60 GB of free space

I have a HDD of 200 GB and 2GB RAM in which 1GB RAM is fully utilized by the Mac Leopard itself. Whenever I have less than 40GB of space, my Mac drive slowly and sometimes i feel its hanged but never.

Hope this might solve you too.

Friday, August 14, 2009

use sed to find and replace a particular text

One of my colleague asked me how to find and replace a particular text in a remote shell where X Windows / any IDE is not available. I just googled for sometime and then I tried my self with only one hint to use the sed command. You will not believe I tried it for 5 times and I got the thing working at the 6 attempt, wow i felt so happy. Anyway back to the command, please use the below command to find and replace in any file.

sed -i "s/example/sample/g" *

The above command will find "example" text in all the files present in the current directory and replaces them with "sample" text. The text example / sample not only accepts exact words but regular expression is also possible.

Please feel free to ask me if you need any help regarding this.

Tuesday, August 11, 2009

Copy Window Freezed in MacOS Finder

Before Reading please make sure that I have alternative solution only, I don't have proper solution.

I was trying to copy files from remote location to my laptop, after 25% of completion the network connectivity was lost. I was surprised to see that copy window got freezed and even the cancel button (x) was also not working. I kept the window open for 2 days and meanwhile I was working on the other things. Atlast my laptop started working slowly so I thought if I get rid of this frozen window it would make my life easier. Unfortunately there was no PID for this to kill it, so atlast I made a Force Quit of the Finder which automatically restarted the Finder and it was good. But I don't know is there any other good idea to get rid of this.

Please help me out if you have any answers for this as I couldn't find any solution even after googling it out.

Friday, August 7, 2009

Mysql Number Formating '0000X'

I was just trying to figure out how to print an stored value of integer having 0 pre appended with it.

The best and good way to prepend zero integer value for a integer of fixed size is to alter the table having "UNSIGNED ZEROFILL" as an attribute for the field which needs zero prepended with it.

`ID` int(11) NOT NULL auto_increment,
`some_id` int(6) unsigned zerofill NOT NULL,

You can do when data is present and you want to do this.

ALTER TABLE `table_1` CHANGE `some_id` `some_id` INT( 6 ) UNSIGNED ZEROFILL NOT NULL

feel free to express your thoughts too.