articles

If, like me, you hose Apache on your Ubuntu LTS server when you finally get around to upgrading libssl, and PHP stops working...

You'll be needing this:

apt-get --reinstall install apache2 php5-mysql \
libapache2-mod-php5 mysql-server

(You're welcome)

Preparing a string for use in a PHP regular expression.

This blog post is just for me, so I can look it up later... I suppose you can borrow it if you find it useful :)

Using dynamic strings inside a regex can be annoying, especially if you can't guarantee that the strings are actually sane. Including a URL in a regular expression is downright obnoxious, since URLs and regular expressions share most of the same special characters, but they mean entirely different things. I threw this function together to make strings regexable. Enjoy.

Function

/**
 * Prepare a string for use in a regular expression.
 * 
 * @author Justin Hileman {@link http://justinhileman.com}
 * @access public
 * @param string $str
 * @return string
 */
function preg_real_escape_string($str) {
    $replace = array('\\' => '\\\\', '^' => '\^', '.' => '\.',
        '$' => '\$', '|' => '\|', '(' => '\(', ')' => '\)',
        '[' => '\[', ']' => '\]', '*' => '\*', '+' => '\+',
        '?' => '\?', '{' => '\{', '}' => '\}', ',' => '\,');
    return strtr($str, $replace);
}

Yeah, the name is a bit weird. This function is an analog to mysql_real_escape_string(), so it seemed fitting.

Usage

// basic usage (this is actually exactly the case I wrote this function for).
$regex = '/^' . preg_real_escape_string($name) . '/i';
$nameless = preg_replace($regex, '', $something_starting_with_name);
 
// trying to find a URL via regex can be especially obnoxious.
$regex = '/' . preg_real_escape_string($my_url) . '/';
$some_text = preg_replace($regex, '<a href="$1">$1</a>', $some_text);

My year in cities, 2009

I'm doing Kotke's cities thing. Here's my list for 2009:

  • Atlanta, Georgia1
  • Austin, Texas
  • Boston, Massachusettes
  • Denver, Colorado2
  • Los Angeles, California
  • Monteverde, Costa Rica
  • New Haven, Connecticut
  • New York, New York
  • Philadelphia, Pennsylvania
  • Portland, Oregon
  • Prosser, Washington
  • Provo, Utah
  • Puntarenas, Costa Rica
  • San Francisco, California
  • Washington DC
  • Wenatchee, Washington
  • Wilton, Connecticut

I spent one or more nights in every city on this list. Thanks to JetBlue's All You Can Jet pass for facilitating several of those trips :)


  1. Under duress. Thank you, Delta. 

  2. Also under duress, this time courtesy of United Airlines. 

Google Wave for iPhone is HOT.

Seriously. It even does realtime updates.

IMG_0293.PNG

IMG_0292.PNG

IMG_0285.PNG

IMG_0286.PNG

IMG_0287.PNG

IMG_0288.PNG

IMG_0289.PNG

IMG_0290.PNG

IMG_0291.PNG

Presented without comment

Strange Google keywords that landed at my blog

  • [searching for something dirty]
  • message link generator

Unrelated Yahoo search results that ended up here

  • 404 justin
  • 404 music / justin
  • acta "only one ipod"
  • base structure
  • best punchlines humor
  • blog [searching for something dirty]
  • cach a poo
  • cach the poo
  • clickable link generator
  • [searching for something dirty]
  • [searching for something dirty]
  • googol justin
  • how do you make fans
  • how much is the music industry worth
  • my space cool
  • [searching for something dirty]
  • [searching for something dirty]

A whole grip of Microsoft Live/MSN search terms which, in some crazy stretch of the imagination, might possibly relate to my blog

  • "types of stupidity"
  • +brain fard
  • +dot your happy friend dot info
  • +dot your space friend dot info
  • +what is acquaintances
  • add,message,comment links
  • again or contact info justin
  • alphebetize iphone menu
  • cach a poo
  • cach a poo 2
  • cach the poo
  • catch a poo
  • catchthe poo
  • chuck hileman blogger
  • clickable link generator
  • [searching for something dirty]
  • [searching for something dirty]
  • define musing
  • difference between a single dot ("./myimage.jpg") and a double dot ("../myimage.jpg")
  • dot your freind dot info
  • dot your happy friend dot info
  • dot your space friend dot info
  • frankie leman
  • google justin
  • googol hot open girls
  • hi my conputer info
  • hileman beer
  • [searching for something dirty]

And it appears that Bing might be carrying on the tradition

  • google justin
  • jastin for laught
  • [searching for something dirty]
  • "girl jeans"
  • advanced healing bandaid
  • arnold bennett
  • beautified quotes
  • bringo stop talking to machines
  • cach a poo
  • cartoon register groceries
  • doophp
  • dot unicode
  • download high def trailers
  • drupal webfm securing
  • em,px,
  • firefox really slowing down my internet
  • google.justin
  • gustaso.com
  • how to get firefox not to use memory when us load pages
  • how to save e-mail info on xp full install
  • howto disable url search ie
  • i think i have disabled number lock
  • ie6 backspace key
  • inspiration when sleepy

Context: Each list above consists of the unrelated search terms found in the top 50 keyword referrers from each search engine. For example, Google was wrong in about 4% of its top fifty search terms. Microsoft Live search failed in an astounding 76% of its tries.

For the curious: All the [searching for something dirty] placeholders were variations on the name of a certain website which will remain nameless.

Spyc vs. syck: Speedier YAML parsing in PHP

This post is mostly pretty pictures. I just ran some really quick benchmarks on a couple of of the YAML parsing options available for PHP. The blue line is the Spyc YAML library. The green line is the syck PECL extension. The yellow line is a standard PHP include(), and is on the chart as a reference point.

The first two charts were tested with a fixed file size and a variable number of iterations. The final chart tracks the change in parsing time as file size increases. Each test was run with 100 iterations, and the file size was doubled at each stage.

The pretty pictures

Average parse time

Total parse time

Total parse time for larger files

More info than you cared to know

  • This is a very informal benchmark. Feel free to supplement it with testing of your own.
  • All benchmarks were run on the same Ubuntu 9.04 virtual machine running PHP 5.2.x.
  • Tests were run in a Zoop Framework skeleton app (from the upcoming Lunar release), since I had one handy and it's really easy to deploy.
  • The YAML benchmarks on the first two charts consist of loading and parsing a ~160 line file (a YAML dump of the default Zoop skeleton configuration).
  • The PHP include benchmark exists only as a reference point. It consists of loading a var_dump()'d version of the same configuration array used in the YAML tests. This file was included via a standard PHP include().
  • The first two sets of tests were run with 1, 50, 100, 250, and 500 iterations, respectively. The final test was run with 100 iterations and variable file size.

Coda tip: show "invisible characters" when you highlight text

Coda is awesome. Here's a quick way to make it awesomer: invisible visible invisible characters!

Coda lets you show all the newlines, tabs and spaces, which comes in handy. But the default settings are pretty distracting. If you change the invisible character display color to match the background, they only show up when you select text.

First do this:

Show invisible characters

Then change this:

Change invisible character color to match the background

And rock out like this:

Invisible visible invisible characters!

Pepsi is listening, tell them to bring Mtn Dew Throwback back!

Via the Twitter:


pepsi: Hey Throwback fans!We've been listening 2 you & are now debating bringing it back 4 another limited time period. But we need your feedback!
about 4 days ago

pepsi: Tell us why you love it/want it back. We're listening and looking at every #Throwback tweet. (so using # would help).
about 4 days ago

So what are you waiting for? Tell @Pepsi to bring back Mountain Dew Throwback!

Pro Tip: Use an explicit LIMIT in Doctrine

Doctrine is usually pretty rad. And sometimes it's really really dumb.

For example, in an imaginary CMS the following DQL query will grab a random blog post:

$random_post = Doctrine_Query::create()
    ->select('*')
    ->from('BlogPosts')
    ->where('published')
    ->orderBy('RANDOM()')
    ->fetchOne();

And it will work great when you first start writing blog posts. But as the total number of posts increases, the performance will get worse and worse. That's because, apparently, when you ask Doctrine to "fetch one" that doesn't quite convert to LIMIT 1 on the back end. It will actually select--and possibly instantiate an object for--everything that matches your query. After it's done with all this work, Doctrine will hand you the first result.

If you want to save yourself headaches later, use something like this:

$random_post = Doctrine_Query::create()
    ->select('*')
    ->from('BlogPosts')
    ->where('published')
    ->orderBy('RANDOM()')
    ->limit(1)
    ->fetchOne();

Any time you call fetchOne(), be sure to explicitly use limit(1).

Things I'd love to see in Pukka

I've been using Pukka—a Mac client for Delicious—for a bit, and it's pretty great. (More on that later, it's already the subject of a half-finished Technophobe review). I like it enough that I recommended it to a friend today:


bobthecow: @storiesofmac Pukka is pretty okay (Delicious + Mac)
about 2 hours ago

And what do you know, Justin Miller (the creator of Pukka) noticed:


incanus77: @bobthecow Any way I can make Pukka 'really ok'? :-)
about an hour ago

So here, other Justin, are a couple of ways to make Pukka great:

  • Pre-populate the page title when dragging a URL into Pukka for bookmarking: I was actually surprised that it didn’t already work like this.

  • Popular tags support: I still use the official Yahoo plugin in Firefox to do the majority of my bookmarking because of this one feature. I will drag a page from Safari to Firefox and bookmark it there just so I don’t have to think up all the tags to use.

  • Global keyboard shortcuts for bookmarking: I'm not sure how this one would work, but I’d like to be able to bookmark via hotkey in any browser. It might need to be an input manager or a set of browser plugins. Think 1Password for bookmarks.

  • Bonus: if you can work it into the plugin/input manager goodness, I love being able to select a paragraph from the site to use for my Delicious description text.

  • Real Spotlight integration: For this it might make sense to stash the local bookmark cache as a folder full of webclips, and make sure they’re named, tagged, and commented in a Spotlight friendly way.

You're well on your way, and I'd love to see Pukka get even better.

Better than Follow Friday

Here are the ten people to whom I’ve given the most gold stars on Twitter:

  1. @sween (43)
  2. @rachijan (39)
  3. @badbanana (27)
  4. @apelad (26)
  5. @yowhatsthehaps (21)
  6. @biorhythmist and @texburgher (18)
  7. @strutting (17)
  8. @donchiefnerd (16)
  9. @GPappalardo (15)

If you’re on Twitter, you should follow these kids. Each of those stars is worth at least a chuckle, and most of them evoked an all-out laugh--though I don’t think I rolled on the floor even once.

If you’re not on Twitter, you will be soon. You might as well give in now and start by following some people on this list.

The list comes from Twitterbelle, a cute little web app by @poeks that checks who you’ve favorited with your last 200, 500, or 1000 stars. Feel free to check out my full list. (Plus, you should prob’ly follow everyone in the top 50).

We're going to play a new game...

After reading a couple of blog posts on a comment system called Disqus, I want to give it another shot.

I tried Disqus back in the day, and it was really slow and generally fairly annoying. Most of their issues seem to be resolved, and they've picked up a lot of steam in the meantime. So now I'm considering swapping out my current comments for something a little more hip and magickal. But I'd like your feedback on the issue. So here's what you've gotta do:

  1. Leave a comment below.
  2. Let me know how you feel about the experience.
  3. That's it!

You'll notice that there are several ways to identify yourself. If you have a Disqus, Facebook, or Twitter account you can use one of those. Feel free to try out a couple of accounts, or choose none at all. You can also link to this post on just about any social media site (FriendFeed or Twitter or Reddit or YouTube, for example) and it should pull in those comments as well.

So I'm curious what you think about it.

How is the experience? Do you like it better than a traditional blog comment system? Can you see yourself actually voting on other comments à la Slashdot/Reddit/Digg?

Have you used Disqus (or Intense Debate, or another similar service) in the past? Was there anything about it that you couldn't stand?

Most importantly, will this make you more or less likely to join the conversation?

We don't need to make a decision right away. We can play with Disqus for a while and see how we feel. If it's horrid, the old comment system is just a pref setting away.

So talk to me :)

Note: This is the first post on my blog (and currently the only one) with Disqus comments enabled. All older posts still use the native comment system. So you've gotta try Disqus out on this post. Thanks!

Save yourself from the Twitpocalypse with this handy bookmarklet

The Twitpocalypse is upon us, and a whole lot of things have broken...

In some cases it's recoverable though. If you click a link from your favorite Twitter-related service and come across a URL like this, you can fix it! Just use this handy dandy little bookmarklet and you'll be back on the right Tweet in no time.

UNpocalypse!

Use this like you normally use a bookmarklet. Drag it to your bookmark bar, or right click and "save as bookmark".

The standard bookmarklet disclaimers apply: This works in Firefox and Safari, but might not work in all browsers. It's a quick and dirty bookmarklet, so if you use it somewhere it doesn't belong it will do unexpected things with your browser. Don't try using it on non-Twitpocalypsed tweets, as it will try to grab some random tweet from the far distant future.

Six fun Twitter searches

Apparently nobody cares what you had for lunch. Nobody wants to hear about your bodily functions (or so I hear). So what else is Twitter good for?

Keeping your finger on the pulse of awesome, of course!

And the best tool for the job is Twitter Search. Check out some of my favorite Twitter searches below. Make up some of your own and share. Enjoy!

Note: Because some people on Twitter use offensive language, these searches occasionally return content that gets apps blocked from the iTunes App Store.

redacted.png
is-down.png
dear-hate.png
dont_click.png
bacon.png
this-twitter-thing.png

Radical

Sometimes I find awesome in unexpected places. Check out these great Unicode glyphs... In the U+2F00 to U+2FEF range there's a set of characters known as the Kangxi Radicals.

Yeah, I mostly like them for their names.