URL escaping in Javascript

November 16th, 2009 No comments

Though normally you can use the escape function for this, note to full URL encode an actual URL, use encodeURIComponent instead … saves a lot of headaches when deailing with ajax ….

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: Javascript Tags:

mySQL backup script

November 16th, 2009 No comments

This backup is listed on the mySQL site somewhere. Backs up a DB broken down into individual tables. Great if you have large data sets. This one also purges the files after 7 days ( does leave the directories behind though )

#setup
suffix=`date +%Y%m%d`
dest=/mirror/mysql/SQL01
cmd='/usr/bin/mysqldump'

databases=(`echo 'show databases;' | mysql -h SQL01 -u root | grep -v ^Database$`)

for d in "${databases[@]}"; do
if [[ $d != 'tmp' && $d != 'test' ]]
then
echo "DATABASE ${d}"
s="use ${d}; show tables;"
tables=(`echo ${s} | mysql -h SQL01 -u root | grep -v '^Tables_in_'`)
for t in "${tables[@]}"; do
if [[ $t != 'tbl_parameter' && $t != 'tbl_session' ]]
then
echo " TABLE ${t}"
path="${dest}/${suffix}/${d}"
mkdir -p ${path}
${cmd} --user=root --host SQL01 --quick --add-drop-table --all ${d} ${t} | bzip2 -c > ${path}/${t}.sql.bz2
fi
done
fi
done

# delete old dumps (retain 5 days)
find ${dest} -mtime +10 -exec rm {} \;

find /mirror -depth -type d -empty -print0 |xargs -0 rmdir

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: MySQL Tags:

Select random date

October 30th, 2009 No comments

I use this for insert records into a queue. To avoid overload one day, just split the records up over a number of days ….

now() + INTERVAL rand()*2 day + INTERVAL 2 hour

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: MySQL Tags:

Get useragent in JSP file

October 28th, 2009 No comments

request.getHeader("user-agent");

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: Java, Uncategorized Tags:

Notes on installing pgbouncer

September 15th, 2009 No comments

.. this is me just dumping my brain from the office after installing pgbouncer. FYI it works great, and really does improve the speed for db generated web pages. Don’t take this as THE install method, this is just notes so I can remember how to do it again :P

Get the source from pgfoundry ( I put it in /usr/local )
wget http://pgfoundry.org/frs/download.php/2284/pgbouncer-1.3.1.tgz

Unpack it
gunzip -c pgbouncer-1.3.1.tgz | tar -xv

Get / unpack / make libevent if not already installed
wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
gunzip -c libevent-1.4.12-stable.tar.gz | tar -xv
cd libevent-1.4.12-stable
./configure
make
make install

Back to pgbouncer
cd pgbouncer-1.3.1
./configure
make
make install

Move the ini and user files to /etc so I know where they are
mv etc/pgbouncer.ini /etc/
mv userlist.txt /etc/

Edit the userlist.txt to add user
Edit the pgbouncer.ini to point to new locations
auth_file = /etc/userlist.txt
logfile = /var/log/pgbouncer.log
pidfile = /tmp/pgbouncer.pid

Add libevent module ( fixed library not found error )
vi /etc/ld.so.conf.d/libevent-i386.conf

add line
/usr/local/lib

Run ldconfig to take new settings
ldconfig

I added the following to the START of postgresql in /etc/init.d
$SU -l postgres -c "pgbouncer -d /etc/pgbouncer.ini"

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Categories: Linux Tags: