Only allow numbers in an input field in AS2

If you’ve ever created a form using ActionScript 2, you know that sometimes you want to limit what characters a user can type into a given field. For example, if you’re asking the user to enter their age, or a zip code, they certainly don’t need to use letters. So you can restrict the user to only be able to type certain keys on the keyboard when they’re in that field. Here’s how:

myinputfield_txt.restrict = “0-9″;

This tells Flash to only allow the numbers 0-9 to be typed into that field.

Run PHP as a FastCGI on a MediaTemple DV 3.5 Server

If you found this article, you probably have a reason to want to move away from mod_php.  Mine was because I was trying to operate a Magento install on a MediaTemple DV 3.5 server with periodic problems and outages.  The symptoms were that the site would slow down tremendously, to the point that requests would just hang… no response from the server.  Eventually, I was able to look at server resources in the Plesk interface and this is what I saw:

load_average_100

The CPU usage was through the roof.  And it stayed there too.  In case you’re not familiar with Plesk, you can find the CPU usage by logging into Plesk, then going to Virtuozzo >> Resources.  So I performed various upgrades to the server to try and get this system under control.  First, I installed APC (Alternative PHP Cache) which is a handy little program that caches the compiled PHP opcode to save the computer some processor cycles.  That helped a bit, but still didn’t solve the periodic problem of server slowdowns.  I decided to install php as a FastCGI to free up some resources.  Doing so on Media Temple was not as easy as I’d have liked, and the lack of documentation made it a bit of a challenge.  Here are the steps I took:

  1. You must enable root access on your Media Temple DV account.  This is required, since some of the files you’ll be creating need to go into directories where only root is allowed. Media Temple has a knowledgebase article on the subject.  Basically you click a button on your Media Temple Account Center page.
  2. Enable CGI and FastCGI on the domain where this will be applied.  Here’s how: 1. Log into Plesk  2. Click on Domains on the left side   3. Click the blue VR icon next to your domain   4. Under services check the boxes next to CGI support and FastCGI support  5. Click the OK button at the bottom
  3. Now your domain is ready to run FastCGI.  Log into your server via SSH as root.
  4. Run the commands below (without the quotes.  replace yourdomain.com with your actual domain name)
  5. “cd /var/www/vhosts/yourdomain.com/”
  6. “cp /usr/bin/php-cgi bin/”
  7. “chown -R username:psacln bin” (replace username with your FTP login name for this domain)
  8. “vi conf/vhost.conf”  (using vi or your favorite editor, create this file)
    AddHandler fcgid-script .php

    FCGIWrapper /var/www/vhosts/yourdomain.com/bin/php-cgi .php
    Options ExecCGI
    allow from all
  9. Save the file, then if you’re using SSL on this server, run this command: “cp conf/vhost.conf conf/vhost_ssl.conf”
  10. Now, restart the server: “/etc/init.d/httpd restart”
  11. If you want to see if it really worked, you can create a php page on your server with the line phpinfo();  Look through the page and you should see “Server API: CGI/FastCGI”  if so, you’re in business.
  12. Good luck.

UPDATE: Due to popular demand, I’ve written an article on how to cure 500 errors using this configuration. Click here to read.

Here’s your sign

There have been too many times when I’ve experienced a Bill Engval style “Here’s your sign” worthy experience. So I’ll share some that come to mind…

Coke Glasses from McDonalds
My wife and I were in a McDonalds. There was a sign that read “Buy one get one free Coke glasses, available in 4 colors.” We placed our order and asked for a green and a blue Coke glass. The lady asked us “Which one would you like for free?”

Street Signs
We were driving down the Atlantic City expressway a few weeks ago. We were on a two lane highway doing about 65mph. There was a sign that reads “3 lanes begin 1 mile ahead”. Now this might not seems like much… but why? What is the purpose of warning drivers that a third lane will appear? Were there accidents? Do some drivers see that third lane and swerve off the road in total confusion? Totally unnecessary use of steel and paint.

Installing APC on Media Temple DV 3.5 Server

Here are some quick and easy steps to install APC on a Media Temple DV 3.5 Server

A. Install Developer Tools and enable SSH access.

  1. Log into Account Center on Media Temple
  2. Click on the Admin button next to your domain
  3. Click on the “Root Access and Developer Tools” button
  4. Click the enable button next to Root access
  5. Click the install button next to Developer Tools
  6. This process takes 10-15 minutes to complete, so hold your britches

B. Download, compile and install APC.  Log into your system using an SSH client (Like Terminal on a Mac or Putty on a PC), then run the commands below in order.

  1. cd /usr/local/src
  2. wget http://pecl.php.net/get/APC-3.0.19.tgz
  3. tar -xvf APC-3.0.19.tgz
  4. cd APC-3.0.19
  5. phpize
  6. ./configure –enable-apc-mmap –with-apxs –with-php-config=/usr/local/php/bin/php-config –with-php-config=/usr/bin/php-config
  7. make
  8. make install
  9. echo “extension=apc.so” > /etc/php.d/apc.ini
  10. /etc/init.d/httpd restart

C. The last thing you want to do is copy the apc.php file to your web server to see if APC is running properly.  You can do that with the following command.  Make sure you replace the words “yourdomain.com” with your actual domain name for your web site.

  1. cp apc.php /var/www/vhosts/yourdomain.com/httpdocs/

Now go to http://www.yourdomain.com/apc.php and you should see the caching stats there.

Good luck.

First Monday

It’s the first Monday of the month, and it’s 2:00pm. You may wonder, what could be so inspiring as to cause a post at his very time? Well, out my open window I can hear the whine of the warning sirens for the Limerick Nuclear Power Plant. Having lived here all my life, it’s no surprise. They test the sirens every month at this same time. But I have new neighbors who live down the street. I can’t imagine what a person thinks who just moved here and is unfamiliar with the procedure. I’ll be sure to tell them, but man, what a head job if you’ve never heard that before.

Verizon FiOS IP Addresses

Recently, I called Verizon to see if I could acquire a static IP address. Apparently it’s possible, but it would ultimately cost me an additional $100 a month. I say it would “ultimately” cost me that amount because the transaction would have been more complicated than I would have liked.

First, they’d have to switch my account from residential FiOS to business FiOS. The smallest business plan was about $60 more a month than what I’m paying now. Then, the static IP was about $10 a month. For those astute with mathematics, we’re up to $70/mo now. Lastly, because I would no longer have residential FiOS service, my FiOS TV and telephone would no longer be eligible for their bundle discount, which would increase the price of that plan by about $30 a month. Needless to say, that’s a bit too much for a static IP.

So, I called Verizon’s FiOS division tech support and I asked a simple question… what is the IP address range for FiOS in my area? She couldn’t answer… in fact, she didn’t know what I was talking about. So I told her to find someone there who could answer… She couldn’t. I was appalled. I actually said to her “There has to be someone at Verizon who knows what the IP range is.” I tell you, it was like talking to a wall.

Anyway, I’d been keeping track of my router’s IP address to try and assess what the range might be on my own. I figured I’d see the last two digits hop around and I could determine a range based on the values. So for whomever cares… that isn’t working so hot. My address started in the range 71.175.1.XXX then recently hopped over to 72.94.169.XXX. These subnets aren’t even close.

Moral of the story is… if you want a static IP… go with Comcast or a DSL provider for now. Or you’re going to coughing up the funds.

Import a MySQL database on the command line

If you’ve ever tried to use phpMyAdmin to import a large sql database, then you’ve no doubt had fun slicing the file into smaller parts, or changing apache’s request timeout, or …etc…

There’s an easier, and faster way. Just upload the sql file to your server and use mysql from the command line to import the data. It’s as simple as issuing the following command:

mysql -u USER -p DBNAME < dump.sql

Where USER is your MySQL username and DBNAME is the name of the database you’d like to import into. After hitting enter, you’ll be asked for the password. Enter it and away you go.

Getting started with Drupal modules

One of the most important documents I’ve found while learning about Drupal is the node_example module.  As it’s name suggests, the node_example module gives a user example code for every aspect of creating a module and a new node type in Drupal.  If you’re the type who doesn’t like reading, this could be the chunk of code that fast tracks you to Drupal stardom.  What’s more, the good folks at Drupal update node_example for every version of Drupal that comes out.  Here’s the one for Drupal 6:

http://api.drupal.org/api/file/developer/examples/node_example.module/6/source

What do add_action and do_action do in WordPress?

add_action('foo','bar');
do_action('foo');
function bar(){
    echo "this is the bar function";
}

This would cause “this is the bar function” to be echoed to the browser. This is WordPress implementation of the Observer design pattern. In other words, the call to add_action as stated above tells the WP engine to listen for the action “foo” to be called, when it is, any function added through add_action will be called “Or notified as is the case with the Observer design pattern)

Drupal vs. WordPress, why I’m having second thoughts

I’ve been working on a CRUD plugin for WordPress for about a week. I’ve got most of what I want in there, but I hit a road block. You see, I want my content to be searchable, so I used the wp_posts table to store the header for the record, and I stored additional data in another table. In wp_posts, I changed the post_type to “contacts” for my records so as to differentiate my data from posts and pages. This is effective, and it’s searchable, however I couldn’t find a way to display my data on the front end.

What I realized is that WordPress would be great if it could load a template according to post_type. Right now, the WordPress theme hierarchy does that for Posts and Pages, but doesn’t allow programmers to add their own entries to the theme hierarchy. It would be great if I could add my own entry to the theme hierarchy that says for the post_type = “contacts” use the theme page called “contacts.php” if that doesn’t exist, use “index.php” just like it does for posts and pages.

Maybe you can do this. I’ve been unable to.

So now I’m thinking… well Drupal does that already. Based on your node type, it’ll load the content using code in your module. In fact, across the board, Drupal is made to be extensible so much more than WordPress. So I’ll make this bold statement, at the risk of sounding naive… WordPress is made for Blogging. Period. It’s designers do not want programmers to make it into anything more than a blog. As such, it does blogging better than any other blogging engine available commercially or openly.

On the flip side, Drupal is a CMS, it’s meant to be open and extensible. However, it takes quite a bit of work to get it to do anything useful. A standard install with no additional modules will leave you wanting more. For example, Drupal doesn’t even have a WYSIWYG editor by default. Recently I’ve discovered a great module for that, but it still doesn’t have the file management (i.e. uploading files and placing links into an article) capabilities that WordPress has. Furthermore, there are NO good themes for Drupal at an affordable price. Granted, I purchased the theme that I use for this blog, it wasn’t free. However it didn’t cost me a fortune either. I’ve found no such theme for Drupal. If you know of one, please do tell.