Your IP address is: 38.107.179.240
August 31, 2010
August 29, 2010
Fade-in popup window example in Javascript
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <script type="text/javascript">// <![CDATA[ // Browser safe opacity handling function function setOpacity( divid, value ) { document.getElementById( divid ).style.opacity = value / 10; document.getElementById( divid ).style.filter = 'alpha(opacity=' + value * 10 + ')'; } function fadeInMyPopup( divid ) { for( var i = 0 ; i <= 100 ; i++ ) setTimeout( 'setOpacity("' + divid + '", ' + (i / 10) + ')' , 8 * i ); } function fadeOutPopup( divid ) { for( var i = 0 ; i <= 100 ; i++ ) { setTimeout( 'setOpacity("' + divid + '", ' + (10 - i / 10) + ')' , 8 * i ); } setTimeout('closeMyPopup( divid )', 800 ); } function closeMyPopup( divid ) { document.getElementById( divid ).style.display = "none"; } function launchMyPopup( divid ) { setOpacity( divid, 0 ); document.getElementById( divid ).style.display = "block"; fadeInMyPopup( divid ); } // ]]></script> <div id="popup1" style="width: 380px; height: 300px; display: none; position: absolute; top: 130px; left: 80px;"> <table border="0" cellspacing="0" cellpadding="0" width="380"> <tbody> <tr> <td><img src="/images/menubar_bg.png" alt="" width="356" height="23" /></td> <td><a href="javascript:fadeOutPopup("popup1");"><img src="/images/window-close.png" border="0" alt="" width="24" height="23" /></a></td> </tr> <tr> <td style="padding: 5px 10px; vertical-align: text-top; background: url(/images/popup_body.png) no-repeat scroll left top transparent; width: 380px; height: 277px;" colspan="2"> This is a test of the emergency pop up system. If this were an actual emergency, you'd have been trampled. :-)</td> </tr> </tbody> </table> </div> <input onclick="launchMyPopup('popup1')" type="submit" value=" Launch Popup1! " /> |
You can have multiple popups on one page simply by changing the DIV id and setting the calls to fadeInPopup() and launchMyPopup() accordingly.
August 27, 2010
.htaccess Redirect to a new directory
I recently found I wanted to move some data on my Apache webserver from one directory to another, and didn’t want to muck around with symbolic links (trying to keep the webspace clean and tidy), but also wanted to ensure that links to these items and searches would still find them.
The answer? .htaccess file and Redirect!
For example, say you moved the /photos directory on your webserver to /media/photos you could do the following to ensure that old links work:
In the .htaccess file in your webserver’s root directory, add the following line:
Redirect permanent /photos/ /media/photos
Shazam! http://yourserver/photos/whatever.jpeg will redirect to http://yourserver/media/photos/whatever.jpeg
August 25, 2010
Online DNS Lookup (MX or A Records)
Lookup A records (IP lookup), MX records (Mail eXchanger), and more for a domain (ie: dig).
Results:
August 12, 2010
Pronounceable Password Generator
Here’s a simple online password generator – I’ll likely add some more features, but it works. You can select the style of password from “_Lf?^x)p” gobbledeegook to “maliLulu” pronounceable (and easier to remember) styles.
These passwords are generated using passook.
August 9, 2010
Fixing “Warning: file_get_contents()” php error
I recently got the following error on a newly installed webserver:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.
Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:
allow_url_fopen = Off
To:
allow_url_fopen = On
I recently got the following error on a newly installed webserver:
Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/localhost/htdocs/wordpress/wp-content/plugins/statsurfer/statsurfer.php on line 3543
This happened to me after activating StatsSurfer for this blog, and that big ugly error would appear at the top of every page.
Thankfully, the fix is quite easy (strangely hard to google for though), in your php.ini file (mine’s at /etc/php/apache2-php5/php.ini – other *nix variants will be similar), just change the following line in the php.ini file from:
allow_url_fopen = Off
To:
allow_url_fopen = On
Restart Apache, and off you go.
August 2, 2010
Backing up MySQL database by database and table
Backing up mysql databases using mysqldump is pretty quick and painless:
mysqldump -u username -ppassword -h hostname db_name > backup_file.sql
or
mysqldump -u username -ppassword -h hostname --all-databases > backup_file
The only problem is that it becomes quite cumbersome recover a particular table.
I wrote a little script to backup each table in each database to its own file:
#!/bin/bash
if [ $# -lt 2 ]
then
echo "Usage: backup_all_tables username password [host]"
exit
fi
mysql_bin="/usr/bin/mysql"
mysqldump_bin="/usr/bin/mysqldump"
backup_path="/opt/backups/www/"
if [ $# -eq 3 ]
then
host=$3
else
host="localhost"
fi
user=$1
pass=$2
for db in `echo "show databases" | $mysql_bin -u $user -p$pass -h $host | grep -v Database | grep -v information_schema`
do
for table in `echo "show tables" | $mysql_bin -u $user -p$pass -h $host $db | grep -v "Tables_in"`
do
echo "Backing up $host.$db.$table to $backup_path${host}_$db.$table.sql"
$mysqldump_bin -u $user -p$pass -h $host $db $table > ${backup_path}${host}_$db.$table.sql
done
done
save the script as “backup_all_tables.sh”, edit the $backup_path variable to suit, do a chmod +x backup_all_tables to make it executable, and run it using:
./backup_all tables username password hostname
If the database is on your local machine you can omit the hostname.
This will backup the files in the format “host_db.table.sql”, ie: “localhost_mysql.user.sql”
August 1, 2010
Huge sendmail queue – clearing it out
There are numerous reasons that the mail queue can get over full, ranging from general network problems, to having a user repeatedly sending an email with a large attachment to an incorrectly type address.
The first thing you likely want to do is get some information on what’s in the queue:
To find out how many messages are in the queue:
mailq | tail -1
This will give you the total number of emails in the queue, ie:
Total requests: 6592
You might also want to know how old or new they are, so:
ls -lt | tail -10
and
ls -ltr | tail -10
will show you the oldest 10 and the newest 10 respectively.
To have sendmail retry the emails, simply run (as root):
sendmail -q -v
If you are in a situation where it has filled up the disk and need to fix it FAST, move the directory to another partition and then have sendmail process it from there (stopping sendmail with “/etc/init.d/sendmail stop” is recommended:
mkdir /root/tmpq
mv /var/spool/mqueue/* /root/tmpq
sendmail -q -v -oQ/root/tmpq
(if you get an error like “Argument list too long” instead run “mv /var/spool/mqueue /root/tmp” with sendmail stopped, then restart it)

Like