Archive for February, 2009

6 Signs of Adaptive PHP

Friday, February 27th, 2009

1. Use an associative array for function arguments

How:
function foobar ($args)
{
	$arg['hehe'] = !empty($arg['hehe']) ? $arg['hehe'] : 'a default value';
	$arg['hoho'] = !empty($arg['hoho']) ? $arg['hehe'] : 'a default value';
}
$returned = foobar(array('hehe' => 'foo', 'hoho' => 'bar'));
Benefits:
  • If you change function arguments, you may not need to change how the function is called elsewhere in your scripts
  • All arguments are potentially optional, so no need to be strategic about the order of your arguments in your function calls or declarations
  • Easy to add/remove/modify arguments and default values without worrying about function calls

2. Check if classes and functions exist for plugin detection

How:
if(function_exists('foo'))
{
	$returned = foo($bar);
}
if(class_exists('foo'))
{
	$fooclass = new foo($bar);
}
Benefits:
  • Now you can check for plugins to add additional functionality on the fly
  • Allows for deprecation and future compatibility of functions

3. Use require_once() instead of include() or require()

How:
require_once('foobar.php');
Benefits:
  • Including a script more than once creates errors and conflicts.
  • Using require_once() will prevent duplicate includes.

4. Return associative arrays from functions

How:
function foo($bar)
{
	$returnval['next'] = $bar['current'] + 1;
	$returnval['previous'] = $bar['current'] - 1;
	return $returnval;
}
Benefits:
  • Adding/Changing return values to increase the functionality of a function no longer invalidates previous calls
  • Functions can provide much more information about a function call, making the function more valuable

5. Use the little-known __autoload() in PHP5

How:
function __autoload($class)
{
	require_once($class . '.php');
}

$foo = new bar; // bar.php will be loaded automatically if not yet
Benefits:
  • No need to load everything up front
  • Only the files that are needed will be loaded
  • Simplifies object-oriented plugin detection

6. Automatically detect file locations with dirname(_FILE_)

How:
$currentdir = dirname(_FILE_);
require_once($currentdir . '/plugins/foobar.php');
Benefits:
  • Allows files to be moved around on the server without problems

Posted in Web Programming | 36 Comments »

Office Ergonomics 101

Tuesday, February 24th, 2009

Being a web developer with my own home-office has some great advantages, but at the start I did not put enough thought into how I was going to set it up. You have to remember that you will be spending a great deal of time in this office and you want to be as productive as possible. If you are uncomfortable, your productivity is sure to go down. Below are a few simple ideas to help you get the most out of your office.

  1. Monitor Height
  2. Room Lighting
  3. Chair
  4. Change positions regularly


(via http://www.working-well.org)

Monitor Height

Personally I am still using a Laptop to do all my web development work. I am not yet at the stage of getting a Desktop PC, but I would suggest that if possible get one. Desktops are made to be used for long stretches of time, and laptops don’t have this as one of their top worries. Laptops are “generally” more for short stretches to check email and keep connected while on the road.

To those of you who are forced to use a Laptop; I would highly recommend a Laptop stand to raise the monitor height. This prevents you from hunching over your laptop for 8 hours a day. I can speak from experience that this can cause extreme back pain.

A suggested monitor height is that the top of the screen be approximately eye level (maybe a little below). As well the monitor should be centered and your eyes should be 20-24″ away from the screen.

Room Lighting

Having the properly lighting in the room can make a big difference. You should avoid computing in the dark as the screen will seem quite bright and can ruin your eyes. On the other hand.. the lighting should not be too bright so that extreme glare shows up on the screen. A happy medium between the two is the best fit.

Chair

I would argue nothing is more important than a good quality chair. Imagine sitting on a stool for 8 hours a day… not something you want to try. Get a chair with some firm back support, ergonomic arm rests, and plenty of room to adjust. You want to be able to modify this chair to fit your needs.

This is one aspect I ignored for way too long. Remember don’t cheap out on this piece of furniture or you will pay in the long haul. A good chair can cost anywhere from $400 – $2000. Remember it’s no fun making money if you are in pain.

Change Positions Regularly

This is one point out of this list that maybe doesn’t seem like it belongs. We all know that being in any one position for too long can be painful. Every hour or so, consciously get up and take a little walk to get the mail, or get a snack/drink. Getting some fresh air and getting out of the chair can work wonders.

Conclusion

These are only a few guidelines I have researched, and found out from my personal experience. Please check out this Home Office Ergonomics article for more information.

What do you do to make your home-office a friendly place? Let me know in the comments below.

Posted in Uncategorized | 4 Comments »

3 Screencasts For Building Your Own jQuery Plugin

Thursday, February 19th, 2009

Recently I have been intrigued with jQuery and all that it can offer. I began by starting to learn the simple utility functions and the core features of the library. As I began to develop more and more in jQuery I realized that I would like to re-use code between different projects. This is when I decided to take a look at designing my own plugins.

It also seemed around this time that I found 3 great screencasts that each have a varying degree of difficulty. Below I list all 3 and give you a bit of a description about each:

You Still Can’t Create a jQuery Plugin? – Beginner

This screencast was done by a developer named Jeffery Way. He has long been a developer I have followed as he has an uncanny way of describing things in a simple manner.

This screencast shows you how to build a super basic tooltip plugin that uses a links title attribute. It shows you how to set defaults, pass user-specific settings, and create a new div to hold the tooltip.

View ToolTip Plugin Screencast

Building the imgPreview jQuery Plugin – Intermediate

This screencast was done by none other than James Padolsey. He is a JavaScript guru, so who better to teach us how to build a jQuery plugin.

In this particular screencast, James goes more in depth into the workings of a plugin. He deals with creating custom expressions, preloading images, and even creating callback methods.

View imgPreview Plugin Screencast

Build an Advanced “Poll” jQuery Plugin – Advanced

This screencast is done by a well known jQuery expert, Dan Wellman. He has written a book on the jQuery UI library and has a wealth of knowledge in this area.

This screencast is unlike the others as it incorporates AJAX and PHP/MySQL. It has shows you how to create a JavaScript poll widget that can be included on your site. It creates dynamic radio buttons that post back to a PHP page without a refresh, and updates the MySQL database.

The full tutorial can only be viewed if you have subscribed to TUTS+. TUTS+ is a subscription you can get for for $9/mo or $22 for 3 months. It gives you access to bonus tutorials, and source files from all tuts websites (NETTUTS, PSDTUTS, VECTORTUTS).

NETTUTS+ Screencasts and Bonus Tutorials

Personally I would highly recommend any web developers to sign up for this service as you will get in-depth screencasts / tutorials from the biggest names in the industry. For only $9/mo!!!

View Advanced “Poll” Plugin Screencast

Posted in Uncategorized | 8 Comments »

Google's New Canonical Option

Saturday, February 14th, 2009

Google released on its official blog the other day that it now has provided webmasters with a way to avoid duplicated content issues. They now will allow you to tell them which version of the content you want them to accept. A quick note that should be mentioned here is that Yahoo and Live have implemented this as well.

Now you might be wondering where this would actually benefit yourselves from an SEO standpoint. The following is a simple example:

index.php?color=blue
index.php?color=red

With the above 2 urls all we are changing is the color scheme of the website using the php $_GET variables. The problem comes because both of the above urls will have the same title tag, and content. To Google this is a great example of duplicate content.

Now using this handy new option from Google; we could simply add the following to the head of our HTML document to avoid the duplicate content:

<link rel="canonical" href="index.php" />

Now Google will know that index.php is the file with the content, and will not penalize you for any duplicate content.

This theory is relatively new, and thus it will be changing frequently as people try and get the upper hand. Some people are even suggesting that the tag may eventually become as useless as the meta keyword tag currently is.

Personally I still think avoiding duplicate content without using this tag is preferable, but if you have no choice take a look at it.

Further resources to expand your knowledge on this topic:

Posted in SEO | 4 Comments »

20 Web-Related Twitterers you need to follow!

Thursday, February 12th, 2009

Below is a quick list of some of the people I regard highly on Twitter (@brenelz), and can add plenty of knowledge to your day!

@nettuts

a Nettuts writer named Jeff Way that does AMAZING screencasts and keeps you up-to-date on netttuts

@collis

On the same note as Nettuts Collis founded the Envato Network which is what NETTUTS belongs to.

@jamespadolsey

a young mastermind that hails out of the UK – known for great jQuery work

@davidwalshblog

a mootools developer who doesn’t like all the publicity jQuery gets :p

@chriscoyier

a great CSS guru with excellent screencasts and tries to keep things on the lighter side

@mlane

An enthusiastic graphic designer that finds the great posts on the web

@jeffhui

Jeff is a Django expert that recently did a great screencast on NETTUTS.com.

@ShaneSponagle

A full time web developer that is crazy about MODx.

@iamkhayyam

Has a nose on the net for great articles and RT your stuff plenty :)

@cristianvasile

SEO, Tech, Webdesign, Geek, JQuery, CSS, and Internet Marketing guru

@cameronolivier

great web designer that loves to strike up a good conversation with another twitterer

@briancray

excellent marketing consultant, also known for PXtoEM.com as well as NearbyTweets.com

@naldzgraphics

a graphic designing twitter addict with a new blog

@RafalLos

can’t have all designers so here is a security expert who is a great person

@andysowards

someone like me – a hardcore developer / programmer

@DrewDouglass

great down to earth guy that does some screencasts on ThemeForest and also has a blog at Dev-Tips.com

@jorenrapini

always ready to help you out with any CSS / JavaScript problems you are having

@jasonatennui

very knowledgeable programmer with a great blog

@ambermacarthur

known for various gigs such as Call For Help / TWIT – tremendous usability expert

@Darcy_Lussier

Lastly, I got to throw in a plug for a local developer here in Winnipeg. D’arcy is a great ASP Developer and does consulting on the side.

Posted in Uncategorized | 16 Comments »

 
connect with me!