PHP isDate, checks for valid date, redux 3

I just can't leave well enough alone. This third iteration of the PHP isDate function is a little more concise, and makes changing acceptable formats a little easier. The function signature stays the same, accepting a date, and the expected format of the date, using PHP date expressions.

#accepts a date, and a date format (not a regular expression)
function isDate($d, $f='%d-%m-%Y %H:%M'){
	$dateFmtRE = array(
		'/\//' => '\/',
		'/%d|%e/' => '(0?[1-9]|[12][0-9]|3[01])',
		'/%m/' => '(0?[1-9]|1[012])',
		'/%g|%G|%y|%Y/' => '(19\d\d|20\d\d)',
		'/%H|%I|%l/' => '([0-1]?\d|2[0-3])',
		'/%M/' => '([0-5]\d)');
	if (empty($d))  return true;

	#convert Unix timestamp to a std format (must not include regular expressions)
	if (preg_match('!\d{5,}!', $d))
		$d = strftime($f, $d);

	return (
		#does %d match the regular expression version of $f? if it does m/d/y are in $x
		preg_match('!^' .preg_replace(array_keys($dateFmtRE), array_values($dateFmtRE),$f) .'$!', $d, $x)
		&& (checkdate($x[2], $x[1], $x[3]) || checkdate($x[1], $x[2], $x[3]) || checkdate($x[3], $x[1], $x[2]))
		?true :false);
}

Web Hosting at A Small Orange

Looking for web hosting can be a real pain. Basically you have 10 or so really huge players, who claim to offer no limits on storage and bandwidth, which means every server is just poised to explode as everyone dumps all their crap on there. And then you have literally thousands of small timers, with questionable ability to support their users over the long-haul.

Years back when I was host-hunting I came across A Small Orange, and have been with them ever since. They have been consistently excellent. The only limits on accounts are the physical limits on disk space, and bandwidth. This is actually a good thing, as it means your server is much more likely not to get over burdened by an errant tenant. There are no other limits. Have as many email addresses, domains, sub-domains, databases, and whatever else you can think of, including full command line (SSH) access. As long as you stay within the disk and bandwidth limits.

The best feature is the active forum community, who are usually very willing to help out; and the user support, which is typically extremely fast.

So, it you're looking for a host, sign up at A Small Orange, and get a 15% discount.

Migrate from Subversion to GIT on Windows

There's a lot of information describing how to migrate from Subversion to GIT, but very little which describes the process under Windows. In particular most references assume that you can reference the Subversion repository using file:// which is currently not the case. You need to access the Subversion repository using the svn:// protocol.

The instructions below assume you're using TortoiseSVN, but the process should be basically the same if you are not.
Read more...

Excel: Easy to Maintain List of Values

Creating select lists in Excel is pretty easy. But creating them so that it's easy to add new values is not so obvious. Usually you define a range around the list values, and reference the range from the list definition. The problem with this approach is that is you happen to insert a new value at the end of the list, you need to redefine the range. So you need to remember to insert new values in the middle of the list, which depending how you setup your reference lists, might cause other problems.

This little snippet allows you to simply add new values anywhere on the list, including at the end, without having to redefine anything.
Read more...

JavaScript Ajax Request is always UTF-8

Update 11-Jul-2010: As a result of this ticket, jQuery contentType documentation is now explicit about UTF-8 being used to send data to the server in the Request header.

Dealing with character sets in browser-based applications can be a real pain. You have to ensure all levels of infrastructure are set to use the same character set. For browser oriented applications that means the browser/HTML, JavaScript code, and whatever server side infrastructure you have (code and database for example), all need to be configured correctly. If you are writing a new application, the choice is usually easy: use UTF-8. In fact this shouldn't even be a choice for new apps -- just use UTF-8. However, there are cases where UTF-8 is not an option. Perhaps you're working on legacy code, or are writing a component that will be used by others, and so you need to accommodate a variety of character sets. The later is the case with BlogIt. Recently I added the ability to perform administrative functions over Ajax, and so began a long journey of pain, and a single major lesson...
Read more...

BlogIt skin, Minimous

Minimous is a port of a skin designed for Posteous. It's a very simple, two column skin, with minimal graphics, and very basic layout. It does provide a number of theme colors, and also allows the admin to specify the page width.

BlogIt Release 1.5.0, Ajaxy Goodness

Finally version 1.5 of Blogit is released, and bring with it all new Ajaxy goodness. All actions are configurable to be Ajax based, and you can also choose to have the option to select either Ajax or Normal mode for actions.

The advantage of using Ajax is the speed that it brings to the daily workflow of the blogging system. Posting and editing blog entries is now an instant operation, rather than the normal processing time of 1-2 seconds. That doesn't sound like much, but somehow the psychological effect is significant. Of course, the ability to Approve/Unapprove, and even block commenter IP addresses instantly is nice as well. All in all this release makes for a really nice experience improvement for blog administrators/writers.

Big thanks again go out to SteP for a lot of testing, particularly around international character set testing. There were a lot of thorny, tedious issues dealing with character sets, and SteP's help was critical to getting this release out. Thanks.

Check out the PmWiki BlogIt project page for a full list of changes, and installation information.

Ajax coming to a BlogIt near you soon...

Version 1.5 of BlogIt is now functionally complete. Remaining is some skin enhancements to support Ajax editing, and a lot of testing -- if you want to help test the new version drop me a line.

My goal has been to try and release every 4 weeks. This release is behind that schedule.Why? Partly due to external 'real-life' factors, but also because I got carried away with features. All very worthwhile, but at some point you need to balance time against actually releasing, even when working on a hobby project. So, I'll have a little more focus on the four week timeframe next time around. I'm not trying to be exact here, but a little more focus is a good thing.

BlogIt migration from Subversion to Git

The full history of BlogIt source code is now available on GitHub. You can find and download the current release, all prior releases, and also the most recent 'stable' development release. Here's a quick run down for those not familiar with GitHub:

  • Production and Development Releases: Use the Branch pull-down to select which code base to view. You'll always see the most recent production version when you first visit the page.
  • Past Versions: Each version of BlogIt is identified by a tag. Use the tag pull-down to select a specific version.
  • Download: After selecting a branch/version use cunningly the hidden "Download Source" link near the top right, to download a zip or tarball.

Read more...

Onwards with the Ajaxification of BlogIt

Just a quick update to let you know that the Ajaxification of BlogIt is moving forward pretty well. Most recently added was some full Ajax on comment editing. You can see it in action if you check out one of the test blog entries on the BlogIt test site. Login using password "blogadmin", click "quick edit' next to a comment, and see the wonders ensue!