Monthly Archive for November, 2007

Random Avatar (Take 2)

Rotating avatars are kind of fun to have.  I find that they are especially nice when they change in some subtle way (such as a background or foreground change) because forum members sometimes express surprise.  The script for a random avatar is fairly simple: it should read in a list of files, choose one at random, and then redirect the output.  This last step can be accomplished in two ways: with the header(“Location: image.png“) function in PHP, or by using GD to read the image in and then output it.  Then, there is the subject of masking.  By using a custom .htaccess file and Apache’s RewriteEngine, you can circumvent the prevention of dynamic PHP scripts as images.  The .htaccess file consists of two lines:

RewriteEngine On
RewriteRule image.png image.php

Most forums don’t want users using dynamic PHP scripts because it is possible to be malicious with them (one of the more harmless things I can think of is getting the viewer’s IP address).  So, use this trick with caution.  I only post it here because it is fairly easy to learn about anyways.

Instead of using the traditional “image rotator”, I decided to get a bit fancier.  I created a couple of foreground images and a couple of background images.  I wrote a quick PHP script to merge the two.  The result is this:

http://jwcxz.com/pic/avatar/square/index.png

The sourcecode is available here.  Fundamentally, the design is extremely simple.  Foreground images are named fgX.png, where X is an increasing integer, starting at 0 and background images are named bgX.png in a similar fashion.  The variables $fmax and $bmax must be modified each time a new image is uploaded.  This is a minor inefficiency, but I didn’t want to have the script use scandir() every time someone looks at an image.  The system then just overlays the foreground image over the background image and prints out the input.

Anyways, my goal is to actually put some decent background and foreground images in there now.

I Can’t Think of a Title…

Here’s a fun list of fun things that I have been doing (for fun) to keep my brain from overheating.

  • Unreal Tournament 3 Demo
  • Trying to fix the Vista bootloader (okay, not entirely relaxing)
  • Coding an awesome email forwarding script that works with CPanel’s “pipe forwarded emails to program” feature. It adds MySQL goodness in there, too and supports sending to multiple addresses. Entry and code are coming.
  • Unreal Tournament 3 Demo
  • Playing around with vLite to make a more pleasant Vista install disk (it runs with reasonable speed on my laptop with only 256MB of RAM!)
  • Working on various software projects (I’m going to get back to GmailUI soon; I promise)
  • Designing the new version of my site. Yes, Internet Explodrer is ruining it despite good CSS. In fact, I have to use hackish, messy CSS to fix some of the problems (and others don’t look like they’ll ever be fixed)
  • Unreal Tournament 3 Demo
  • Filling up more pens. I designed a better cap on the end. It involves a small screw.
  • Unreal Tournament 3 Demo
  • etc.

Yes, the UT3 demo is amazing. No, it doesn’t run particularly well on my computer at maxed settings. It runs fairly smoothly with medium-high settings on a lower resolution, though.

Patching libgmail to Work with the New Gmail Interface

Google has heavily modified the Gmail interface fairly (more AJAX, fewer page refreshes), heavily breaking libgmail. Fortunately, though, the folks at Google have kept the old interface. A quick patch will modify libgmail to use this old interface again.

  1. Download my patch here.
  2. cd to the directory containing libgmail. It might be located at /usr/lib/python-2.5/site-packages or /usr/local/lib/python-2.5/site-packages (or python-2.4 if you still have version 2.4). You’ll need su, obviously, unless you run your system as root.
  3. Patch with: patch libgmail.py libgmail.patch
  4. Test your scripts that use libgmail.py.

Until the developers of libgmail update their code, this will suffice. I haven’t tested the patch on older versions of libgmail (I’m using the newest version), but patch should at least report a fuzzy match.

By the way, I have found the next programming language that I intend to learn.

Ridiculously Simple WordPress Updater

Thank you, BASH, for making me lazy. I wrote a quick script to update WordPress when I tell it to. Weighing in at a hefty 30 lines, the script will download the latest copy of WordPress and overwrite (after seeking your permission) your existing installation when you invoke it. Just fill in the first three variables with your own data and run it.

Sample output:

[joeyjwc@jupiter public_html]$ ./wp-upgrade.sh
--20:07:12--  http://wordpress.org/latest.tar.gz
Resolving wordpress.org... 72.233.56.139, 72.233.56.138
Connecting to wordpress.org|72.233.56.139|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: `wordpress-2.3.1.tar.gz'    [ <=> ] 883,535     --.-K/s   in 0.1s
20:07:13 (8.37 MB/s) - `wordpress-2.3.1.tar.gz' saved [883535]
Latest WordPress code downloaded.
Now copying code to: /home/joeyjwc/www/blog
Press q to cancel.
Copied.  If there have been major changes, you might need to run:

http://blog.jwcxz.com/wp-admin/upgrade.php

Associative Array -> Menu #2

I revised my original code for an algorithm to form a menu from an associative array.  I got rid of the use of echo in favor of pointers, which make the code more pleasant overall.  This helped to eliminate some bugs that I hadn’t noticed.  Also, I made the HTML proper by enclosing the sub-level <ul>s with <li>.  It’s still BYOCSS though…  New code is here.