Where’d the Media Go?

December 6th, 2007 by Brian No comments »

Great editorial cartoon – found it at the Old Gold & Black

Where'd the media go?

Trouble with PHP regular expression; REG_ERANGE error

November 29th, 2007 by Brian 2 comments »

I had a situation where I needed to validate an email address that included an apostrophe. It is not widely known that the apostrophe (and a bunch of other symbols for that matter) are valid characters in the official RFC2822 specification for email address formats.

Anyway, I kept getting an error when I tried to add the apostrophe to my character classes in my regex. It gave me a strange error referencing REG_ERANGE. After some googling, I came across this blog post which led me to the answer. The problem is related to the placement of the dash (”-”) character in the regex.

Example 1:

if (ereg("[^a-zA-Z0-9_-.]", $userid)) {
    echo 'bad';
}
else {
    echo 'good';
}

The problem? The dash, or hyphen, being before the period. It thinks it’s a range, like you see in a-z. This may not be a bug, per se, but it’s certainly not smart enough for me.

The solution? Simply put the dash at the end of the regex.

Example 2:

if (ereg("[^a-zA-Z0-9_.-]", $userid)) {
    echo 'bad';
}
else {
    echo 'good';
}

No thanks, Chuck Norris… or Mike Huckabee

November 27th, 2007 by Brian No comments »

I’m still making up my mind about the pantheon of Republican candidates for president. I was briefly excited about the candidacy of former Arkansas governor Mike Huckabee. Then I started doing some research…

Even though I might draw the ire of Chuck Norris (have you seen this commercial? hilarious!), I can NOT handle the following clip:

[youtube]http://www.youtube.com/watch?v=DaJW7nXw30A[/youtube]

From what I gather – there is broad consensus that the go-to option used to pay for government programs during Huckabee’s administration was to raise taxes.

NO THANKS!

Why I switched to a new IDE for PHP development

November 27th, 2007 by Brian 1 comment »

I’ve been using Dreamweaver for about 10 years in some form or fashion. It actually started when I purchased Allaire HomeSite 3.0 in 1997. Macromedia purchased Allaire in 2001 and eventually merged HomeSite with their Dreamweaver product. Dreamweaver 8 is what I’ve been using for the past 2 years; that is, until I found PHP nirvana!

I have tried other IDE’s off and on for the past 5 years – trying to get more of a Visual Studio experience. I was really jealous of the code-completion and hinting features that were available in VS. Dreamweaver does ok at basic function hints for PHP, but nothing I found did a great job of combining all the site management features of Dreamweaver with the intelligent code parsing (ie. reading my classes and adding them to the code-completion hints). I’ve tried Eclipse with its PHP plug-in, UltraEdit, Zend Studio, phpDesigner and probably some others that I’m not listing.

PhpED Workspace

» Read more: Why I switched to a new IDE for PHP development

On-the-fly Form Validation with JavaScript Regular Expressions

November 19th, 2007 by Brian 1 comment »

I needed to check a text input field on a form to allow only specific values as the user typed in the field. The regular expression only allows characters a-z, numbers 0-9, the “dash” symbol and the underscore. Not sure why, but I had to break out the check for a space into a second regex.

Here's the JavaScript function:
<script language="javascript" type="text/javascript">
function testField(oField) {

	var illegalChars = /[^a-zA-Z0-9_-]/;
	var spaceChars = /\s/;
		// allow only letters, numbers, dashes and underscores
	if (illegalChars.test(oPrefix.value) || spaceChars.test(oPrefix.value)) {
		alert("The prefix may only contain letters, numbers, dashes and underscores.");
		oPrefix.value = oPrefix.value.substring(0,oPrefix.value.length-1).toUpperCase();
	}
	else {
		oPrefix.value = oPrefix.value.toUpperCase();
	}

}
</script>

And here's the HTML form that calls the script through the "onKeyUp" action.

<form name='frmTest' method="POST" action="somepage.php">
Text: <input type='text' name='someFieldName' value='' maxlength="5" style="width:65px;"  onkeyup="testField(this)">
</form>

Incoming Deacs Looking for a National Championship

November 19th, 2007 by Brian No comments »

I hope these guys are as good as we think they are. They certainly seem to be coming in with a bit of swagger about them.

Top class has fond memories of coach
This article is mostly about the 3 top recruits and their brief relationship with late head-coach Skip Prosser. But the last few paragraphs are exciting to think about…

Looking ahead

Talk to Aminu, Walker or Woods and they all have one goal in mind: a National Championship. Walker said he knew that the Deacons could be in that position as soon as he gave his nod to the program.

“As soon as I committed to Wake Forest, I started getting in contact with Tony Woods and he was telling me that he was going to choose between Florida and Wake Forest,” Walker said. “As soon as he said that, I knew that we were going to be something special. I was looking forward to that. Then when Al-Farouq came on with Tony, I was speechless.

“I know we are going to come in, work hard and do what we have to do to win a national championship.”

Aminu said he wants to play with a different mind-set this year, in honor of Prosser.

“I think there is a little more fire knowing that you were the last guy to commit to him. It kind of makes you want to dive onto the floor a little harder and a little more often. I think it’s motivating,” he said.

Walker shares the same sentiment.

“All Coach Prosser ever said to me was, ‘That I can’t wait to see you play. I know you’ll be a successful basketball player.’ I was looking forward to that so much.

“I was depressed for a few days. I could barely eat. When I dedicate these games, it is going to be real meaningful. I know Al-Farouq and Tony feel the same way.”

If You Could Only See

November 8th, 2007 by Brian No comments »

This morning I had the “party shuffle” feature going on iTunes. I heard “If You Could Only See” from the band, Tonic, coming through the speakers and remembering that this was the first mp3 I had, the thought occurred to me that perhaps the file modified date would tell me the exact date & time of when that was!

Sure enough. Aug 30, 1997 at 8:10PM EST. I’d say I was pretty early in the movement don’t you think?

If You Could Only See

MySQL Automated Backup and Testing Bash Script

October 31st, 2007 by Brian No comments »

So – you can go to any one of 100,000 sites that will tell you how to do an automated MySQL database dump with some combination of mysqldump and crond, etc. But, I was recently faced with the question, “what happens if the dump file is corrupt? can we validate it before we pack it away with our backup service?” So I came up with this little shell script.

It does the following:

  1. Creates a backup of the selected db using mysqldump
  2. Generates an MD5 checksum of the backup file (written to a separate file)
  3. Attempts to restore the dumped file into a dummy test database
  4. If errors are encountered, it grabs the error and sends an email to the designated address
  5. If no errors are encountered, wraps the .sql and .sql.md5 in a timestamped, gzipped, tarball – then deletes the originals

Download the file here

#!/bin/sh
#######################################################
# LICENSE:
# (c) 2007 Brian Bell (GNU LGPL V2.1) You may
# view the full copyright text at:
# http://www.opensource.org/licenses/lgpl-license.html
#
# DESCRIPTION:
# A simple BASH script to do automate MySQL database
# backup; includes testing and MD5 hash creation.
# Emails designated address on failure.
#######################################################

## CONFIGURATION VARS
MYSQL_NAME=
MYSQL_HOST=
MYSQL_USER=
MYSQL_PASS=
MYSQL_TESTDB=
BACKUP_PATH=/path/to/backup/dir # No trailing slash
MAIL_SUBJECT=”TESTING MySQL Backup Error”
MAIL_TO=”monitor@yourdomain.com”

#######################################################
## We need to create a unique timestamp for use on the filename
TIMESTAMP=`date +%Y_%m_%d`

## Generate the base part of the filename to use in backing up
BACKUP_FILE_BASE=”${MYSQL_NAME}_${TIMESTAMP}”

echo “Backing up $MYSQL_NAME…”
/usr/bin/mysqldump –opt -c -e -Q -h $MYSQL_HOST -u $MYSQL_USER –password=$MYSQL_PASS \
–add-drop-table $MYSQL_NAME > $BACKUP_PATH/$BACKUP_FILE_BASE.sql

## MD5 the backup file
/usr/bin/md5sum -t $BACKUP_PATH/$BACKUP_FILE_BASE.sql > $BACKUP_PATH/$BACKUP_FILE_BASE.sql.md5

## Try to import the backup sql into a test db
MYSQL_RESULT=`/usr/bin/mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} –password=${MYSQL_PASS} ${MYSQL_TESTDB} < \
${BACKUP_PATH}/${BACKUP_FILE_BASE}.sql >

${BACKUP_PATH}/mysql_test.log`

if [[ “$MYSQL_RESULT” =~ “ERROR” ]]
then
echo “The following error was encountered at `date` ” > ${BACKUP_PATH}/error_email.log
echo “” >> ${BACKUP_PATH}/error_email.log
echo “#####################################################################” >> ${BACKUP_PATH}/error_email.log
echo $MYSQL_RESULT >> ${BACKUP_PATH}/error_email.log

echo “SENDING ERROR EMAIL TO: ${MAIL_TO}”
/bin/mail -s “$MAIL_SUBJECT” “$MAIL_TO” < ${BACKUP_PATH}/error_email.log
else
tar czpf $BACKUP_PATH/$TIMESTAMP_$BACKUP_FILE_BASE.sql.tar.gz $BACKUP_PATH/$BACKUP_FILE_BASE.sql* –remove-files
fi

Here we go…

October 31st, 2007 by Brian No comments »

So the deal is, I come across quite a lot of stuff in the course of doing my job that I think others would find useful. Sometimes it is the little stuff that is the most frustrating to find which I hope to catalog here. For example – trying to install a particular package on Ubuntu that is providing generic and vague error messages, etc. I usually wish that if someone had just posted a blog entry about my specific problem, maybe I wouldn’t be spending this half-hour unnecessarily. Anyway, maybe this stuff will be useful to someone.

“Huckabee would be a disaster on immigaration”

January 2nd, 2007 by Brian No comments »

From the Selwyn Duke at American Thinker:

Huck would be a disaster – a disaster – on immigration. In fact, in 2006 he compared those who would crack down on illegals to antebellum slave masters, saying,

“One of the great challenges facing us is that we do not commit the same mistakes with our growing Hispanic population that we did with African Americans 150 years ago and beyond. We’re still paying the price for the pathetic manner in which this country handled that.”

Outrageously, it seems Huck can’t distinguish between denying citizens the protection of the law and requiring non-citizens to follow it.

According to the president of the immigration reform group NumbersUSA, Roy Beck, this isn’t out of character for Huck. Says Beck,

“He was an absolute disaster on immigration as governor. Every time there was any enforcement in his state, he took the side of the illegal aliens.”

Read the full article here.