Recent blog posts
Yes, a bit specific, but I need to store some links!
Been upgrading from an old Drupal 4.5 (aka Civicspace 82) to Drupal 5.1.
I had to get rid of the unused civicrm tables. Installing it seemed like a good idea at the time, but no point of using it for a tiny campaign. Here's a script that will delete the tables. It's posted here because the InnoDB engine complains if you drop these in the wrong order, and violate some constraints.
Here's a simple way to do name-based dispatch.
Here's how to create one of those text fields with HTML that the user's supposed to copy-and-paste into their page. It's not hard.
Create a form.
Add a Text Area. Give it a name, and set the rows and columns.
From the text area dialog, click on the "Advanced Properties..."
Add a property named "onclick" with the value of "this.focus(); this.select();".
NOTE: I found a serious problem - NVU's code reformatting will cause the html code to break within myspace, because NVU inserts newlines. To fix the problem, you have to save out the source, join all the lines, and upload the file manually.
I recently lost a chunk of data while I was developing a nice little macro to produce a report. How it was lost, is pretty sad. I had become used to pressing a few keys to clear out my spreadsheet, and I accidentally pressed the keys on a spreadsheet of the live data. Pffft. Data vanished.
I luckily had most of the data in another document, and restored some of the lost data, but, the lost bits were lost. All this was due, not to faulty code, but because I failed to create a development sandbox.
Yes, this was only a macro, but, even for something so simple, it's smart to make a separate place to develop it. This sandbox would have contained a copy of the data.
A sandbox is better than a backup. That's because the sandbox is a minimal subset of what you need to write your program. The real deployment environment is usually a lot more complex. To back up the real environment, so it's safe to develop in there, could be more difficult than you could imagine, and take a long time, too.
Error messaging facility:
The listener would collect all error messages into an object, and provide methods to help display them.
It can also dispatch code:
Shortly after I wrote this note, a class at PHP Classes showed up that does something related: error_manager
User-submitted HTML often contains small markup errors that can affect other parts of the page. The most common are unclosed tags that cause text to be bolded, italicized, or linked all the way down the page. The visual effect is catastrophic, though the error is really minor.
The html_close_tags() function scans HTML code, and generates a string that will close all the open tags. An easy way to use it is like this:
First draft of a "captcha" class that asks the user the sum of two numbers. It helps you write code to ask a question like this: What is the total of five plus three? (answer with a word) [ ] The user should respond with "eight".
How it WorksA captcha needs to "remember" the question that it posed to the user. To do this, the constructor takes an argument that's used as the key. It then saves the captcha data to a file in tmp/ named with the key.
Suppose you're tallying some data. You want to know if a value has shown up in the data. You can do this by using the array, like this:
$tally = array(); while( $row = getData() ) array_push($tally, $row); if (in_array($tally, 'theValueIWant')) echo "yes"; else echo "no";
There's a faster way, by using the array key. (It should be faster.)
This is a Perl version of the VB FileMirror class shown earlier on this site. The class helps you write scripts to (semi) safely mirror or move a file system from one directory to another. It does this by building the correct destination paths, making destination directories, and deleting files only after they appear to have been copied over.
Docs are in FileMirror.txt, attached.
DriveGMover.pl is a script that uses the class.
If there's anything that annoys people more than funky indentation, it's bad comments. I don't mean about the code, but in the code.
People get into all kinds of gripey little snits about how to indent code. Whenever you start a project, it's pretty important to nail down indentation, because it's one of those personal preferences that becomes "a big issue" when there's a conflict. Usually, the indentation is a non-issue, but it's something to fight about instead of discussing the real underlying issues, like interpersonal communication problesm.
So, let's catalog some styles, and discuss:
This is a repository of "novice" articles, written with the intent of driving more traffic to the site, and getting more ad clicks. It's pretty crass, I know, but the information may be very useful.
Here's yet another image gallery. This one requires no database, but requires you to create a file called captions.php in each directory of images, and populate it thusly:
It features a potentially annoying "paramater hiding" feature, one-image-ahead-preload, and very simple navigation. It was written at the request of Eternal_Student on Experts Express.
I've been spending the past day messing around with WordML to get it to generate Word files from PHP. The goal was to create printable tables. As George Bush said as the Iraq War slid toward failure: "Mission Accomplished."
My strategy was to start with a Word file, save it as xml, aka WordML, and then using the file as an xml template for the table layout. This is analogous to designing your output forms in NVU or Dreamweaver, and then turning it into a template.
Note that I saved the document out as an .xml file, not an .htm file. The .htm file could also be used as a template, but it doesn't retain all the Word features. There's also an alternate format, .htx, that is a MIME encoded .htm with enclosures, but the entire thing is MIME encoded, and decoding (and re-encoding) is a pain. XML is clean and relatively simple, and allows you to embed graphics.