Archives By Category: Programming

document.createElement and checkboxes

I ran into a problem in building the web interface for SnapTest today, where I couldn't seem to get a checkbox to show up as checked in IE. The original code looked something like

And no matter how many times I tried, IE (6 specifically) refused to check the checkbox. It turns out IE want your checkboxes made in a Mozilla-incompatible way. Specifically, IE lets you call document.createElement using an entire HTML tag, which will result in a node you can perform operations on.…

Isolation Testing in PHP

Since SnapTest 1.0, I've been wanting to improve upon the level of isolation occurring on a per-test level. Working with one PHP process per file reduced the chance of collision, but it still had problems. In cases where a tested object had to work with static classes, for example, it was difficult to ensure the class was reset properly during setUp() and tearDown(). To get there, each test would need to be ran in its standalone PHP process.

When doing research on how to spawn sub processes cross-platform, the options end up being very limited. Since forking is not available on window boxes, the only two available options seemed to be popen() with STDIN and system() with a socket connection. With inspiration from Ming's spinlock concept for JavaScript, it was possible to spawn the needed child processes, and check back on their output in a round robin fashion. Using /bin/nice (or the /low switch on windows) also keeps any one process from starving the parent.…

Just In Time Loader for JavaScript

The most recent version (1.0.0) can be downloaded here:…

Javascript’s Strange Threaded Nature

There's a lot of digging required to figure out if Javascript is single or multi-threaded, and for every article out there, at least three contradict it. Thanks to the work Dan Simard in June, a final answer on Javascript threads was reached. The only major problem in this was that the comments by a user to Simard's post indicated that alert() caused Firefox's execution chain to change. The result was while the prompt was on screen, setTimeout() and other assorted callback functions were free to resolve.

The problem is made worse with several setTimeout() calls. As a single thread, JavaScript maintains some sort of event stack, where all of the callbacks and timeouts pile up, waiting for their turn. Once the event stack is out of events, the timers start again to count down to execution. If you fire one call with a setTimeout() and a timeout value of 2 seconds, and one more second of code execution follows, there will still be 2 seconds on the timer since it has not had a chance to run.…

Git-Svn on OSX

Update Aug 08: It was pointed out that you need the OSX Developer Tools installed. They are on the OSX CD, and enable the ability to compile things. It's a must have for this to work.…

Stylizing the Form Submit Button

"The buttons aren't styling" I remarked as I stared at the page in Camino and Safari. Testing on the Mac platform has been the absolute bane of my existence as of late, mostly because for some reason, these browsers in particular are very protective of their form widgets. Coming back to Cameron Adams' Entry on Styling Form Widgets, I found that none of the Macromedia examples were actually working for Camino/Safari, although they looked beautiful in Firefox. The submit button simply would not take the background settings. Interesting enough though, something of input type="button" styled perfectly.

However, the value attribute of the button wasn't getting passed in. For the legacy code around Gaia, we have forms with more than one possible "submit" for an action. The most common case of this is preview and submit buttons we traditionally use in the forums. This left us with two scenarios:…

PHP Transaction Manager Architecture

This is part two in the PHP Transaction Manager Series. You may also find the related entries in this series of interest:

Note: This article was written under the guise of PHP 4, which lacks a lot of object related functionality that would be beneficial to the development of the code used in these examples.

Avoiding AJAX Scope Issues in Prototype

I haven't seen this covered much, but I really felt it was worth a mention. A lot of people have worked with the prototype library, including myself. One of the most challenging things I've had to do was create an object that could make an AJAX request, and then internalize the response. Calling a function out on the global scope is messy and in poor taste if you can avoid it. I thought back to my Java classes, and remember an almost reflexive style of programming. About an hour later (including reading through prototype's source) I had a working model.

The major players in this design are the XMLHttpCatch object and the Ajax.Request object. Our goal is to call a sending function inside of an instance of myObj, and then have the response be ran in the context of myObj. By default, you cannot refer to "this" inside of the callback, because of scope issues. The solution is to encapsulate the request, and then have a way for the response to find its way back home. We do this by passing the scope down into the XMLHttpCatch object.…

Textify 2.0 has Arrived

Note Textify is now 2.1. It supports cookie level saving and by-paragraph gradients.

It's been long overdue, and has done all sorts of things like suck at being PHP and slow (and occasionally core dumping). Jokingly, I told my friend it should be the responsibility of the client's computer to coredump. After a bit more joking, more on my part than his, I realized Aaron was right and I should rewrite the Textify module. I needed to get down and dirty with Prototype(Prototype JS Library Home Page) anyway, and what better way than some powerful string processing libraries and amazingly quick regex. Pound for pound, indexOf() and charAt() leave me returning to PHP with a longing for some really basic functionality. For historical background, gradient text became a trend back in the days of Yahoo! Chat, with programs like CheetaChat and YChat making colored text blending commonplace (or at least that was how my generation remembered it). I found myself wanting that effect, so I wrote something. That was version 1 almost a year ago. This is now version 2, and it got a major overhaul.…

Making it Transaction Anything (in PHP)

This is part one in the PHP Transaction Manager Series. You may also find the related entries in this series of interest:

Note: This article was written under the guise of PHP 4, which lacks a lot of object related functionality that would be beneficial to the development of the code used in these examples.