Friday, December 23, 2005

GROUP BY techniques

Useful GROUP BY techniques (source: Jeff's Blog (SQLTeam hosted)) for SQL Server developers. Rather than grouping unneccesarily columns, use a derived table. i.e. (SELECT ... FROM ... WHERE ... GROUP BY ...) AggregateTableName. Plus don't group expressions, but the columns that make up the expression.


Tags: , ,

Tuesday, December 20, 2005

PHP Email Encode

Function to encode an email address to help protect against spamming.

function mailto_link($email)
{
 $encoded = bin2hex($email);
 $encoded = chunk_split($encoded, 2, '%');
 $encoded = '%'.substr($encoded, 0, strlen($encoded) - 1);
 $htmlencoded = substr(chunk_split(bin2hex(" $email"), 2, ";&#x"), 3,-3);
 return "<a href=\"mailto:$encoded\">$htmlencoded</a>";
}

Takes an email address as the parameter and outputs an encoded mailto link. You could use this while looping through email records in a database for example.

<?php echo mailto_link("user@example.com"); ?>

Tags: ,

Sunday, December 11, 2005

PortableApps.com

PortableApps.com is the new site for Portable Firefox / Thunderbird / FileZilla / OpenOffice etc. All of the applications on this site can be run from an external flash/hard drive. No installation neccessary. Just unzip and go. More applications will be on the site in the future. From operating systems and office suites to image editors and games.


Tags: ,

Tuesday, December 06, 2005

Extensions for Web Developers (Firefox / Internet Explorer)

A list of Firefox extensions that are useful for web development. The Web Developer Extension is a 'must have' for web developers (i.e. if you could only have one, it would be it). Some haven't been updated for Firefox 1.5 (or you may have to go to the extension authors homepage to get an updated version).

Update (07 Dec 2005): Add N Edit Cookies, DevBoi, Screen grab!, MozRef Sidebar.
Update (20 Jan 2006): Console², FireBug, View Cookies, View Rendered Source Chart.
Update (25 Jan 2006): IE View Lite.

And for Internet Explorer:

There may be others for Internet Explorer that I do not know of (I have also not listed anything that you have to pay for).


Tags: , , , ,

Monday, December 05, 2005

getElementDimensions (JavaScript)

This function returns the dimensions of an element (left, right, top, bottom, width and height). You can pass on either a string (which gets the element by ID), or the element itself.

function getElementDimensions(el)
{
 if(typeof(el) == "string")
 {
  el = document.getElementById(el);
 }
 if(!el || !el.offsetParent) return false;
 var left = el.offsetLeft, top = el.offsetTop, width = el.offsetWidth, height = el.offsetHeight;
 do
 {
  el = el.offsetParent, left+= el.offsetLeft, top+= el.offsetTop;
 }
 while (el.offsetParent);
 return {"left" : left, "right" : left + width, "top" : top, "bottom" : top + height, "width" : width, "height" : height};
}

Example use:

var foo = document.getElementById("foo");
var fooDim = getElementDimensions(foo);
if(fooDim)
{
  alert(fooDim.left);
} 
var barDim = getElementDimensions("bar");
if(barDim)
{
  alert(barDim.top);
} 

Tags: , ,