I love recursive functions. And I especially love them when they can be used for applications like menu creation. Here’s a nice little recursion function that I wrote in PHP to create a menu from an associative array. It takes an associative array as an input and creates a nice menu from it. I have also included the JavaScript to make the showing/hiding of the submenus work, too. There are essentially two well-defined levels of CSS: the main menu and all of the sublevels below the main menu. The main ul can have any class that you want. The sublevels all have the class “sub.” You can use CSS nesting to define specific styles for third, fourth, etc. level submenus. For example:
ul { text-decoration: underline }
ul .sub { font-weight: bold; text-decoration: none }
ul .sub .sub { color: #555 }
ul .sub .sub .sub { color: #999 }
This CSS will make the first level (ul) underlined, the second level bold (but not underlined), the third level bold and dark gray, and the fourth level bold and light gray.
The only real bug that I can see right now is that indentation is not very strict (multiple sublevels are not correctly indented and the last <ul> is incorrectly indented), but that’s fairly minor. If I were to modify the function to correctly indent everything, then I imagine that the function would become rather bloated.
And yes, this method is going to be used in the next design of my site.
Enjoy.
Edit: I just found out that you need to enclose the sub-level <ul> tags with <li> tags around them. I’ll leave it to the reader to modify the script because I’m too lazy to do that right now.
Published on
October 13, 2007 in
Code.
I need to replace all instances of joeyjwc.x3fusion.com with jwcxz.com.
Method 1: Do it manually.
Method 2: Write a script to do it for me.
I opted for Method 2. Using sed, find, and a few other friends, I finally managed to write a script that would accomplish the aforementioned goal (and referenced too many sites in the process…). Here it is in all its glory. Perhaps the casual reader might find it to be somewhat useful.
It’s a three-phase process. Phase one was to create an exact copy of the structure of the directory that I was working in. I did this by following these instructions. Phase two and three are both located within the script. First, the system looks for instances of joeyjwc.x3fusion.com in files matching the listed filetypes and replaces them with jwcxz.com. Then, it looks for instances of the new email address and changes it back to the old one (I haven’t finished setting up my email accounts). It optionally supports working within a subdirectory. For example, I can cd to software, run ./replace.sh software, and the script will run for all files in the software directory (and its subdirectories).
Published on
October 13, 2007 in
General.
So, I finally bought a domain name: http://jwcxz.com. The name itself was somewhat of a spur-of-the-moment impulse buy, but I have been looking at buying a domain name for quite a while now. There were no good four letter domain names containing jwc, so I proceeded to five letter domain names, where there were plenty. I chose jwcxz.com for a few reasons. It’s very easy to pronounce (“J-W-C-X-Z-DOT-COM”), extremely fast to type (the cxz is much like rolling one’s fingers on a table), and short enough to include in limited space.
http://joeyjwc.x3fusion.com still works fine. In the future, though (maybe a year from now), I will be eliminating it. In the meantime, I will be scouring my site for hard-coded instances of joeyjwc.x3fusion.com and replacing them with jwcxz.com.
I’m also thinking of changing the site’s layout around quite a bit. But that’s a long ways off…
The blog has been transferred to blog.jwcxz.com, but many of the links that referenced files on my site are now broken. I’ll write up a quick script to fix them at some point.
Published on
October 9, 2007 in
General.
I’ve started to get into the messy stuff: extracting message information with libgmail. A piece of sample output for getting the authors of a message is:
\u003cspan id\u003d"_upro_email1@domain.tld"\>Name1\u003c/span\>, \u003cspan id\u003d"_upro_email2@domain.tld"\>me\u003c/span\> (3)
That might seem fairly easy to parse with a little REGEX. Just remove all the unpleasant stuff and build yourself an array of authors (and the thread message count is on the end).
But the fun occurs when you get this:
\u003cspan id\u003d"_upro_email1@domain.tld"\>Name1\u003c/span\> .. \u003cspan id\u003d"_upro_email2@domain.tld"\>me\u003c/span\>, \u003cspan id\u003d"_upro_email3@domain.tld"\>Name3\u003c/span\> (11)
In this email, there were more than three participants, but only three are listed (notice the ..). The REGEX becomes a little more complicated, but it’s still possible. I just need to teach the system how to determine whether there are additional (and hidden) authors in the message. I wonder what other kinds of fun things await (I took a look at how libgmail returns the body of a message, as well. That was scary, to say the least).
To be continued.
I was bored. More accurately, I didn’t want to do the work that I (still) have to do.
Sometimes, when I want to send a message using Gmail, I become frustrated by the overall inefficiency. First, I have to open up my browser. Then, I need to click the link on my favorites bar. Then, I need to click Compose Mail. And finally, I can write what I was going to write. (If you think I’m a lazy fool by now, you’re probably right.)
So, I decided to experiment with libgmail a bit. The result was an easy, clean command-line interface for writing email messages. Then, I decided to take things a step further. I built a dynamic menu system and added a few options to it (send an email, check unread messages, etc.). I then started to design a purely function-based script that would give me a fast, powerful email client.
I’m starting to like the result. So far, the client supports sending messages and checking the number of unread messages, but I plan to add support for reading messages and replying to them in the future. Furthermore, the code is fairly clean (it’s classless, but that’s okay) and very flexible. It shouldn’t be too hard to add new features.
You can download a preliminary test version here. I also have included some sample output. I’ve started a page here.
Published on
October 5, 2007 in
General.
Being left-handed, it’s hard for me to find pens that dry very quickly so that I don’t smudge the page as my hand moves across it. I have found that liquid ink pens seem to do the best job; gel ink dries too slowly. I recently bought a package of Staedtler Liquid Point 7 pens and have really enjoyed them. After about three weeks of writing, the first pen ran out. Considering that I only used that pen to write, I would say that the link lasted for a decent amount of time. So, as I moved on to the next pen, I thought about how to make use out of my empty pen (which doesn’t support refill cartridges). I found a small jar of Parker Quink and got an idea…
First, I made a small dent in the center of the very end of the pen. Using the smallest drill bit that I could find, I bored a small hole into the end. Then, using a cheap pipette (this got messy), I filled the pen up. Finally, I sealed the pen off with some Goop glue.
It seems to be working fine now. The ink dries very quickly, much like the original ink. I’m just concerned about how cheap I was.