How to move a column in MySQL

August 13th, 2008

mysql> ALTER TABLE mytable MODIFY COLUMN mycolumn INT AFTER someothercolumn;

How to setup a basic SVN repository and server

June 18th, 2008

Become root and install subversion via yum

# yum install -y subversion

Create your svnroot directory

# mkdir /home/svnroot

Edit your svnserve.conf

# vim /home/svnroot/conf/svnserve.conf

Your basic svnserve.conf will look like this:

[general]
anon-access = none
password-db = passwd
authz-db = authz
realm = Masao’s First Repository

Edit your authz file

# vim /home/svnroot/conf/authz

to look like this

[/]
masao = rw

Edit your passwd file

# vim /home/svnroot/conf/passwd

to look like this

[users]
masao = mypassword

Start your svn server

/usr/bin/svnserve -d -r /home/svnroot/

Create a directory and some files in it

$ mkdir myproject

$ cd myproject

$ touch myfirstfile mysecondfile

$ svn import . svn://localhost/myproject -m “initial commit”

Adding mysecondfile
Adding myfirstfile
Committed revision 1.

Now checkout your project

$ cd /tmp

$ svn co svn://localhost/myproject
A myproject/mysecondfile
A myproject/myfirstfile
Checked out revision 1.

You’re done!  Thanks Ian!

Profiling Perl

June 17th, 2008

# perl -d:DProf test.pl
hello

# ls
test.pl  tmon.out

# dprofpp tmon.out

Total Elapsed Time = 0.009982 Seconds
User+System Time = 0.009982 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
100.   0.010  0.010      1   0.0100 0.0100  warnings::BEGIN
0.00       - -0.000      1        -      -  strict::import
0.00       - -0.000      1        -      -  strict::bits
0.00       - -0.000      1        -      -  warnings::import
0.00       -  0.010      2        - 0.0050  main::BEGIN

libMagick.so.10: cannot open shared object file

June 3rd, 2008

Can’t load ‘…/auto/Image/Magick/Magick.so’ for module Image::Magick: libMagick.so.10: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/DynaLoader.pm line 230.

  1. Add /usr/local/lib to /etc/ld.so.conf
  2. Run ldconfig as root.

Change URLLIST in CPAN due to lagging

May 7th, 2008

To remove the first entry in the urllist, do this:

o conf urllist shift

This will make CPAN use the next FTP site in the queue.

How to edit the Mediawiki main page

April 4th, 2008

Edit this page:

MediaWiki:Mainpage

as in:

http://www.yourdomain.com/wiki/index.php/MediaWiki:Mainpage

Troubleshooting a MySQL query

April 1st, 2008

Use EXPLAIN to show which indexes are being used.

mysql> EXPLAIN SELECT mycolumns FROM table1 LEFT JOIN table2;\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: ag
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1010
Extra:
*************************** 2. row ***************************
id: 1
select_type: SIMPLE
table: zsg
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 361
Extra:
*************************** 3. row ***************************
id: 1
select_type: SIMPLE
table: ads
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: database.table.column
rows: 1
Extra:
*************************** 4. row ***************************
id: 1
select_type: SIMPLE
table: account_networks
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: database.table.column
rows: 1
Extra:
*************************** 5. row ***************************
id: 1
select_type: SIMPLE
table: accounts
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: database.table.column
rows: 1
Extra:


6 rows in set (0.00 sec)

How to get the directory location of a shell script

March 26th, 2008
dirname=`dirname $0`

How to Fork in Perl

March 26th, 2008

Kick off multiple processes simulataneously in Perl.

my $num = 10;

my @children;

for (my $i = 0; $i < $num; $i++) {
my $pid = fork();
if ($pid) { # parent
push @children, $pid;
} elsif ($pid == 0) { # child
print "child $i\n";
sleep 5;
exit;
} else {
print STDERR "couldn't fork\n";
}
}

foreach my $child (@children) {
waitpid($child, 0);
}

Adding Wordpress Categories programmatically using Perl/LWP

March 25th, 2008

Comment out one line in this file:

wp-admin/admin-ajax.php (around line 586)

case ‘add-cat’ : // From Manage->Categories
#check_ajax_referer( ‘add-category’ );

Now you can submit categories using Perl/LWP!