Skip to content

Posts from the ‘Web’ Category

16
Jan

Trust Nobody

One important lesson when developing applications (I’m focusing on websites here, but this applies to all types of applications) is to ditch user trust.

In a nut shell, do not trust any input you receive from a user. Seriously, do not assume it is clean and good, treat all user input (whether it be cookies, text from a text box or something else) as potentially dangerous. Check it, filter it, escape it.

Never let input from a user go straight into your database or on to a page without it being filtered. If you let it straight into the database you leave yourself open to SQL Injections and other attacks.

This is why you should clean up all input. (Click for bigger version)

Keep that in mind when you are developing an application, any and all user input needs to be checked out, torn to pieces, ripped apart, put back together before being considered safe.

3
Jan

Striped Backgrounds

Just a FYI for all of you web designers out there about pretty striped backgrounds.

I’m actually unsure if this is a LCD screen thing, or all of them in general. I actually don’t remember it from my old CRT screen, but let’s face it, who has a CRT these days? (OK, I’ll admit it I have one…)

Some websites like having a striped background, with an image like the following.

It does look pretty neat, and when it’s full-paged background it can give a webpage an interesting look.

The trouble is, scrolling. On screens like mine images like that do not work well when scrolling. The background does this weird flickering thing when scrolling along, and it does mean the website looks less cool, and more cheap.

I’d seriously advise you skip the tiny little stripes in background images. Try larger ones, they can look pretty good as well. Or, you know, a solid colour doesn’t hurt either.

30
Dec

Add a CSS class to any disabled button

This adds the class of “myclass” to any input with a type of “button” that is marked as disabled. This way you can easily style disabled buttons across a multitude of browsers.

$('input[type=button][disabled=disabled]').each(function(){
	$(this).addClass('myclass');
});
22
Dec

LTrim, RTrim and Trim JavaScript Functions

These are some functions I found online, and it drives me mad having to find them each time. I didn’t write these, but they’ve been passed around a lot. They’re useful if you need some basic JavaScript functions.

Left Trim
Pass it a string to trim and any characters that should be trimmed from the left. chars can be left empty to trim spaces.

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

Right Trim
Works exactly the same as the left trim, just on the right.

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

Trim
Combines the left & right trim to have a full trim functions.

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}