Archive for April 2006

Updated: A9 switched to live.com?

Edited 5/1/06: As pointed out by Peter, it looks like A9 doesn’t include either the standard Google search or the Google Images search as options. It’s not locale related, as his experience matches mine. Guess I’m going back to google.com directly, although I’ll miss the parallel searches.

Before I start let me explain why I use A9: I get a kick out of seeing the images that come up for my searches, sometimes they’re just ridiculous. The text results show up on the left, and the image results on the right.

It looks like A9 just switched the default engine for my searches from Google to Live. Google has been relegated to the “More choices…” menu. I have nothing against Live, exactly, however I don’t really dig how it was just changed without a user prompt.

The real suck of this, though, is that with Google being a later option than Images, Google search results now appear to the right of the images instead of to the left, which is just plain silly.

While it wasn’t hard to find in “Help”, the method for changing the order of the result boxes is in a non-intuitive place: You can change the order of the search result boxes by going to the “Add/Remove” option of “More Choices…”. Problem solved I guess. Still, an irritating development that I’ll chalk up to the “anti-user user interface movement”.

timezones, UTC

Time zones are a major source of annoyance for me, when writing code or working with databases that store time-keyed data. It’s especially irritating when you have to deal with the abomination that is daylight savings time.

So, I’ve finally decided to go ahead and set my server clocks to UTC (or GMT). It wasn’t hard to figure out how to do this, but documentation for this specific task was rather sparse as most people seem to want to move away from UTC.

On FreeBSD and Debian (Sarge) Linux, you can do this by copying /usr/share/zoneinfo/Etc/UTC to /etc/localtime . On Debian, you’ll want to replace what is currently in /etc/timezone with the string “Etc/UTC”. Then run ntpdate against your favorite time server, and reboot so all applications have the proper timezone setting.

You’ll need to figure out how you want to set your CMOS clock. I’ve left them as they are, set to local time, because it’s not convenient to load up the BIOS and change them. On FreeBSD, if your CMOS clock is on local time, touch /etc/wall_cmos_clock . If UTC, rm /etc/wall_cmos_clock . On Debian (Sarge) Linux, run “hwclock –localtime” or “hwclock –utc”.

jpgraph, SetFont

jpgraph is a pretty slick tool. It makes nice looking charts and graphs, and it is very easy to use. You simply pass it an array and it can draw it. Many other tools require serious data massaging and configuration to simply display a simple graph.

However, it’s hard to use your own truetype fonts. I verified that TTF works on my PHP installation, but I received frustrating errors for commands that probably ought to work (but I see now why they didn’t). There’s nothing as simple as:

$graph->xaxis->SetFont("/usr/X11R6/lib/X11/fonts/TTF/luxirr.ttf");

One error I received was “unknown font family specification”, which, according to Google, has only been seen by a couple people in Japan. Heh.

The FAQ has an entry about adding new TTF fonts, but what it describes involves modifying the library to add your font family, which is something not everyone will be able to do, or will be willing to do. (I chose not to because I prefer to use libraries as-is whenever possible).

Here’s how I use a .ttf file that does not exist in the one directory JpGraph checks, without modifying the library. It should work for .ttf files in your local directory. Quick summary: You should be able to put the first block of code near the top of your file, and use the lines from the second block of code just before calling the Graph->Stroke() method. I’ve included some boring details below as well. This has been tested with JpGraph versions 1.19 and 1.20.3 and PHP 4.4.x. It does not work with PHP 5.

Note: This is a hack. You’ll be creating a new TTF superclass, since jpgraph uses a hardcoded TTF_DIR variable for the path, and you’ll be replacing an existing font family in the code, because jpgraph hardcodes the font count. (PHP doesn’t let you redefine constants for some undocumented and unknown reason, making this class stuff necessary). The new class is as follows:

class TTF_local {
  var $font_files, $style_names, $ttf, $family_local;
  function TTF_local($fontfile,$fontfamily) {
    $this->ttf = new TTF();
    $this->style_names=$this->ttf->style_names;
    $this->font_files=$this->ttf->font_files;
    $this->family_local = $fontfamily;
    $this->font_files[$this->family_local] =
      array(FS_NORMAL=>$fontfile);
  }
  function File($family, $style=FS_NORMAL) {
    if ($family == $this->family_local &&
      isset ($this->font_files[$family]) &&
      isset ($this->font_files[$family][$style]) &&
      file_exists ($this->font_files[$family][$style]) &&
      is_readable ($this->font_files[$family][$style])) {
      return $this->font_files[$family][$style];
    } else {
      JpGraphError::Raise("Error with font $family/$style . It may not exist.");
    }
  }
}

(Note: The error handling in this class could be greatly improved).

And the following code will instruct JpGraph to use the new class, and will redefine font family 43 (this value must be 10 < = x <= 43 as defined by jpgraph.php). This assumes $graph is a Graph() object, and that you want the luxirr.ttf file from FreeBSD 4.10's XFree86-fontScalable-4.3.0 package.

$family_local = 43;
$graph->cache->img->ttf = new
TTF_local(‘/usr/X11R6/lib/X11/fonts/TTF/luxirr.ttf’,$family_local);
$graph->xaxis->SetFont($family_local,FS_NORMAL);

Whew. That sure was a lot of code for something relatively basic. Maybe a later version of jpgraph will let you just point directly at a path, or PHP will let you re/undefine constants. Who knows what the future may hold!

Note: You may also be able to create your own local jpg-config.inc file, and require() that before the jpgraph.php file. I don’t know if that works, but it does still limit you to working with one and only one font directory.

Note2: A proper patch would involve an update to the TTF class that rips out all of the assumptions the library makes about filenames and paths, to be replaced with a configuration file (the path of which could be specified as a constructor argument to TTF()) that lists out the fonts and paths, as well as a method that lets you specify arbitrary fonts on-the-fly. If there is any interest in such a thing, I’ll write it up and submit the patch.

Immigration

If illegal immigrants become legal Americans, will they continue to work in agriculture, where they’ve worked now for a relative lack of other options, or will they try to move on to other better paying careers? I’d try to move on, or at least start expecting more money (even if I didn’t get it).

I also wonder what the new excuse will be. “Americans won’t do these jobs” would have to change, if they are given citizenship.

I’m not against the idea of amnesty (the word politicians are afraid of), I just wonder how well the reasoning being presented has been thought out.

“unless otherwise stated” in shorthand?

I’m trying to figure out what the common phrase “unless otherwise stated” or “unless otherwise specified” would be in shorthand. It’d probably something Latin like etc or ie/eg. “nisi cetera” or “nisi secus” is as close as I can get, using online Latin/English dictionaries, and without any knowledge whatever of the Latin language.

I could just use “uos” but I think I’d have to explain it to everyone every time I typed it.