Sunday, December 28, 2008

Linux : Installing mplayer on centOS

Installing mplayer on centOS is simple ! Execute the following commands as root


% wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
% wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
% rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
% rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm
% rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm
% yum check-update
% yum install mplayer

Tuesday, September 16, 2008

Bash : concatenate strings in bash

The problem -

You have $yr=2008
You want to obtain something like 2008_data.csv etc

$yr_data.csv does not work

The solution - Use curly braces to separate variables from strings
like this

${yr}_data.csv

Thursday, September 11, 2008

Linux : setting up hostname

Here's how you can set hostname of your linux machine

Become root, save hostname in /etc/hostname and tell the hostname
command to read the name from the file.
Here are the commands to do the same

% su
% echo your_hostname > /etc/hostname
% hostname -F /etc/hostname

However, on next reboot, hostname will be lost.

On Red Hat / centOS, edit HOSTNAME= entry of the file
/etc/sysconfig/network

This sets up the hostname permanently.

Sunday, August 10, 2008

MySQL : Delete all tables of a database

It seems there's no command to delete all tables of a database. I have
been just dropping the database and creating it again. Does anyone
know any better method ? If you don't have privileges to create/drop
db, my method is not going to work :-)

Friday, February 01, 2008

MySQL : grant command

The GRANT function is used both to create new users, and to assign privileges to users.
mysql>GRANT SELECT, INSERT, UPDATE, DELETE
->ON widgets.* TO widgetAdmin@localhost
->IDENTIFIED BY 'ilovewidgets';

Assuming that the user widgetAdmin did not yet exist when this query is executed, both the user and db tables will be updated with the necessary rows.

The above is taken from dev.mysql.com.

You can also use assign all privileges to a user on a certain database. Following is the syntax.

mysql> GRANT ALL PRIVILEGES ON
    -> test.* TO 'ketan'@'localhost'
    -> IDENTIFIED BY 'ketans_password';

I find this command exceedingly useful ! A quick way to set up privileges of a user on a db.

Thursday, January 03, 2008

PHP : Facebook application to solve jumbled words

Wrote a facebook application to solve jumbled words.

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

Try it out.

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;
}