All Starred Messages in Thunderbird 3

I “star” messages in Thunderbird pretty frequently as a reminder to go back and look at them. But it doesn’t usually work.

Why not? There is no easy way to go back and look at starred messages by default. I could resort each folder, looking for stars, but that’s annoying. I was hoping one of the Smart Folders would be “Starred Messages” but, sadly, I was wrong.

You can’t even easily search for starred messages!

But you can create a new saved search. Here’s how:

  1. Go to File > New > Saved Search…
  2. Name it something like “Starred”
  3. Set “Create as a subfolder of:” to wherever you’d like the folder to live.
  4. Click “Choose” to pick which folders to search.
  5. Change the filter to “Status” “is” “Starred”.
  6. Save it.

Then you can open your saved search in a new tab, or just leave it in the list of folders.

Posted here to save someone else some time.

Identity 2.0 – A Primer

Google your name. Right now. I’ll wait.

Good. What came up?

Look at the first page of results and ask yourself these questions about each one:

  1. Is it really me?
  2. Did I create this?
  3. Do I control this?

You need to be able to say “yes” to all of these for at least the top two or three results. (As I write this, the RSSmeme page repeating my Google Reader shared items has crawled above my blog, and I’m upset about it.)

Creating Identity

I’m lucky. My last name is very rare, so even if you Google just “Socol” I come in second—only to my father, and ahead of Wikipedia. You may not be so lucky, saddled with a name like Jones or Smith or, even worse, you might have the same name as a celebrity. You may have an uphill battle.

People with common names need to get creative. It can be as simple as adding an initial—my friend became Alec R. Johnston to distinguish himself. Something a little more creative—Lisa Bettany named her blog Mostly Lisa. Or you can geek out, like Ben Lew, who uses the name n0s0ap. (Those are zeros.)

Ben uses the name n0s0ap on del.icio.us, flickr, Last.fm, Digg, Twitter, etc. Lisa uses a combination of “MostlyLisa” and “LisaBettany.” I use a combination of an old name, “UrbaneExistance” (I know it’s spelled wrong) and “JamesSocol” for all new registrations.

But all of us, Alec, Ben, Lisa, and I, make sure our real names are linked to our identities. It’s no Clark Kent: n0s0ap is Ben Lew, with the glasses on or off.

Owning Identity

Do you own your own domain name? Why not? Go buy it. Now. Go!

I have this conversation with friends all the time. Would you want someone signing your name on paper documents? Of course not, so why would you let them do the same thing online? I own jamessocol.com, jamessocol.net, and jamessocol.org, just so no one else does. Even if you do nothing but have it redirect to your social network of choice, you should own your name.

If your name is taken, reread the last section and get creative.

Now, about those social networks. You don’t need to be on every one, but get on a few, build a profile, and put your name on it. You can create and control your own Facebook and MySpace pages without knowing a single HTML tag. Once you’ve got a name, whether it’s your real name or something else, use it. last.fm/user/you. twitter.com/you.

Controlling Identity

The best way I’ve found to control what the web knows about you is to start your own propaganda campaign. Put your name on a lot of things, preferably with links back to your own site.

An easy way to start is by commenting. Blog comments help the most, since you spread that influence around the whole internet, but within MySpace or Facebook posting real, meaningful, interesting comments on profiles and walls will make sure people think of you when they hear your name.

If you have the time, try blogging. There are a lot of blogs with great advice, but you can always just “write what you know.” Once you find your voice, the writing flows.

What else? It depends what you like. If you take pictures, get a Flickr stream. Last.fm is a great way to share and find music you like. GoodReads is a similar site for books. Twitter is great for finding people with similar interests and building connections. LinkedIn is a professional social network, particularly good for people in marketing or new media. Blogger, while not the best blogging platform, has some good community features. There is a lot out there.

Be Yourself

Don’t let someone else be you! Own your own identity and be proud of it. It will help you build authority and when a potential employer or client googles you, they’ll get a good idea about you from the first page of results.

What else, 2.0-savvy readers? What did I forget?

Better Living through Memcached

I wanted to put something specific in the title, like “Speed up your service” or “Reduce server load” or “Limit database calls” or… You see why I chose “Better Living.”

Memcached is a memory caching system with an obvious name. It allows you to store basically any data that can be serialized into a giant, memory-resident hash, then retrieve it with its unique key.

Imagine not querying your database on every request, and you only begin to get a sense of how useful this is.

Let’s go through a simple, single-server setup. (more…)

How to: Upgrade or Recompile PHP on RHEL5 (Outdated)

Update: This post is nearly two years old, and this is not how I would recommend upgrading PHP on RHEL, yet it continues to get traffic. If I can get my hands on a copy of RHEL, I’ll update this (or I might try using Fedora just to compare).

Upgrading PHP on RHEL 5 is difficult. Having done it on several servers, I’ve gotten it down to a 15 to 20 step process. It takes a while, but it’s straightforward. I thought I’d share, because help was sparse and noncontiguous at best.

RedHat Enterprise Linux: Hard to upgrade PHP.

RedHat Enterprise Linux 5 comes with PHP 5.1.6 and, as of this writing, this is the highest version available on yum. If you want to upgrade to 5.2.4, or even recompile 5.1.6 with a custom configuration, you’ll need to resolve several dependencies, first.

Unless otherwise specified, whenever I run ./configure, I always include --enable-shared and --enable-static.

The first step is to make sure you have a working APXS script installed. None of the servers on which I’ve done this had it. I installed Apache 2.2.4 over the default install, since it was the latest version. Be sure to enable APXS with --enable-so. Be careful configuring Apache, as it likes to install itself in /usr/local/apache2/ instead of /etc/httpd/, which you may prefer.

Now we start resolving the dependencies. I’d start with libtool and libiconv. The former you should be able to install via yum. The latter you may have to download, and after you configure it, from the source directory copy m4/iconv.m4 to /usr/local/share/aclocal/iconv.m4.

Use yum to make sure mysql-devel is installed, you’ll need it to link to mysql.

Then I’d do the image manipulation software, since it’s fairly easy. Use yum to install libjpeg, libpng and freetype. You can then use yum to make sure both gd and gd-devel are installed.

I installed libmcrypt, libmhash, and ming at this point. I’d say it’s a good time to get any of these more particular dependencies out of the way. I also installed Tidy, which you need to check out from their CVS repository. You can run build/gnuauto/setup.sh from the Tidy source directory to create the autoconf files.

Now we get to the crux of the matter: configuring PHP. All the major dependencies should have been taken care of. If you have other PHP options you’ll need, make sure those prerequisites are installed, as well. Run the configure script in the PHP source directory with everything you need enabled. I find it helpful to create a script like php.config with the following format:

'./configure' \
'--with-cgi' \
'--with-fastcgi' \
'--with-gd' \
...
'--with-xml' \
"$@"

You need to include the slashes \ at the end of every line. The last line, "$@" makes the script output the output of configure.

If you get an error running make, you may need to edit your Makefile. Find the EXTRA_LIBS section (in vi/vim, type <ctrl-c> /EXTRA_LIBS <return>) and add -liconv to the end of the line. Then try make clean && make and it should work.

You may or may not have to edit your httpd.conf, after running make install from the PHP source directory, to add the AddType or AddHandler directive for PHP.

That should be it. You can install extensions via PECL or Pear and everything should run. Save the source directory and your php.config (or config.nice) file, and you’ll be able to recompile at any time, in case you forgot something. (I, for example, forgot to add --with-mysql the first time!)

Let me know if you run into other problems. Most can be solved by typing yum install ###-devel to resolve a dependency, but if not, I’ve done this enough to be of some help.

MySQL Subqueries

I often find it difficult to find tips and advice for doing relatively simple things in things like MySQL, Ruby, Python, etc. So, starting with this post, I will help fill that niche. Today’s topic is Using Subqueries to Simplify your SQL Queries.

For this article, I’m using PHP and MySQL for examples. There are slightly different implementations of SQL in the various database engines, but this is one thing they all have in common.

SQL is called “structured query language” because it allows subqueries to make complex queries easier and faster. The idea of a subquery is simple: have the database perform one query and insert it into another.

There are dozens of useful ways of using subqueries, but I will concentrate on two: subqueries in the select expression and subqueries in the where clause.

Security Concerns

In most web programming languages, the interface between the script and the database only allows one query per access for security reasons: an injection attack could input something like '; DELETE * FROM users; and do some serious damage to a website. Imagine your SQL query to login looked something like:

SELECT * FROM users WHERE user_name = '$username' AND password = '$password';

If you are not checking and cleaning the input appropriately, someone could type the snippet above into your login form and, if multiple queries were allowed, MySQL would execute the following:

SELECT * FROM users WHERE user_name = ''; DELETE * FROM users; AND password='';

Since the empty string wouldn’t match any rows (hopefully), the first query would be discarded. The second query, the DELETE statement, would run, terminating at the second semicolon. Since the third piece of code is nonsense, MySQL would throw it out with an error.

To solve this problem, languages like PHP cause MySQL to issue an error any time there is more text (except comments) after the line terminator, usually the semicolon. The downside is that situations arise where you need to run multiple queries. The result is either often either a godawfully complicated statement with multiple JOINs, or running several queries, each of which requires communication with your database server and can slow down your applications.

In the examples below, I’ll pretend we’re building a forum that has four tables:

  • users with primary key user_id
  • forums, a list of all the boards, with primary key forum_id
  • threads which links each thread to a forum with forum_id and has primary key thread_id
  • posts which links each post to a thread with thread_id and has primary key post_id

Subqueries in Select Expressions

One way to speed up your queries again is to use subqueries. Subqueries are full SQL queries nested within another query. For example:

SELECT (SELECT * FROM t1);

Obviously it’s a pretty simple example. Notice the parentheses. Subqueries must always be in parentheses, even if they are inside a function, like:

SELECT MAX((SELECT salary FROM employees));

Let’s get to work on our forum. Say that while reading all the threads of a forum you’d like to have both the number of threads and the number of posts in the forum. One way is to run two separate queries:

SELECT COUNT(*) AS threads FROM threads WHERE forum_id='1';
SELECT COUNT(*) AS posts FROM posts LEFT JOIN threads USING(thread_id) WHERE forum_id='1';

That might not be so bad if your SQL server is localhost, but more and more hosts are running dedicated SQL servers, meaning that every query has to run across the internet, be processed, and run back, slowing down your application. But we can run this in one query with two subqueries:

SELECT
(SELECT COUNT(*) FROM threads WHERE forum_id='1') AS threads,
(SELECT COUNT(*) FROM posts LEFT JOIN threads USING(thread_id) WHERE forum_id='1') AS posts;

We can add the above to our query to get the name of the forum and its description, so we can further decrease the number of trips to the database:

SELECT
(SELECT COUNT(*) FROM threads WHERE threads.forum_id=forums.forum_id) AS threads,
(SELECT COUNT(*) FROM posts LEFT JOIN threads USING(thread_id) WHERE threads.forum_id=forums.forum_id) AS posts,
forum_name,
forum_description
FROM forums WHERE forum_id='1';

Notice that we also changed the WHERE clauses to match whatever forum ID we put into the “outer query“.

Subqueries in Where Clauses

Another simple and useful way to use a subquery is in a WHERE clause. Here you must be careful to match the WHERE syntax and the type of data returned by the subquery. For example, in WHERE user_name = (...), the subquery ((...)) must return a single value, while in WHERE post_date IN (...), the subquery can return a list.

In our forum, we might want to search for all posts by a specific user, but we don’t want our visitors to need to know the user ID—or perhaps we want a more descriptive URL, like search.php?user=USER_NAME instead of search.php?user=#ID#. But in our forum, to be efficient, we link posts to their author by the user_id column.

One way to do this is to run a query to find the ID then run another query to find the posts. Another way in this particular case is to use a JOIN statement. But yet another way is to do this:

SELECT * FROM posts WHERE user_id = (SELECT user_id FROM users WHERE user_name = 'foo');

In the case above, a JOIN would also get us the information we want, but in some cases this isn’t true, for example:

SELECT column1 FROM t1
WHERE column1 = (SELECT MAX(column2) FROM t2);

When you need to COUNT or otherwise aggregate one column, you’ll need to use a subquery instead of a JOIN, as well.

Summary

This article only scratched the surface of subqueries. Subqueries can be nested, they can appear in other places and do other things, and they can make your SQL more readable, among others. I don’t claim that the SQL statements above are the world’s most efficient or best way to do things—if you know a better way, let me know! I just want to give an introduction to subqueries, a very basic part of SQL that few people I’ve met seem to understand.