Always Get Better

Never stop looking for ways to improve

February 15th, 2010

Now that the rebellion against IE6 has hit mainstream, a brave new world of CSS3 and HTML5 has been opened to web professionals.

Beware Mixing Purposes
CSS is intended to define the appearance of elements, not their behaviour. Be very careful about “overloading” CSS to accomplish tasks best performed by JavaScript.

A popular example of poor CSS usage is drop-down menu lists. Some web programmers use CSS’ :hover selector to instruct the web browser to display sub-navigation when the user hovers over a list item.

ul#menu li:hover ul { display: block; }

This is much better accomplished using a touch of jQuery:

jQuery("ul#menu ul").css({display: "none"}); // For Opera
jQuery("ul#menu li").hover(function(){
jQuery(this).find('ul:first').css({visibility: "visible", display: "none"}).show(268);
},function(){
jQuery(this).find('ul:first').css({visibility: "hidden"});
});

Not only is this example less dependent on consistent web browser support for the CSS :hover selector, we’ve even thrown in a spiffy little roll-out animation.

Keep It Simple
The nth-child selector is one that stands to be abused by overzealous developers. Imagine this: change the display of every nth element as defined through an algebraic expression.

Why is this a bad thing? CSS is run in the same memory space as the general web page – that’s why it’s so fast. JavaScript tends to be isolated; meaning if you make an infinite loop in JavaScript, the web browser will eventually stop it from running. If the same thing happens in CSS, your web session is probably toast.

Separate Logic from Presentation
CSS was a leap forward because it separated presentation from structure; rather than programming font and colour elements, designers were able to explicitly control the way their web page appeared on screen. HTML was being used to serve the purpose CSS was designed to cover.

More recently, CSS has become a crutch to enable functionality better suited for JavaScript. When unsure about which to use, ask yourself: Does this solution affect only the display, or is some action happening?

January 24th, 2010

When running a default installation, WAMP Server’s Apache crashes when installing X-Cart. The error happens immediately after setting up the MySQL tables and is caused by the curl extension in PHP.

To resolve, click on the WAMP Server icon in the task tray, go to Apache -> Version -> Get More. Download one of the 2.0 series Apache servers and install it.

Repeat the process for PHP; download one of the 5.0 series PHP versions and install it.

Switch WAMP Server to the new versions and run the install again – it should work with no problems.

February 7th, 2009

It couldn’t be easier to convert a string to a number in Flex Actionscript. The language doesn’t have (or need) an atoi() function as seen in languages like C – it’s as simple as creating a cast:

var myString:String = “15″;
var myNum:Number = Number( myString );

The framework will convert any data type, not just strings. If it is unable to do so, it will return 0 (for ints) or NaN (for floating point).

November 29th, 2008

Anyone half-serious about running a large blog knows that search engine ranking is critical to getting properly indexed. Over 90% of the traffic to Always Get Better originates from search engine traffic – therefore the ease of which Google (among others) is able to index this site is the life-blood of its continued success.

WordPress is a terrific platform with out-of-the-box support for many of the critical elements necessary for site building: CSS layouts, RSS feeds, track backs. But the glaring problem with WordPress is the default title format: “Blog Name > Blog Archive – Post Title”. What is that!?

Many search engines only catalogue the first several characters of web page titles. If the title of your post is at the end of the page title, it may get cut off in favour of your blog’s name!

The simple solution is to reverse the code as explained at the WordPress garage (and quoted below for convenience):

You can switch it through the use of plugins, but if you want to avoid using another plugin you can fix this in the header.php file. Find the code that starts with <title>, and replace what is currently there with this:

<title><?php if ( is_single() ) { ?> <?php wp_title(''); ?> &raquo; <?php } ?><?php bloginfo('name'); ?></title>

November 12th, 2008

Aside the from the bloated abomination that is Acrobat Reader, I can confess that I am a proponent of software from Adobe.  As a long time user of Photoshop and Illustrator, I have always found their products to be powerful and usable.

Recently I’ve taken up time creating applications with a trial version of Flex Builder.  This is the first time I have ever really given a product a full test drive during the trial – normally it gets used once or twice then forgotten about.  Flex Builder is a solid product, built on a great platform.  I can’t get enough of it.

Since I truly like this software, I decided to go ahead and plug in my credit card information to get myself a full copy.  When I got to the Adobe online store though, I was sadly let down by my experience.

I am in Canada but for some reason my existing account has ‘United States’ listed as my address.  Not a big deal, I’ll just change it, right?  No – it is not a changeable field.  You can change your region on the Adobe site but that doesn’t affect your account at all.  If I can’t change my country, I can’t order online because my credit card information will be wrong.

Not a big deal – I called the sales phone number and explained what my problem was, hoping to order the product by phone.  You can’t order software for download by phone, they will only ship it to you.  I’d much rather just have the serial number, so I am transferred to the online support department to get the country of my account changed.

Once I noticed my phone timer had reached 37 minutes, I hung up and tried searching the Internet for a solution to Adobe’s problem.  I found this blog: http://www.gurtle.com/ppov/2008/10/17/adobe-id-customer-service-fail/

Basically, you can’t change your country.  The only way to do it is to create a new account with the correct country.  It would have been nice if the gentleman in sales had known to tell me that instead of letting me wait on hold for an indefinite period of time.

Really, the reason I am most angry is because the muzak that plays on Adobe’s hold line is not just obnoxious, it’s too loud.  Right now my head is ringing and I still have no Flex Builder to play with.

November 9th, 2008

When creating components in Flex, designers sometimes need to attach events to the main stage. Unless the application has reached creationComplete, the stage property of custom components will be null.

If you need to, for example, attach a MOUSE_MOVE event to the application stage from a component that doesn’t include a creationComplete override, you have two options.

Wait for Event.ADDED_TO_STAGE

addEventListener( Event.ADDED_TO_STAGE, function(e:Event):void
{
stage.addEventListener( MouseEvent.MOUSE_MOVE, myMouseMoveEvent );
});

Attach Through the System Manager Object

The system manager parents all displayable elements within the Flex application. It is an elegant way of accessing the stage through custom flex components which have not yet been added to it.

systemManager.stage.addEventListener( MouseEvent.MOUSE_MOVE, myMouseMoveEvent );

November 8th, 2008

If you have threaded processes called by your ASP.NET code, and those processes crash, your site may start giving Service Unavailable errors.

Use iisreset to quickly get back up and running.

In order to prevent this from occurring at all, I recommend putting try { } catch { } around any statements inside a threaded function.