June 20, 2008

YUI - getElementsBy TagName

Filed under: Javascript — chris @ 9:27 am

Similar to jQuery, MooTools and other Javascript libraries, Yahoo!’s YUI DOM utility offers upgraded element searches. finding an element by class name is nice, but what if you want to find an element by tag name?

YUI does not have a function named getElementsByTagName, but the getElementsBy will do just that.

getElementsBy(method, tag, root, apply)

The method attribute is the important one here. The tag, and root are mainly there to offer optimization by reducing the possible scope of items the method is ran against.

If all you need is elements by a certain tag name, just pass in a function into the first argument that always returns true, and make sure to pass in a tag name for argument 2 that your looking for.

For example,
var forms = yDom.getElementsBy(function(el){return true;},'form'); should return an array of form elements that can be accessed further.

If you need a more specific filter (e.g. only ‘a‘ tags with class=’selected’) you could interact with the el item in the function. If you return true, the item will be added to the list. Otherwise return false and it won’t be in the array.

A good resource for more YUI Dom fun can be found at klauskomenda.com

Developer cheat sheets

Filed under: XHTML, CSS, PHP, Javascript, SQL — chris @ 9:19 am

This is just a link to a great little list of cheat sheets that will probably come in handy. It has a hand full of sheets for Design (CSS / HTML), Programming (PHP, ASP, ROR, JavaScript…), Database (MySQL, PostgreSQL, SQL Server…), and others (Vi, htaccess, Regular Expressions).

If you’ve ever found yourself looking for that exact command on Google, one of these might be worth pinning to your workspace wall.

The Best Developer Cheat Sheets Around (from Webmasters by Design)

January 31, 2008

Tips to optimize your SQL and PHP

Filed under: PHP, SQL — chris @ 12:48 am

These tips will work for most SQL based server, including but not limited to PostgreSQL and MySQL.

1. Don’t use the DELETE statement

Instead, use an UPDATE statement to mark a row to be deleted at a later time. Build your database so that the tables have a ‘deleted’ column. Then, run the DELETE at a later time on all rows marked to be deleted. Just use a small boolean value in the ‘deleted’ column, or you could even call it ’status’ and leave room for more status’s of a row by using an integer or small character value.

This can be big. Put simply, an UPDATE statement is cheeper than a DELETE statement because your DELETE statement will force the entire table to re-index the primary keys and the indexed.

2. Reduce IO’s by reducing SELECT calls

If you use UPDATES a certain way, and your database is also using UNIQUE fields correctly, you can reduce SELECT statements.

For example, if you have a table where you want to decide wether to INSERT or UPDATE, you might try running a SELECT to check for the data first. That will ALWAYS result in two calls.

<?php
// this code will always result in two calls !!
$count = functRunQuery("SELECT COUNT(*) FROM user_table WHERE username='john';");
if ($count > 0) // then run UPDATE
else // run INSERT
?>

Instead, run the UPDATE or INSERT first without using a SELECT call if you can…

<?php
// this code could result in one call
$affectedRowCount = functRunQuery("UPDATE user_table SET username='bob' WHERE username='john';");
if ($affectedRowCount > 0) // we're done, don't need to do anything
else // didn't find any rows so run the INSERT here
?>

OR, if your table would probably see more successful INSERTs than UPDATEs do it the other way around (PHP5 method here)…

<?php
// this code could result in one call
try {
// try inserting the user without checking possible unique conflicts...
functRunQuery("INSERT INTO user_table (a_unique_username) VALUES ('bob')");
} catch {
// catch the error here if 'bob' is already in the database, and run an UPDATE instead
}
?>

If scalability is a possible issue for your application, you should always be looking for ways to reduce database calls and cut down on re-indexing.

January 29, 2008

PHP abstract class (my first impressions)

Filed under: PHP — chris @ 11:35 pm

I’ve been using PHP for a while now, but I’ve never dug too deep into it’s programming strengths. I’ve recently been thrown into using abstract classes in PHP. This article is just a first impression of what they are, and how I see them being useful in a project.

First, what is an abstract class? In not-so-technical terms, they seem to be just like a normal class. You define methods, variables, use a construct function, and can declare items as private or public.

abstract class FormBuilder {

	public $method;
	public $action;
	public $name;

	function __construct($name,$action,$method) {
		$this->name = $name;
		$this->action = $action;
		$this->method = $method;
	}
}

(more…)

November 6, 2006

PHP and ASP Includes

Filed under: PHP — Mike @ 11:16 pm

PHP and ASP are both very powerful server side scripting languages (SSL) that can add a lot of versatility and functionality to a website. You don’t have to understand much programming, however, to make use of one of their most handy components, include statements. Which language you use depends on what type of server your site is hosted on.

(more…)

October 2, 2006

Accessibility Basics

Filed under: XHTML, CSS — Mike @ 2:33 pm

Most people generally agree that websites should be made usable to the widest audience possible. Web designers are constantly trying to accommodate users with various browsers, but we must also consider a host of other possibilities.

It is likely an impossible task to make a decent website that is usable by everyone, but it is a noble effort to try. The major users we need to consider (in addition to those that we consider as “standard” users) include those using old browsers, screen readers, and text browsers, those with poor vision, those who are colorblind, users without Javascript, those using cell phones or other mobile device. (more…)

September 7, 2006

Javascript Cookies

Filed under: Javascript — chris @ 9:21 pm

Using a cookie with JavaScript is easy. With the cookie, you can save small bits of information that will allow you to create a customized experience for the user. Remember though, you should never save personal information in a cookie, like a social security number, a password, or a credit card number. Cookies are not a very secure way of transferring information. Also, don’t rely too heavily on JavaScript cookies since a viewer can turn them off. If you need to track viewer information or pass personal information, use server-side session variables. (more…)

September 6, 2006

Convert MySQL Date

Filed under: PHP, SQL — chris @ 7:02 pm

Let’s walk through the steps of creating a PHP function that will convert a MySQL date (2002-06-03) and turn that into a real world date. That way, if you ever use the date type of MySQL, you can use easily convert that date as you call it in your PHP code. It’s a small function that is driven almost solely by the substr function built into PHP. (more…)

September 5, 2006

Legibility Basics for the Web

Filed under: XHTML, CSS — Mike @ 1:20 pm

Typography is one the most important aspects of design and, yet, is one of the most commonly overlooked. Good typography is essential for good design in any medium. The key to good typography on the web is legibility. By choosing the right font or combination of fonts, using contrasting colors, proper alignment and spacing, you can achieve cleaner, more dynamic, and more effective websites. (more…)

August 9, 2006

Photoshop Menus and Palettes part 1

Filed under: Photoshop — nicholas @ 7:44 pm

Adobe Photoshop is the most important piece of software for a designer. Not because it does amazing things but instead because it provides a basis for understanding how most design software works. The method in which photoshop uses layers, applies filters and lets a user manipulate pixels is one of the most important things a designer can understand. It is because of this that we will be going over photoshop and most of its functionality piece by piece. (more…)

Next Page »