Archive for May, 2009

Hashtag and Username Linking in Twitter Apps

May 12th, 2009

Are you trying to add automatic hashtag and username hot linking in your PHP twitter app?

I just tried to do this with my amdavidson.me lifestreaming site. It’s just two nested regular expressions. If there’s some problem with nested preg_replace functions, or if any regular expression geniuses have better ideas, feel free to comment.

But if not, here’s a little code for you, should make things super easy. It assumes your tweet variable is $tweet, replace with whatever you’d need.

1
2
3
4
5
echo preg_replace('/\#([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://hashtags.org/tag/$1\">#$1</a>",
preg_replace('/\@([a-zA-Z0-9_]{1,15})?/',
"<a href=\"http://twitter.com/$1\">@$1</a>",
$tweet));

Minimalism Revisited

May 4th, 2009

Well, this site just got more tweaking today to make the theme feel a bit more “andr3w”. I’m pretty comfortable with it now, it will certainly still change, but I don’t think it will be all that much.

The theme that I based my theme on is called Minimalism and it was done by Christian Geneahr. In turn it was based on the classic Kubrick, a theme so widely used and appreciated, I would call it the “Pappy” of all Wordpress themes.

With Kubrick’s fine lineage, Christian was able to make quite a nice minimalist theme. It just needed a couple more refinements for me to feel totally comfortable with it and now that my changes are somewhat stable, it’s time for me to do my GPL duty.

So, without further adieu: Minimalism-Revisited.

Length Errors in Apache Bench

May 4th, 2009

Are you seeing errors for content length in your Apache Bench tests of your webserver?

I had a hell of a time wondering what was going wrong with my webserver under load and finally found the answer here.

Turns out that Apache Bench takes the first pulled request and compares the length to all subsequent requests. Makes sense for a purely static page, but when you have a random image cropping up, you’re sure to see at least a couple bits difference in length.

So if you’re serving straight, hand coded HTML, enjoy the feeling of knowing that you’re getting the same length content each and every time… but if you’re like the rest of us (and anyone who would actually be using Apache Bench) feel free to rage that there’s no command line switch to turn off that silly notification.