Gordon P. Hemsley

Linguist by day. Web developer by night.

Posts Tagged ‘PHP’

PHP, MySQL, and the BIT field type

Posted by Gordon P. Hemsley on February 8, 2010

As Dave Humphrey once taught me:

When you do a search, and it comes back with no results, it’s a sign that you need to write something.

This is an issue that I came across while testing SASHA (which is available for you to try out, by the way), and I didn’t know if it was a bug or a feature. I could find no mention of it anywhere, and the people in the #mysql IRC channel on FreeNode weren’t especially helpful in helping me get to the bottom of it.

What is the issue, you ask? Well, even that in and of itself is a question, because I don’t know whether it’s a bug (or feature) in PHP or MySQL. However, I’m inclined to think it’s the latter, and I’ll get to why in a moment.

But first, some background. The table that SASHA uses to store schedules uses the BIT field type for keeping track of which days of the week a schedule occurs on. I figured it’d be easiest to use a 7-bit field and just flip a bit for each day of the week. And that worked fine for me on my local test server. But then I had a colleague test SASHA out on his test server, and things went a little wacky.

It took a little while to figure out what was causing our problem, and we finally got to the bottom of it: I was using MySQL 5.0 and he was using MySQL 5.1! Apparently, between 5.0 and 5.1, the return format of a BIT field changed from the literal binary data (output in the browser as a character, because the browser didn’t know it wasn’t) to a decimal representation of that data.

The first problem with that was that I had no idea there was a possibility of getting anything but the raw binary data I was getting on my server. The second problem was coming up with a straight-forward solution to detecting whether the database was feeding us raw binary data or converted decimal data. There was no direct way to do this, but I figured out the next best thing. A simple way to check what kind of data we’re getting is to find out whether it converts cleanly to an actual character. Here’s an excerpt from SASHA that demonstrates:

// MySQL 5.0 returns bit as binary, while MySQL 5.1 returns decimal
if( $days == chr( ord( $days ) ) )
	$input = 'binary';
	$input = 'decimal';

That seems to do the trick when it comes to handling unpredictable BIT field data.

(Again, I can’t guarantee that this isn’t actually a PHP issue, but I seem to recall us both being around the same version of PHP.)

If you have any insight into the matter, please do leave a comment.

Posted in Mozilla, Open Source, SourceForge | Tagged: , , , , , , , , , , , , , , , | 4 Comments »

Writing an Extension for Tab Sets

Posted by Gordon P. Hemsley on March 7, 2009

So, lately, I’ve been having problems with running Firefox 3.0.x on my MacBook Pro (which, admittedly, has been causing me many, many problems in the past couple of months unrelated to Firefox) in terms of speed and response time and whatnot. I’ve fairly certain it has something to do with the number of tabs I have open (which usually falls within the range of 75–100 tabs in my main window, plus a couple of other windows with fewer). However, running even more tabs (115+) on the latest Firefox 3.1b3 candidate build (build 2, as previously mentioned) doesn’t give me nearly as many problems. In fact, I think any problems it does give me are a result of Firefox 3.0.x slowing down my computer and confusing 3.1b3 into think it’s the one to blame.

But anyway, that’s beside the point. The point is, because of this large number of tabs, I’ve been looking to splitting them up into multiple windows. The thing is, if the computer’s not being slowed to a halt, I still have plenty of trouble finding the tabs that I want. It’s no fun having to scroll through 100 tabs to find what you’re looking for, after all.

So, I came up with the idea of writing an extension to have some way of managing what window is for what tasks (i.e. giving them names). Unfortunately (or fortunately, as it often saves me trouble), like every other idea I’ve thought of, someone has already created an extension that does what I’m looking for. This time, it was FireTitle.

The difference in this case, though, is that I’m not quite sure it’s tailored to fit exactly what I want to use it for. In fact, there are a number of problems with it:

  1. It doesn’t work with Firefox 3.1 (or, at least, hasn’t been tested for it).
  2. It only seems to get updated whenever a new version of Firefox comes out (i.e. it’s only been updated 3 times since it was created for Firefox 1.0).
  3. It doesn’t put the name of the tab set in the window title bar, only in the Window menu.
  4. It has a couple of other features I’m not interested in.
  5. It doesn’t save the information across sessions, a feature that was introduced in Firefox 2. (This is especially important, because I work continuously on the same set of tabs, independent of whether Firefox had to close for some reason. I don’t want to have to rename them every time I restart Firefox.)

On the flip-side of that, I’ve been wanting to write an extension for Firefox, but I haven’t had any good ideas to do it with. (Like I said, every time I come up with an idea, someone’s already beaten me to the punch.) So I think I just may go ahead with this idea. Or, at least, I’ll try to. I mean, I have a lot of stuff to do. But this should be useful for me, so that should drive me to do it. Another problem, besides time, would be learning how to do all the fancy code work. I’m a PHP coder, and I haven’t had sufficient experience with JavaScript to know everything by heart. Your help will be appreciated as I blog about it along the way.

I haven’t yet decided what I’ll call it, but it will be based around the concept of “tab sets”. As the term implies, these are sets of tabs group together by a common purpose. This might include “Firefox development” or “Fixing bug 487625” (a completely random number, as it were). This common purpose will also be reflected in the name of the tab set. (In these cases, they’d likely be identical.) So now on to the features:

  • As previously mentioned, named tab sets, possibly with more lengthy descriptions available somewhere.
  • Prepend tab set name to window title (which is followed by the browser branding on Windows, but not Mac; not sure about Linux)
    • Keep normal page title of frontmost tab of each window involved
  • Include number of tabs in the window title bar
    • Eliminates the need for the Tab Counter extension
  • Allow bookmark sets (folders) to be opened as a named window/tab set
  • Perhaps create a status bar button that would open (pop up) to give a list or thumbnails to bring a different tab set into focus (à la most multiple desktops applications). I’m imagining this in the lower left corner of the browser, by the way.

That’s all I’ve come up with so far. I haven’t yet started working on anything. I first have to look into the heart of FireTitle and see how they do it. Also, I don’t know quite how the features go across Firefox versions, but I’m going to be aiming this primarily for Firefox 3.1 (or, 3.5… grr…). If it turns out that’s not a big hassle to include Firefox 3.0 support, then I’ll do that, too.

If you have any questions, comments, suggestions, or answers regarding anything I’ve mentioned here, please comment. I’m looking for any and all feedback I can get.

Posted in Mozilla | Tagged: , , , , , , , , , , , | Leave a Comment »

My Foray into Mozilla Education

Posted by Gordon P. Hemsley on February 14, 2009

I’ve recently rebooted this blog based on a suggestion by David Humphrey (humph) of Mozilla Education (wiki) during a discussion in #education. I’ll now be using it blog about my endeavors across the Internet related to software development (particularly the open source kind), as well as any other coding experiences I may have (including website development).

I’m excited to get involved with Mozilla Education, because that means I’ll be able to put my new Linguistics major to work (I’m currently attending the University of Vermont), while also building upon my 10 years of web development—not to mention being able to contribute to a community that I’ve been following and wanting to get involved with for those same 10 years. (I used Netscape 4 back in the day, was thrilled when Netscape 6 came out, soon switched to Mozilla Application Suite, and was finally convinced to switch to Firefox, where I’ve been ever since.)

In the coming days and weeks, I’ll be working with humph and others to decide where I’ll best fit. He suggested that I start with getting familiar with Ubiquity, so that I can perhaps help with their development of their natural language processing engine. He also mentioned the possibility of improving the tools that the localization team uses to translate Mozilla products into languages other than English, particularly via the Web. In the meantime, though, I have to brush up on my JavaScript, because it is an integral part of most Mozilla products, especially Ubiquity.

So I hope this will be a good experience for me, and I hope that I will be able to contribute something that other people will consider useful in the course of their using (or developing) Mozilla products.

Posted in Mozilla | Tagged: , , , , , , , , , , , , , , , | Leave a Comment »