JavaScript 101 – Private Variables

Funny things happen in the course of piecing together solutions in this field. Programmers have a tendency to throw their hands up in the air when they get to the end of a week and they can’t quite figure out a concept, and the problem is compounded when looking at programmers who don’t take the time to actually learn the new idioms of a language before getting into the position of writing production code.

JavaScript lends itself to this type of behavior. It has Java in it’s name, and it looks a lot like C or Java syntax, so it attracts a lot of OO type behavior. Little do these people know the language should be written more like lisp and less like Java. Continue reading “JavaScript 101 – Private Variables”

canPlayType is nearly useless

http://www.w3schools.com/tags/av_met_canplaytype.asp

Go ahead, look at the documentation for this function. For those of you who don’t like to follow links, you would be looking at the documentation for a function attached to any html5 video element. It accepts a mimeType, a set of codecs and well… here is the the rub. What would you expect it to return?

I expected a boolean. The guy who worked on this problem before me tested it as though it were a boolean…

if (video.canPlayType(mime + ";codecs='" + codec + "'"))

In fact, after polling the friends around me, every single one of the 15 people I have asked expected the same. In reality it returns either “probably”, “maybe” or “”. This is probably the most non-committal function in the history of time.

Further, imagine my surprise when I opened Safari up, yes I’m on a mac, and passed it 20 different combinations of videos and codecs, all of them return something odd – “maybe”. Not only did this happen for mpeg, which is absolutely supported, but it also returned maybe for wmv and avi files, which were absolutely not supported. I can only hope that this function works better on the iPad/iPhone and Android devices.

Until then, I’m going to be using something else.

Intro to the WordPress Settings API

API Documentation is always going to be a hell that I do my best to avoid. I learned early on when working with SourceSDK that documentation for much of anything worth a damn would be hard to find and the new WordPress Settings API (SAPI) is in the same ballpark. This was actually added to the 2.7 release of the trusty blogging / CMS software, but it was (was? is!) not well documented and has some really dope capabilities and features that you should all take advantage of.

So what are you waiting for? Time to rewrite a plug-in and learn the new API!

Continue reading “Intro to the WordPress Settings API”

My Forums

I absolutely hate advertisement bots, and i wish that their inventors would be blessed with a flesh eating virus. I have been fighting a losing battle over the last two years to regain control over my forums, claiming it back from the shitty bots, and i think i have finally figured things out.

Below is the beginnings of a script that you can run on a semi regular basis and keep your PHPBB3 Databases cleaned of ridiculous bullshit landing on your forum. Just remember to log in from time to time to resynchronize your statistics.

Continue reading “My Forums”

Grinding My Gears – Stored Passwords

WASHINGTON - FEBRUARY 12:  James Locher III (C...

Personally, I don’t think that software needs to be so god damned difficult to make. I mean, if you follow the “standards and practices” that you see standardized and practiced by the broad majority of today’s websites you could come to no other conclusion.

Three days ago i signed up on a website, one that I am quite sure has been around for a good portion of the web epoch as they tout themselves as being 2.0 compliant – whatever the fuck that means — and low and behold I was sent something that I never in my life fucking wanted. Never in my life would I ever need to be sent something that I had given to them. I don’t need it, I don’t want it as it is a sure sign of an amateur dev team and the fact that it exists is almost enough to cause me to want to scream.

My god damned password.

Continue reading “Grinding My Gears – Stored Passwords”

Optimize your Tables!

One thing that seems to always irritate me when im trying to organize my backups together is how the file sizes bloat over time. You can, and probably should look into optimizing your tables but for those of you who dont have the time or the will power to care to do it in any other method if you place this function at the top of your automated backup script and simply call it appropriately you will be able to automate the process of optimizing all tables that dont meet your threshold and or maximum free space requirements.

You can just set up a cron job to call your PHP scripts and it should take care of things from there.

$_CONFIG['threshold'] = 0.01;
$_CONFIG['maxfreedata'] = 102400;

function optimizeDatabase($host, $user, $pass, $dbase)
{
	global $_CONFIG;

	$mysqli = new mysqli($host, $user, $pass, $dbase);

	if (mysqli_connect_errno())
	{
		printf("Connect failed: %sn", mysqli_connect_error());
		exit();
	}

	if ($result = $mysqli->query('SHOW TABLE STATUS WHERE '.
		'(Data_free / Data_length) > ' . $_CONFIG['threshold'] .
		' AND Data_free > ' . $_CONFIG['maxfreedata']))
	{
		print 'Optimizing Database: ' . $dbase . "n";
		while ($row = $result->fetch_object())
		{
			printf("%-25s %8d %8dn", $row->Name,
				$row->Data_free, $row->Data_length);
			$mysqli->query('OPTIMIZE TABLE ' . $row->Name);
		}

		$result->close();
	}
	$mysqli->close();
}

optimizeDatabase('localhost', 'User', 'Password', 'Database');