Test Post with Tweet

Test Post with Tweet

new line added.

Silverlight: Setting Wait Cursor on Disabled Controls

For operations that take a long time, you’ll want to notifiy users that something is happening, and perhaps prevent them from interacting with the application during that time. One method is to make a semi-opaque rectangle covering the whole control, with a loading message of some kind.  But I wanted to just disable the controls and change the cursor to the Wait cursor.  I tried setting IsEnabled=false and Cursor=”Wait” on my User Control, to no avail. It looks like you cannot change the cursor on disabled controls; it will just remain the Arrow cursor. And you can only set IsEnabled on controls, not containers such as Grids, which contain numerous controls. My solution was to wrap the grid in a Content Control and set IsEnabled=false there. Then set the cursor property to the parent User Control (the opposite wouldn’t work, since the Disabled would propagate down). This way you’ll need to set two different properties, but you won’t  have an extra rectangle or canvas in your page.

Integrating PHP Command Line Scripts with Existing Web Projects

After reading the post on Johan Mares site about the PHP command line interface, I thought I would indulge in the details how I’ve been using the PHP cli for some of my web based applications.

First, some of my web apps have multiple configuration files which are determined by the $_SERVER['HTTP_HOST'] value. If (stricmp( $_SERVER['HTTP_HOST'],’compiledweekly’) ) { // then I load compiledweekly config file }. So with that in mind, I had to add to the top of my cli scripts the following line:

$_SERVER['HTTP_HOST'] = ‘compiledweekly.com’;

This required me to have to edit the command line script every time i used it with another site. Here’s the trick: pass arguments to your command line so your script can parse them. Here’s how I did it to also include a verbose mode.

	if( count($argv) > 1 )
	{
		for( $x = 1; $x < count($argv); $x++ )
		{
			switch($argv[$x])
			{
				case '--verbose': { // Print results to std out
					$Verbose = true;
				}; break;
				case '--host': { // Print results to std out
					$_SERVER['HTTP_HOST'] = trim($argv[$x+1]);
				}; break;
			}
		}
	}

	if( $Verbose ) echo "Starting script...\n\n";
	// Continue with your script below

So with the following example I can run my script for my compiledweekly.com site with verbose information. Example:

/path/to/script.php --verbose --host compiledweekly.com

Now if you use your php script in a cron task, don't include the --verbose and make sure you check the $Verbose flag before printing any results. Don't forget to add to the end of the command line " > /dev/null 2>&1" minus the quotes, this sends any std out and std error messages to a black hole.

If your command line script is saved in a web accessible folder, here's a line you should add to the top so no web browser can execute your script:

if( php_sapi_name() != 'cli' ) die('Access denied.');

This will take your command line apps to a new level while giving you the ability to use existing web code.

Converting URL to Local File Path in Batch MySQL INSERT Query Using SUBSTRING_INDEX() and CONCAT()

I wanted to quickly take a URL (e.g. http://www.compiledweekly.com/somefolder/somefile.ext) and translate it to the local path (e.g. /home/user/public_html/somefolder/somefile.ext) while inserting multiple records into a new table. My first thought was to select all the records, use PHP to trim off the path, then insert the new record in the new table. There’s a better answer, use SUBSTRING_INDEX() and CONCAT() with a INSERT INTO table SELECT statement.

INSERT INTO new_table
SELECT CONCAT(‘/home/user/public_html/somefolder/’, SUBSTRING_INDEX(s.url, ‘/’, -1)) AS local_path
FROM source_table AS s
WHERE …

It does the job with out having to write a single line of PHP code!

Updating XP and Vista to support WebDAV Web Folders from Apache – Patch KB907306

If you are familiar with WebDAV or even Subversion and use Windows XP/Vista, you will appreciate this tidbit of information.

You can browse a WebDAV server in Windows XP and Vista using Windows Explorer. There is a problem though, Windows XP and Vista will try to use NTLM authentication (Active Directory) to authenticate with the server. If you configure your Apache WebDAV server with either no, basic or digest authentication, then you will hit a roadblock. Luckily Microsoft created the KB907306 patch. Unlucky for myself, other websites refer to the patch number missing the last digit ‘6′. This will drive you crazy when you know you should be able to copy/paste the KB number in Google and quickly find the download page on microsoft.com. Other documents will say to search for KB90730. You should be searching for KB907306. You can search for “Software Update for Web Folders“, but you will also get a lot of other search results that are not nearly as helpful. Hopefully this blog post will save some folks the aggravation.

Now that you’re here, there is no need to search! The patch is available from the following link: http://www.microsoft.com/downloads/details.aspx?FamilyID=17c36612-632e-4c04-9382-987622ed1d64&DisplayLang=en

PHP Function HTTP Status Code Value as String

I’ve been working with the php CURL library and found that it would not return an error if the server returned a 500 error. After looking up 3 different status codes that I wasn’t very familiar with, I created the following function. It is very complete and includes additional WebDAV, Apache and Microsoft codes.

function http_status_code_string($code, $include_code=false)
{
	// Source: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

	switch( $code )
	{
		// 1xx Informational
		case 100: $string = 'Continue'; break;
		case 101: $string = 'Switching Protocols'; break;
		case 102: $string = 'Processing'; break; // WebDAV
		case 122: $string = 'Request-URI too long'; break; // Microsoft

		// 2xx Success
		case 200: $string = 'OK'; break;
		case 201: $string = 'Created'; break;
		case 202: $string = 'Accepted'; break;
		case 203: $string = 'Non-Authoritative Information'; break; // HTTP/1.1
		case 204: $string = 'No Content'; break;
		case 205: $string = 'Reset Content'; break;
		case 206: $string = 'Partial Content'; break;
		case 207: $string = 'Multi-Status'; break; // WebDAV

		// 3xx Redirection
		case 300: $string = 'Multiple Choices'; break;
		case 301: $string = 'Moved Permanently'; break;
		case 302: $string = 'Found'; break;
		case 303: $string = 'See Other'; break; //HTTP/1.1
		case 304: $string = 'Not Modified'; break;
		case 305: $string = 'Use Proxy'; break; // HTTP/1.1
		case 306: $string = 'Switch Proxy'; break; // Depreciated
		case 307: $string = 'Temporary Redirect'; break; // HTTP/1.1

		// 4xx Client Error
		case 400: $string = 'Bad Request'; break;
		case 401: $string = 'Unauthorized'; break;
		case 402: $string = 'Payment Required'; break;
		case 403: $string = 'Forbidden'; break;
		case 404: $string = 'Not Found'; break;
		case 405: $string = 'Method Not Allowed'; break;
		case 406: $string = 'Not Acceptable'; break;
		case 407: $string = 'Proxy Authentication Required'; break;
		case 408: $string = 'Request Timeout'; break;
		case 409: $string = 'Conflict'; break;
		case 410: $string = 'Gone'; break;
		case 411: $string = 'Length Required'; break;
		case 412: $string = 'Precondition Failed'; break;
		case 413: $string = 'Request Entity Too Large'; break;
		case 414: $string = 'Request-URI Too Long'; break;
		case 415: $string = 'Unsupported Media Type'; break;
		case 416: $string = 'Requested Range Not Satisfiable'; break;
		case 417: $string = 'Expectation Failed'; break;
		case 422: $string = 'Unprocessable Entity'; break; // WebDAV
		case 423: $string = 'Locked'; break; // WebDAV
		case 424: $string = 'Failed Dependency'; break; // WebDAV
		case 425: $string = 'Unordered Collection'; break; // WebDAV
		case 426: $string = 'Upgrade Required'; break;
		case 449: $string = 'Retry With'; break; // Microsoft
		case 450: $string = 'Blocked'; break; // Microsoft

		// 5xx Server Error
		case 500: $string = 'Internal Server Error'; break;
		case 501: $string = 'Not Implemented'; break;
		case 502: $string = 'Bad Gateway'; break;
		case 503: $string = 'Service Unavailable'; break;
		case 504: $string = 'Gateway Timeout'; break;
		case 505: $string = 'HTTP Version Not Supported'; break;
		case 506: $string = 'Variant Also Negotiates'; break;
		case 507: $string = 'Insufficient Storage'; break; // WebDAV
		case 509: $string = 'Bandwidth Limit Exceeded'; break; // Apache
		case 510: $string = 'Not Extended'; break;

		// Unknown code:
		default: $string = 'Unknown';  break;
	}
	if( $include_code )
		return $code . ' '.$string;
	return $string;
}

HTTP Code values are taken from the Wikipedia entry found here: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Publish test

Publish test

Download This Episode

Compiled Weekly Recording from G1 Android Phone Try 2

This is a recording of Compiled Weekly from the recorder app in the
Google G1 Android phone. It came out pretty well. What do you think? I
may start podcasting this way all the time!

Attempt 2!

The first attempt I did not save the mp3 in stereo mode, which meant flash and quicktime among other players would not be able to play the file correctly. Problem fixed in this version.

Download This Episode

Compiled Weekly Recording from G1 Android Phone

This is a recording of Compiled Weekly from the recorder app in the Google G1 Android phone. It came out pretty well. What do you think? I may start podcasting this way all the time!

Download This Episode

CW10 – May 22, 2008 – Zend PHP 5 Certification Study Guide and Open Flash Charts

Angelo discusses the Zend PHP 5 Certification Study Guide 2nd edition and explains how to implement Open Flash Charts into your PHP project.

Don’t forget to E-mail comments and suggestions to compiledweekly AT gmail.com.

Links:

Download This Episode

Blubrry player!