[ View menu ]

script.aculo.us Sortable.create onUpdate event isn’t firing

October 27, 2008

I recently ran into a really annoying issue where the Sortable.create onUpdate event just would not fire for me.


<ul id="list">
  <li>Something #1</li>
  <li>Something #2</li>
  <li>Something #3</li>
</ul>
<script type="text/javascript"><!--
Sortable.create("list", {onUpdate: function() { alert("Something moved...") }});
// --></script>

It turns out that each draggable item needs to have a unique id value. Since this code was in a PHP page, I just added this to fix it:


<?php $i = 0; ?>
...
<li id="item_<?php echo $i++ ?>">

Excluding a single file from HTTP Authentication in .htaccess

September 26, 2008

We recently ran into an issue where we needed a custom HTTP 401 (Authorization Required) error page on a site that was protected by basic HTTP authentication implemented in a .htaccess file.

Since I’m not very familiar with .htaccess stuff, it took quite a bit of Googling on my part and the solution turned out to be very simple:

<files maintenance.html>
Satisfy Any
</files>
 
AuthUserFile /www/.htpasswd
AuthName "Restricted Area"
AuthType Basic
AuthGroupFile /dev/null
Require User admin

“maintenance.html” is a file that sites in the root of my web directory.

Replacing whole words in strings in PHP

May 15, 2008

I was recently tasked with creating a simple dirty word filter in PHP that relies on our blacklist of about 600 words. The filter should simply replace the word with its character length in asterisks.

My first attempt just used str_replace, but I quickly realized that even dirty words embedded in clean words would get filtered. For example, words like “glass” would get filtered to “gl***”.

The solution? Regular expressions:

function str_replace_word($needle,$replacement,$haystack){
    $pattern = "/\b$needle\b/i";
    $haystack = preg_replace($pattern, $replacement, $haystack);
    return $haystack;
}

The pattern is pretty simple, but not being very familiar with regular expressions, I had to do a couple Google searches before I found what I needed.

Here’s a simple breakdown of the pattern string:

The pattern delimiter

The pattern string begins and ends with a forward slash / character. These two characters are called the pattern delimiter and are required by the preg_match function. They can actually be any non-alphanumeric and non-backslash character, so you can pick your pattern delimiters to help with readability.

$pattern = '/\bMatch me\b/';
$pattern = '@\bMatch me\b@';
$pattern = '#\bMatch me\b#';

If you don’t supply a pattern delimiter, PHP will spit out this warning:

Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in

The word boundary \b

The \b escape character acts as a word boundary. For a nice explanation of this metacharacter, take a look at Jan Goyvaerts’ excellent regular expression tutorial page.

The ‘i’ at the end

The ‘i’ at the end of the pattern string just tells preg_match that the search should be case insensitive.

Campfest 2007

August 16, 2007

In early August of 2007, a group of 6 dapper young men set about on a week long trek through the wilderness of northern California and southern Oregon. They spent 3 nights surrounded by bears in Crags Castle National Park near Mount Shasta and another 3 frigid nights in Crater Lake National Park. Barely surviving on pizza, steak and chili, the brave young men spent their last moments together bickering about the validity of Chrono Trigger as a real video game before succumbing to hip and knee pain and going home.

Mount Shasta
Crags Castle National Park and Mount Shasta

Crater Lake National Park
Crater Lake National Park

Blizzcon ‘07

COSPLAY GIRLS TEH HAWT

Blizzon might as well be called WoWCon, and since I don’t play WoW, I had no idea what the panels were about. I spent a good amount of time just walking around, taking pictures and following the cosplay girls.

Take a look at the gallery.

Chicago

Chicago!

San Francisco Roadtrip

June 5, 2007

San Francisco Roadtrip

How to fix moiré

April 10, 2007

http://www.dbphoto.net/techniques/

Canyon Park Hike

April 9, 2007

Canyon Park Hike - Monrovia, CA

Canyon Park in Monrovia, CA.

Rocky Peak Hike

April 7, 2007

Rocky Peak Hike

Starring Robert Redford, Meryl Streep and Tom Cruise.

« Previous