Friday, December 28, 2007

PHP : Solve jumbled words

Wrote a facebook application to solve jumbled words. Here's the link

http://apps.facebook.com/word_jumble/

Enjoy !

Wednesday, December 12, 2007

MySQL : rename a table

Renaming a table is easy ! Following is the command.

mysql> RENAME TABLE users TO members;

Saturday, November 24, 2007

Perl : selecting randomly elements of an array

#!/usr/bin/env perl
use strict;
my @test = (0,1,2,3,4,5);
my $i = 6;
while($i > 0){
       my $offset = int(rand(scalar(@test)+1)) - 1;
       print $test[$offset]."\n";
       splice(@test,$offset,1);
       $i--;
}

Saturday, October 13, 2007

Perl : making all filenames lowercase

Renaming all files in a directory to lowercase names in a directory recursively.

find . -type f -exec perl -e 'rename($_, lc) || warn "$_: $!\n" for @ARGV' {} \;

Wednesday, September 12, 2007

MySQL : root password reset

Here's what you need to do in case you forget the root user password of mysql.

# stop mysql service
/etc/init.d/mysql stop

# Start to MySQL server w/o password
mysqld_safe --skip-grant-tables &

# Connect to mysql server using mysql client
mysql -u root

# Setup new MySQL root user password
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

# Stop MySQL Server
/etc/init.d/mysql stop

# Start MySQL server and test it
/etc/init.d/mysql start
mysql -u root -h localhost -p

Tuesday, September 04, 2007

Web Development : Saving sessions in database

Some advantages of saving sessions in database.

1. The session data is more secure as a potential hacker must be
able to log into the database before he can access anything.
2. The use of multiple servers would not create a problem as all
session data now resides in a single central place and is accessible
by all servers.
3. It is much easier to query the database should the site
administrator require information about current sessions or current
users.

--
Regards,
Ketan

Wednesday, August 29, 2007

Linux : setting up rdist

rdist command is very helpful in synchronizing filesystems on two
server. rdist stands for remote distribution. Many useful options are
available with the command.

See `man rdist` for more information about the command.

This is how I set up rdists :-)

My crontab entry
10 * * * * rdist -f $HOME/bin/rdist_file > /dev/null

###rdist_file contains

## these are comments
/path/of/source/file -> target_server1 install
-onochkowner,nochkgroup,nochkmode /path/to/the/target/file;

### file rdist ed to target_server2
/path/of/source/file -> target_server2 install
-onochkowner,nochkgroup,nochkmode /path/to/the/target/file;

Linux : splitting a log file

To split a file into small files of 5000 lines, use this,

% split -l 5000 file

This creates files like xaa, xab etc.

Thursday, August 23, 2007

My website

I have launched my website.

http://www.carvingIT.com.

Your feedback is welcome !

Thursday, August 09, 2007

Leaving my job

After working with ANSYS-Fluent Inc. for more than 7 years, I have
decided to start working as a Consultant in the field of Linux,
Apache, MySQL, Perl/PHP. After joining Fluent, I developed liking for
the Linux platform and the open source technologies.

During my tenure with Fluent, I wrote many complex perl scripts and
modules. Now, I think Open Source is the field where I can help the
community and grow individually as well.

Monday, May 14, 2007

html source and bandwidth usage

1 character equals 1 byte.  Extra newline in html source means one extra byte sent to client.
If a website gets some 400 pageviews per day, you send 400x30 (sligtly more than 1 Kb) extra bytes per month.
This means 1 character may mean 1 Kb of bandwidth usage per month for a website of low traffic. More the traffic more the size associated per character.

Therefore, to save the bandwidth and to improve loading speed of your pages, optimize your templates and html !

Wednesday, February 28, 2007

mod_perl : DBI.so/GD.so can't be loaded

mod_perl can not load modules like DBI.so or GD.so ? The reason this happens is that the perl version with which you compiled mod_perl may not be the same that you are using currently. Whenever you upgrade perl, you have to recompile mod-perl and may be re-install these modules. That may solve this problem.

If you are using Apache2, you are lucky in the sense that you won't have to compile apache with mod_perl. Just re-build perl and install it and then build mod_perl and install.

Monday, January 22, 2007

PHP : Handling multiple select menu

Thought of putting a code to illustrate handling multiple select menus with php.

Note the square brackets and the multiple="multiple" part in the form.

HTML form
---------

<form action="some_action_file.php" method="post">
<select name="select_name[]" multiple="multiple">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</select>
<input type="submit" value="Submit" />
</form>
PHP part
----------
<?php ## some_action_file.php foreach ($_POST['select_name'] as $select_name){ echo "$select_name<br />"; ## prints all the selected values; one per line } ?>

Monday, January 15, 2007

Perl : Removing last newline in while

Here's a way to check if we are at the last iteration and removing the newline if true, while iterating through lines.

while(<>){
chomp if eof; ### eof returns 1 if next read on filehandle returns end of file
print;
}


Friday, January 05, 2007

Perl : Locating a perl module file

How do you find out exactly where a perl module file is ? Following example searches Template.pm in the paths where perl modules are installed.

find `perl -e '$,="\n";print @INC'` -name Template.pm

Note

The perl command is in back-ticks. This is an example of command execution within a command.

Thursday, January 04, 2007

Networking : Switches versus Hubs

A few days back, I replaced hub with a switch in my small LAN at home. Although it's just a plug and play sort of switch, I had to do some configuration changes so that computers could ping each other. I spent a lot of time solving connectivity problems :-) Learnt a lot about how switches work in the process.

I can think of following differences between a hub and a switch.

1. Hub requires no knowledge of how it works. It's easy to install. The same is not true with switches. Even if the manual s
ays "plug and play switch", it's better to know how switches work.

2. You may have to configure your NICs (network cards) so that the switch communicates. To configure network cards, you need
 to learn what to configure.

3. Switches offer you a learning opportunity :-). In the process of making your network work for you, you'll learn people me
an by words like duplex auto-negotiation and speed.

4. If you are required to troubleshoot, you learn still more. In that case, you'll learn commands like ethtool, ifconfig, tr
aceroute, ifup, ifdown etc.

5. Conlusion is, Switches are better than hubs not only because of the reasons you read on the net, but they also teach you
networking.