Your browser is very old. You might enjoy surfing the web more if you used something newer like:

Google Chrome

Even Firefox would be OK.

If you're being forced at gunpoint to use Internet Explorer, you should at least upgrade it. Version 8 is tolerable and 9 will be OK when it comes out.

Posts from May 2009

Be Safe and Don’t Be a Jerk

Mark’s (incomplete) Guide to Riding in Traffic

There is a conversation that I have over and over again in various forms. It goes something like this:

PERSON: You ride your bike to work?
ME: Yesssss….
PERSON: How far is it?
ME: About 10mi.
PERSON: TEN MILES!?!?!
ME: It’s pretty flat most of the way
PERSON: But how do you ride? There are no bike paths.
ME: I usually just take surface roads in the most direct route I can. There are a couple of shortcuts I take to avoid particularly annoying intersections.
PERSON: You ride on THE ROAD!?! Like with cars and stuff !?!
ME: Ummm, yeah.

Most people think nothing of driving everywhere but are completely terrified of the possibility of riding a bicycle in traffic.

Guess how many fatal bicycle crashes there were in 2007?

~700 1

Let’s compare that to the

~37,000

fatal motor vehicle crashes there were in 2007.

The other thing to keep in mind is that 700 number includes all of the people who were doing stupid things like riding without a helmet down the wrong side of the road in the dark with no lights. So I think we can stop quibbling about safety and start talking about how YOU TOO can learn to ride in traffic without constant fear of death or injury.

Gear

  • Helmet. This is the #1
  • (in case you missed it) HELMET. In many cases, a bicycle fatality can be turned into a bicycle injury accident just by WEARING A HELMET.
  • Bright clothing and/or Reflectors
  • Flashing lights if you’re riding in low-light conditions. Make sure you have lights for front and back. I have one of these for the front and one of these for the rear.
  • Rear-view mirror. While not required, one of these can be helpful when changing lanes and keeping an eye on traffic behind you. There are glasses mounted and helmet mounted varieties.

This next area focuses on how you ride. Obviously how you ride is important for safety reasons. But it’s also important because, when you’re out on the road, you’re representing all cyclists. Every bad interaction you have is a black mark against all of us. That person will be less and less forgiving and considerate each time they come across a cyclist in the future.

Follow the Rules of the Road

  • DON’T ride on the sidealk.
  • DON’T ride on the wrong side of the road.
  • DON’T run red lights and stop signs.
  • DON’T weave in and out of traffic.
  • DO signal your turns.
  • DO obey lane designations. That means turn left from the left lane, respect right-turn and left-turn only lanes, etc.

Left-turn signalRight-turn signal

Part of the reason for the bad blood between so many cyclists and so many drivers is the erratic behavior of many cyclists. That means drivers don’t know how a cyclist is going to behave in any given situation which leads to misunderstandings and frustration all around.

There are few other strategies that I use to establish my space on the road.

Ride in the lane, not on the shoulder

Ride in the lane to the left of the shoulder
I usually ride 6″ – 12″ into the lane rather than riding on the shoulder. This may feel counterintuative since you’re out in traffic even more but I’ve noticed a big shift (for the better) in how cars behave towards me since I started riding this way. Being out a bit in the flow of traffic forces cars to be more aware of you and give you a reasonable about of room when passing.

Watch your line

I see this behavior a lot, especially in residential neighborhoods. A cyclist is riding up a street with lots of parked cars. Everytime the cyclist gets to a large gap between the cars, they move over closer to the curb. When the gap ends, they move back out to go around the next set of cars.

This is dangerous. You’re essentially having to merge back into traffic over and over again and you’re decreasing your visibility at the same time.

My preferred strategy is to pick a line that avoids all parked cars and maintain that line, and here’s the important part, even when I have room to my right.

Don't zig-zag around cars

Another example would be a road that has three lanes but the right lane changes to right-turn-only after a block or so. My approach is to ride down the middle lane rather than having to merge out of the right-hand lane as I get closer to the light. It does mean I have cars passing me on the right and the left but I still feel safer with that than making an extra lane-change.

Don’t be a jerk

Here’s the scenario. You’re riding down the road and someone passes you, way too close, honking and yelling. What’s your first instinct? Shout something back? Flip them off? I know that’s my overwhelming urge but it’s better for everyone if you can take a deep breath and let that righteous anger go.

Conversely, if a car does something nice, wave! Smile! If you’re in a situation where they’ll be able to hear you, throw a “Thank you!” their way. If you screw up because you weren’t paying attention, apologize. I spaced out on a ride the other day and had a close call with a very nice man crossing the street. He clearly had the right-of-way so I stopped and apologized profusely for my mistake.

It’s all about trying to build up a healthly relationship between cyclists, cars, and pedestrians where everyone can be safe and get where they’re going.

Do be safe. And don’t be a jerk.



1 F.A.R.S Encyclopedia

Facebook’s OpenID Support: It’s cute and all but…

I was excited when I first heard Facebook was going to launch support for OpenID. I love OpenID and I wish I could use it in more places. Having a big name like Facebook supporting OpenID is a big step towards more widespread acceptance.

I rushed right over to my Account Settings page to link my OpenID url with my Facebook account. Now I currently use MyOpenID as my provider but I also have an OpenID Delegate page that I use for most of my actual logins.

Delegate page source

That lets me specify the http://antelopelovefan.com/id as my login URL but the actual authentication happens through MyOpenID. This is nice because I won’t have to go around changing all of my identities if I switch from MyOpenID to something else.

Unfortunately, Facebook doesn’t seem to support delegate urls.

Not a valid OpenID url

That’s a pretty big bummer right there.

Then there’s the issue that the automatic login doesn’t seem to work. It’s supposed to go like this:

  1. Login into your OpenID provider
  2. That sets a cookie saying your particular OpenID has been authenticated.
  3. You go to the Facebook site.
  4. It checks to see if you’ve authenticated any OpenIDs linked to your Facebook account.
  5. If you have, then you get automatically logged into Facebook.

To be fair, it does work some of the time. In my case, it seems to be about every third time. The rest of time, I just end up at the Facebook login screen.

Which leads to my final beef.

Even when the automatic login does work, I keep running into situations where I get redirected to the Facebook login screen even though I’m (in theory) already authenticated). I lost two Facebook messages this way. I automatically logged in and went to compose a message. Everything was fine until I actually hit send at which point I ended up at the login screen and my message was gone.

To sum up, I’m excited that Facebook is trying to support OpenID but I some big improvements come soon.

Basics of the PHP PCRE functions

I’m only going to talk about the three I use the most but, there are a number of useful PCRE functions in PHP.

preg_match

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] )

preg_match returns 0 for no match or 1 if a match was found. It’s important to note that preg_match stops searching after the first match. Use preg_match_all if you need all matches within a string.

You can get back any backreferences by passing an empty array as the $matches argument.

Here’s a simple example that we use to parse a string like ‘variable = value’ into pieces:

$regex = '/^\s*(.*?)\s*=\s*(.*?)\s*$/';

$subject = 'variable = value';
$matches = array();

if( preg_match($regex, $subject, $matches) ) {
    echo '<pre>' . print_r($matches, true) . '</pre>';
}

which outputs this:


Array
(
    [0] => variable = value
    [1] => variable
    [2] => value
)

Another handy trick is to use extended regular expressions (/pattern/x) which lets you space the pattern across multiple lines and even include comments:

$regex = '/^
          \s*(.*?)\s*  #Match group 1 contains the value on the left side of the =, excluding any whitespace
          =
          \s*(.*?)\s*  #Match group 2 contains the value on the right side.
          $/x';

preg_replace

mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit= -1 [, int &$count ]] )

Most of the time str_replace is sufficient (and faster!) but preg_replace has some great uses as well. In its most basic form, you pass it a regular expression and a replacement value and it replaces all matches.

Using the regex and subject in the previous example, let’s see how we can use preg_replace to reverse the values on either side of the =. If we start with ‘variable = value’, we want to end up with ‘value = variable’.

$regex = '/^\s*(.*?)\s*=\s*(.*?)\s*$/';

$subject = 'variable = value';

echo preg_replace($regex, '$2 = $1', $subject);

Our regular expression creates two backreferences, one for each value on either side of the = side. We can refer to these by number ($1 and $2) in the replacement string which makes it very easy to reverse them.

preg_split

array preg_split ( string $pattern , string $subject [, int $limit= -1 [, int $flags= 0 ]] )

Again explode or str_split will be more efficient if you don’t actually need regular expressions to split your string.

Here’s an example that splits a sentence into words using whitespace, commas, or periods as the delimiter:

$subject = 'The quick, brown, fox.  jumped over, the lazy dog.';

$data = preg_split( '/[\s,.]+/', $subject);

echo '<pre&gt'' . print_r($data, true) . '</pre>';

which outputs this


Array
(
    [0] => The
    [1] => quick
    [2] => brown
    [3] => fox
    [4] => jumped
    [5] => over
    [6] => the
    [7] => lazy
    [8] => dog
    [9] =>
)

If you’re looking for tutorials and documentation on lots of different flavors of regular expressions, I highly recommend Regular-Expressions.info.