Here’s my first video segment.
Shot in 720p with my new Panasonic DMC-ZS3.
PHP has some pretty handy superglobal arrays such as $_SERVER which gives you all sorts of great info about the server and the executing script. One such variable is $_SERVER['DOCUMENT_ROOT']. The PHP manual describes this variable as the document root directory under which the current script is executing, as defined in the server’s configuration file.
If you are using IIS (a windows webserver), there is a slight problem if you want to use this variable. IIS is lame and doesn’t set this variable most of the time!! Very frustrating to say the least! Luckily, there is a little bit of PHP code that can set this variables for you if you have the misfortune of using a IIS based server. Since $_SERVER is just an array, we are free to manipulate (or in this case add) variables directly to it.
OSX 10.6 Snow Leopard comes bundled with Apache 2 and decent build of PHP 5, but .htaccess files won’t work by default. If you aren’t familiar with Apache, .htaccess files are a pretty cool way to customize or overwrite settings on a per directory basis. Things I’ve used .htaccess for include mod_rewrite rules (for pretty URLs), increasing the PHP upload filesize, and pointing log files to a custom destination.
There is a pretty simple change you can make to enable the use of .htaccess files. We’ll be using the command line for this one, but you should already love the terminal right? Fire up your terminal program of choice and type in this command:
cd /etc/apache2/users
I just came across an interesting MySQL issue while working on a project. By default, if you create a table in MySQL it will provide a case insensitive collation to the table. What that means is checking a text field in the database for string and STRING would both equate to true! That might not be the ideal situation if you want to preserve case sensitivity.
For example, say I have a users table that stores login info for a website, each row has a username. If the default case insensitive collation was used, the following SQL statements would both return the user row.
/* returns 1 row */ SELECT * FROM users WHERE username = 'justin'; /* returns 1 row */ SELECT * FROM users WHERE username = 'JUSTIN';
The other day an interesting question was posted to the WebAssist forums (full thread). Basically, a user was getting some JavaScript errors when adding PowerGallery to an existing page in their site. The error was complaining about the $() function. For those unfamiliar with MooTools, the $() function is a quick way to get a reference to an element by its id – instead of using document.getElementById() – and extend it with some MooTools magic.
After using Firebug to track down the exact error, it was pretty clear what was going on. The user’s page already had jQuery on it! When they added in their PowerGallery code, it was causing a conflict. Luckily, MooTools has a way to deal with this issue. Instead of using $(), use document.id(). This function was added as part of the MooTools Dollar Safe Mode updates made in version 1.2.3. Since jQuery defines the $() function too, MooTools wasn’t redefining it (to help not break jQuery).
The fix was to replace all $() function calls with document.id() in the gallery JavaScript. Using some PowerGallery code as an example:
//change this this.wrapper = $(el); //to this this.wrapper = document.id(el);
I never recommend using more than 1 framework if you can avoid it and I’d always pick MooTools as my one and only!
Not too long ago, crazy multi dimensional arrays were all the rage. I mean it’s pretty clear people[0][3] gives me the first name for a person in my array right?? Yeah, um no. Something like people[0].firstName is quite a bit clearer – give me the first name of the first person in my array. This is just a reminder than in you can use keyed objects (or arrays) instead of relying on numeric indexes for everything. Its surprising, but I still see cryptic indexed arrays used even today in coding.
Here’s the cryptic way:
var people = [ [100, 'pgriffin@spoonerst.com', 'Griffin', 'Peter'], [101, 'wretchedwomb@spoonerst.com', 'Griffin', 'Stewie'] ]; p1 = people[0][3]; //first name for Peter p2 = people[1][1]; //email for Stewie