Friday, July 10, 2009

Linux : Install fonts on Linux

To install new fonts in your home directory (only for you; not
system-wide) follow this procedure.

If ~/.fonts does not exist,
% mkdir ~/.fonts

Download and copy the .ttf files into this directory and run

% fc-cache

For users who need to download Devanagari fonts, here's a good resource.
http://www.wazu.jp/gallery/Fonts_Devanagari.html

Wednesday, May 20, 2009

MySQL:Set up unique key ignoring duplicates

For many of you who might be having trouble setting up a unique key on
a table containing duplicates, here's the key

mysql> ALTER IGNORE TABLE table_name ADD UNIQUE(column_name)

Please note the keyword IGNORE in the above statement. That does the
work forcefully.

Sunday, February 15, 2009

Linux : tr (translate) command

I made a good use of the translate command recently to get month-name
in upper case. I needed this in a shell script. Here's the command

date +%b | tr [a-z] [A-Z]

Output: FEB

Learn more about tr using the following command

man tr

Monday, February 09, 2009

Consider freelancing !

Reasons why you should consider freelancing

* Freelancing provides you with chances to build your own business
contacts who will keep you busy.
* You are free to do many jobs at the same time.
* Nobody takes away your credit. You get rewarded for your work.
* You can work remotely from the comfort of your home. You save daily
commute which takes a lot of time.
* You can work when you are most productive. Flexibility of time is a
great advantage.
* You get good pay rate simply because there are no overheads. Money
is not lost to company administration or your manager :-)
* As I started writing this post, I thought someone must have done it
before so I googled and found that there's a list of 101 such reasons
on
http://www.hrworld.com/features/101-reasons-to-freelance-091007/
I never considered all those reasons before starting freelancing myself.
* Finally, because it's become hard to get a job when the world is hit
by recession.

Tuesday, February 03, 2009

Mysql: keep connection open for longer

These mysql queries will keep the connection open for 1800 seconds

SET @@local.wait_timeout=1800;
SET @@wait_timeout=1800;
SET @@local.interactive_timeout=1800;
SET @@interactive_timeout=1800;

Wednesday, January 28, 2009

MySQL: GROUP BY on datetime column

SELECT DATE_FORMAT(MyDate, '%d %M %Y') AS Date, COUNT(*) AS numRows
FROM Table1 GROUP BY Date;

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.